usb: gadget: uvc: prevent index variables to start from 0
authorMichael Grzeschik <m.grzeschik@pengutronix.de>
Thu, 21 Apr 2022 21:14:23 +0000 (23:14 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 May 2022 20:08:09 +0000 (22:08 +0200)
Some configfs variables like bDefaultFrameIndex are always starting by
1. This patch adds a check to prevent setting those variables to 0.

Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Link: https://lore.kernel.org/r/20220421211427.3400834-4-m.grzeschik@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/uvc_configfs.c

index 63b8d37..cffa615 100644 (file)
@@ -1565,6 +1565,12 @@ uvcg_uncompressed_##cname##_store(struct config_item *item,              \
        if (ret)                                                        \
                goto end;                                               \
                                                                        \
+       /* index values in uvc are never 0 */                           \
+       if (!num) {                                                     \
+               ret = -EINVAL;                                          \
+               goto end;                                               \
+       }                                                               \
+                                                                       \
        u->desc.aname = num;                                            \
        ret = len;                                                      \
 end:                                                                   \
@@ -1758,6 +1764,12 @@ uvcg_mjpeg_##cname##_store(struct config_item *item,                     \
        if (ret)                                                        \
                goto end;                                               \
                                                                        \
+       /* index values in uvc are never 0 */                           \
+       if (!num) {                                                     \
+               ret = -EINVAL;                                          \
+               goto end;                                               \
+       }                                                               \
+                                                                       \
        u->desc.aname = num;                                            \
        ret = len;                                                      \
 end:                                                                   \