* [patch v2] batman: cleanup: change test for end of array
@ 2010-03-28 13:13 Dan Carpenter
2010-03-29 7:12 ` Marek Lindner
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Dan Carpenter @ 2010-03-28 13:13 UTC (permalink / raw)
To: kernel-janitors
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>
diff --git a/drivers/staging/batman-adv/device.c b/drivers/staging/batman-adv/device.c
index e7f4421..afcf7eb 100644
--- a/drivers/staging/batman-adv/device.c
+++ b/drivers/staging/batman-adv/device.c
@@ -43,10 +43,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)
@@ -102,15 +99,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;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [patch v2] batman: cleanup: change test for end of array
2010-03-28 13:13 [patch v2] batman: cleanup: change test for end of array Dan Carpenter
@ 2010-03-29 7:12 ` Marek Lindner
2010-03-29 8:11 ` Dan Carpenter
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Marek Lindner @ 2010-03-29 7:12 UTC (permalink / raw)
To: kernel-janitors
On Sunday 28 March 2010 21:13:35 Dan Carpenter wrote:
> @@ -43,10 +43,7 @@ static struct device_client *device_client_hash[256];
>
> - for (i = 0; i < 256; i++)
> - device_client_hash[i] = NULL;
> + memset(&device_client_hash, 0, sizeof(device_client_hash));
I might be mistaken but it looks like the "&" is wrong here. Shouldn't it be:
memset(device_client_hash, 0, sizeof(device_client_hash));
Cheers,
Marek
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch v2] batman: cleanup: change test for end of array
2010-03-28 13:13 [patch v2] batman: cleanup: change test for end of array Dan Carpenter
2010-03-29 7:12 ` Marek Lindner
@ 2010-03-29 8:11 ` Dan Carpenter
2010-03-30 2:08 ` Marek Lindner
2010-03-30 9:40 ` Dan Carpenter
3 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2010-03-29 8:11 UTC (permalink / raw)
To: kernel-janitors
On Mon, Mar 29, 2010 at 03:12:23PM +0800, Marek Lindner wrote:
> On Sunday 28 March 2010 21:13:35 Dan Carpenter wrote:
> > @@ -43,10 +43,7 @@ static struct device_client *device_client_hash[256];
> >
> > - for (i = 0; i < 256; i++)
> > - device_client_hash[i] = NULL;
> > + memset(&device_client_hash, 0, sizeof(device_client_hash));
>
> I might be mistaken but it looks like the "&" is wrong here. Shouldn't it be:
> memset(device_client_hash, 0, sizeof(device_client_hash));
Either way works.
You can easily write a small test program to verify. :)
regards,
dan carpenter
>
> Cheers,
> Marek
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch v2] batman: cleanup: change test for end of array
2010-03-28 13:13 [patch v2] batman: cleanup: change test for end of array Dan Carpenter
2010-03-29 7:12 ` Marek Lindner
2010-03-29 8:11 ` Dan Carpenter
@ 2010-03-30 2:08 ` Marek Lindner
2010-03-30 9:40 ` Dan Carpenter
3 siblings, 0 replies; 5+ messages in thread
From: Marek Lindner @ 2010-03-30 2:08 UTC (permalink / raw)
To: kernel-janitors
On Monday 29 March 2010 16:11:34 Dan Carpenter wrote:
> > I might be mistaken but it looks like the "&" is wrong here. Shouldn't it
> > be: memset(device_client_hash, 0, sizeof(device_client_hash));
>
> Either way works.
Ok, I committed it without the "&" - makes me sleep better. ;-)
Thanks for the patch,
Marek
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch v2] batman: cleanup: change test for end of array
2010-03-28 13:13 [patch v2] batman: cleanup: change test for end of array Dan Carpenter
` (2 preceding siblings ...)
2010-03-30 2:08 ` Marek Lindner
@ 2010-03-30 9:40 ` Dan Carpenter
3 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2010-03-30 9:40 UTC (permalink / raw)
To: kernel-janitors
On Tue, Mar 30, 2010 at 10:08:15AM +0800, Marek Lindner wrote:
> On Monday 29 March 2010 16:11:34 Dan Carpenter wrote:
> > > I might be mistaken but it looks like the "&" is wrong here. Shouldn't it
> > > be: memset(device_client_hash, 0, sizeof(device_client_hash));
> >
> > Either way works.
>
> Ok, I committed it without the "&" - makes me sleep better. ;-)
>
Cool.
regars,
dan carpenter
> Thanks for the patch,
> Marek
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-03-30 9:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-28 13:13 [patch v2] batman: cleanup: change test for end of array Dan Carpenter
2010-03-29 7:12 ` Marek Lindner
2010-03-29 8:11 ` Dan Carpenter
2010-03-30 2:08 ` Marek Lindner
2010-03-30 9:40 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox