[PATCH 3.16 168/305] usb: f_fs: off by one bug in _ffs_func_bind()

Ben Hutchings
2016-08-14T11:15:19Z

From: Dan Carpenter <dan.carpenter@oracle.com>

commit 0015f9156092d07b3ec06d37d014328419d5832e upstream.

This loop is supposed to set all the .num[] values to -1 but it's off by
one so it skips the first element and sets one element past the end of
the array.

I've cleaned up the loop a little as well.

Fixes: ddf8abd25994 ('USB: f_fs: the FunctionFS driver')
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
[bwh: Backported to 3.16:
- Adjust filename, context
- Add definition of i variable]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
drivers/usb/gadget/f_fs.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -2355,7 +2355,8 @@ static int _ffs_func_bind(struct usb_con
const int super = gadget_is_superspeed(func->gadget) &&
func->ffs->ss_descs_count;

- int fs_len, hs_len, ret;
+ int fs_len, hs_len, ret, i;
+ struct ffs_ep *eps_ptr;

/* Make it a single chunk, less management later on */
vla_group(d);
@@ -2388,12 +2389,9 @@ static int _ffs_func_bind(struct usb_con
ffs->raw_descs_length);

memset(vla_ptr(vlabuf, d, inums), 0xff, d_inums__sz);
- for (ret = ffs->eps_count; ret; --ret) {
- struct ffs_ep *ptr;
-
- ptr = vla_ptr(vlabuf, d, eps);
- ptr[ret].num = -1;
- }
+ eps_ptr = vla_ptr(vlabuf, d, eps);
+ for (i = 0; i < ffs->eps_count; i++)
+ eps_ptr[i].num = -1;

/* Save pointers
* d_eps == vlabuf, func->eps used to kfree vlabuf later