public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] usb: f_fs: off by one bug in _ffs_func_bind()
@ 2016-05-27 11:23 Dan Carpenter
  2016-05-27 11:45 ` walter harms
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Dan Carpenter @ 2016-05-27 11:23 UTC (permalink / raw)
  To: kernel-janitors

This loop is supposed to set all the .num values to -1 but it's doesn't
set the first element and it sets one element beyond the end of the
array.  Really there is no reason for it to be done backwards.  And
"ret" is the wrong variable to use for an iterator.

Fixes: ddf8abd25994 ('USB: f_fs: the FunctionFS driver')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
I just spotted this reviewing the code, I have not tested it.  Please
review carefully, the vla_ptr() macro is difficult to understand.

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 73515d5..7fff81a 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -2777,11 +2777,11 @@ static int _ffs_func_bind(struct usb_configuration *c,
 	       ffs->raw_descs_length);
 
 	memset(vla_ptr(vlabuf, d, inums), 0xff, d_inums__sz);
-	for (ret = ffs->eps_count; ret; --ret) {
+	for (i = 0; i < ffs->eps_count; i++) {
 		struct ffs_ep *ptr;
 
 		ptr = vla_ptr(vlabuf, d, eps);
-		ptr[ret].num = -1;
+		ptr[i].num = -1;
 	}
 
 	/* Save pointers

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-05-28 12:01 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-27 11:23 [patch] usb: f_fs: off by one bug in _ffs_func_bind() Dan Carpenter
2016-05-27 11:45 ` walter harms
2016-05-27 12:23 ` Michal Nazarewicz
2016-05-27 17:25 ` walter harms
2016-05-28  4:46 ` Dan Carpenter
2016-05-28  4:48   ` [patch v2] " Dan Carpenter
2016-05-28  9:05     ` walter harms
2016-05-28 10:16     ` Michal Nazarewicz
2016-05-28 10:15 ` [patch] " Michal Nazarewicz
2016-05-28 10:53 ` Dan Carpenter
2016-05-28 11:05 ` Dan Carpenter
2016-05-28 12:01 ` Michal Nazarewicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox