]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: uvcvideo: Fix crash during unbind if gpio unit is in use
authorRicardo Ribalda <ribalda@chromium.org>
Wed, 6 Nov 2024 20:36:07 +0000 (20:36 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:51:12 +0000 (12:51 +0100)
commit a9ea1a3d88b7947ce8cadb2afceee7a54872bbc5 upstream.

We used the wrong device for the device managed functions. We used the
usb device, when we should be using the interface device.

If we unbind the driver from the usb interface, the cleanup functions
are never called. In our case, the IRQ is never disabled.

If an IRQ is triggered, it will try to access memory sections that are
already free, causing an OOPS.

We cannot use the function devm_request_threaded_irq here. The devm_*
clean functions may be called after the main structure is released by
uvc_delete.

Luckily this bug has small impact, as it is only affected by devices
with gpio units and the user has to unbind the device, a disconnect will
not trigger this error.

Cc: stable@vger.kernel.org
Fixes: 2886477ff987 ("media: uvcvideo: Implement UVC_EXT_GPIO_UNIT")
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Link: https://lore.kernel.org/r/20241106-uvc-crashrmmod-v6-1-fbf9781c6e83@chromium.org
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/media/usb/uvc/uvc_driver.c
drivers/media/usb/uvc/uvcvideo.h

index ed97ab2af83292cbae2c9a1a341c68da219ddf8d..426b5cf31776205a7f88b08ccb3f4cc743022f50 100644 (file)
@@ -1515,18 +1515,15 @@ static int uvc_gpio_parse(struct uvc_device *dev)
        struct gpio_desc *gpio_privacy;
        int irq;
 
-       gpio_privacy = devm_gpiod_get_optional(&dev->udev->dev, "privacy",
+       gpio_privacy = devm_gpiod_get_optional(&dev->intf->dev, "privacy",
                                               GPIOD_IN);
        if (IS_ERR_OR_NULL(gpio_privacy))
                return PTR_ERR_OR_ZERO(gpio_privacy);
 
        irq = gpiod_to_irq(gpio_privacy);
-       if (irq < 0) {
-               if (irq != EPROBE_DEFER)
-                       dev_err(&dev->udev->dev,
-                               "No IRQ for privacy GPIO (%d)\n", irq);
-               return irq;
-       }
+       if (irq < 0)
+               return dev_err_probe(&dev->intf->dev, irq,
+                                    "No IRQ for privacy GPIO\n");
 
        unit = uvc_alloc_entity(UVC_EXT_GPIO_UNIT, UVC_EXT_GPIO_UNIT_ID, 0, 1);
        if (!unit)
@@ -1551,15 +1548,27 @@ static int uvc_gpio_parse(struct uvc_device *dev)
 static int uvc_gpio_init_irq(struct uvc_device *dev)
 {
        struct uvc_entity *unit = dev->gpio_unit;
+       int ret;
 
        if (!unit || unit->gpio.irq < 0)
                return 0;
 
-       return devm_request_threaded_irq(&dev->udev->dev, unit->gpio.irq, NULL,
-                                        uvc_gpio_irq,
-                                        IRQF_ONESHOT | IRQF_TRIGGER_FALLING |
-                                        IRQF_TRIGGER_RISING,
-                                        "uvc_privacy_gpio", dev);
+       ret = request_threaded_irq(unit->gpio.irq, NULL, uvc_gpio_irq,
+                                  IRQF_ONESHOT | IRQF_TRIGGER_FALLING |
+                                  IRQF_TRIGGER_RISING,
+                                  "uvc_privacy_gpio", dev);
+
+       unit->gpio.initialized = !ret;
+
+       return ret;
+}
+
+static void uvc_gpio_deinit(struct uvc_device *dev)
+{
+       if (!dev->gpio_unit || !dev->gpio_unit->gpio.initialized)
+               return;
+
+       free_irq(dev->gpio_unit->gpio.irq, dev);
 }
 
 /* ------------------------------------------------------------------------
@@ -2152,6 +2161,8 @@ static void uvc_unregister_video(struct uvc_device *dev)
 {
        struct uvc_streaming *stream;
 
+       uvc_gpio_deinit(dev);
+
        list_for_each_entry(stream, &dev->streams, list) {
                /* Nothing to do here, continue. */
                if (!video_is_registered(&stream->vdev))
index d22f586a4426879e71c5b8a061a88dc54eb0ff87..e3ab2ce230703d43bd267c490e99bdc45fa255b8 100644 (file)
@@ -368,6 +368,7 @@ struct uvc_entity {
                        u8  *bmControls;
                        struct gpio_desc *gpio_privacy;
                        int irq;
+                       bool initialized;
                } gpio;
        };