From patchwork Thu May 6 20:18:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 99 Return-Path: Received: from londo.lunn.ch (londo.lunn.ch [80.238.139.98]) by open-mesh.net (Postfix) with ESMTP id A1C8315442B for ; Thu, 6 May 2010 22:20:39 +0200 (CEST) Received: from lunn by londo.lunn.ch with local (Exim 3.36 #1 (Debian)) id 1OA7X8-0002Jf-00; Thu, 06 May 2010 22:18:58 +0200 From: Andrew Lunn To: gregkh@suse.de Date: Thu, 6 May 2010 22:18:37 +0200 Message-Id: <1273177132-8792-12-git-send-email-andrew@lunn.ch> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1273177132-8792-1-git-send-email-andrew@lunn.ch> References: <1273177132-8792-1-git-send-email-andrew@lunn.ch> Sender: Andrew Lunn Cc: b.a.t.m.a.n@lists.open-mesh.net, Dan Carpenter Subject: [B.A.T.M.A.N.] [PATCH 11/26] staging:batman-adv: cleanup: change test for end of array X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.11 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 May 2010 20:20:39 -0000 From: Dan Carpenter The code here is testing to see if "i" is passed the end of the array. The original code works probably, but it's not the cleanest way. Andrew Lunn suggested that I also remove all the hard coded references to 256 so I have done that as well. Signed-off-by: Dan Carpenter Signed-off-by: Andrew Lunn --- drivers/staging/batman-adv/device.c | 11 ++++------- 1 files changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/staging/batman-adv/device.c b/drivers/staging/batman-adv/device.c index c82a5af..fbfe234 100644 --- a/drivers/staging/batman-adv/device.c +++ b/drivers/staging/batman-adv/device.c @@ -44,10 +44,7 @@ static struct device_client *device_client_hash[256]; void bat_device_init(void) { - int i; - - for (i = 0; i < 256; i++) - device_client_hash[i] = NULL; + memset(device_client_hash, 0, sizeof(device_client_hash)); } int bat_device_setup(void) @@ -103,15 +100,15 @@ int bat_device_open(struct inode *inode, struct file *file) if (!device_client) return -ENOMEM; - for (i = 0; i < 256; i++) { + for (i = 0; i < ARRAY_SIZE(device_client_hash); i++) { if (!device_client_hash[i]) { device_client_hash[i] = device_client; break; } } - if (device_client_hash[i] != device_client) { - printk(KERN_ERR "batman-adv:Error - can't add another packet client: maximum number of clients reached \n"); + if (i == ARRAY_SIZE(device_client_hash)) { + printk(KERN_ERR "batman-adv:Error - can't add another packet client: maximum number of clients reached\n"); kfree(device_client); return -EXFULL; }