usb: f_fs: off by one bug in _ffs_func_bind()
[pandora-kernel.git] / drivers / usb / gadget / f_fs.c
index acb3800..9623556 100644 (file)
@@ -712,7 +712,7 @@ static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value)
        if (code == FUNCTIONFS_INTERFACE_REVMAP) {
                struct ffs_function *func = ffs->func;
                ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV;
-       } else if (gadget->ops->ioctl) {
+       } else if (gadget && gadget->ops->ioctl) {
                ret = gadget->ops->ioctl(gadget, code, value);
        } else {
                ret = -ENOTTY;
@@ -1376,11 +1376,13 @@ static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev)
        ffs->ep0req->context = ffs;
 
        lang = ffs->stringtabs;
-       for (lang = ffs->stringtabs; *lang; ++lang) {
-               struct usb_string *str = (*lang)->strings;
-               int id = first_id;
-               for (; str->s; ++id, ++str)
-                       str->id = id;
+       if (lang) {
+               for (; *lang; ++lang) {
+                       struct usb_string *str = (*lang)->strings;
+                       int id = first_id;
+                       for (; str->s; ++id, ++str)
+                               str->id = id;
+               }
        }
 
        ffs->gadget = cdev->gadget;
@@ -2163,7 +2165,7 @@ static int ffs_func_bind(struct usb_configuration *c,
        const int high = gadget_is_dualspeed(func->gadget) &&
                func->ffs->hs_descs_count;
 
-       int ret;
+       int ret, i;
 
        /* Make it a single chunk, less management later on */
        struct {
@@ -2192,8 +2194,8 @@ static int ffs_func_bind(struct usb_configuration *c,
        memset(data->eps, 0, sizeof data->eps);
        memcpy(data->raw_descs, ffs->raw_descs + 16, sizeof data->raw_descs);
        memset(data->inums, 0xff, sizeof data->inums);
-       for (ret = ffs->eps_count; ret; --ret)
-               data->eps[ret].num = -1;
+       for (i = 0; i < ffs->eps_count; i++)
+               data->eps[i].num = -1;
 
        /* Save pointers */
        func->eps             = data->eps;