Author: marek Date: 2010-03-30 04:08:05 +0200 (Tue, 30 Mar 2010) New Revision: 1615
Modified: trunk/batman-adv-kernelland/device.c Log: batman-adv: cleanup: change test for end of array
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 error27@gmail.com
Modified: trunk/batman-adv-kernelland/device.c =================================================================== --- trunk/batman-adv-kernelland/device.c 2010-03-25 01:39:32 UTC (rev 1614) +++ trunk/batman-adv-kernelland/device.c 2010-03-30 02:08:05 UTC (rev 1615) @@ -45,10 +45,7 @@
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) @@ -104,15 +101,15 @@ 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; }