FAILED: patch "[PATCH] media: uvcvideo: Fix crash during unbind if gpio unit is in" failed to apply to 5.15-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x a9ea1a3d88b7947ce8cadb2afceee7a54872bbc5
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025021032-zipping-fedora-af63@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From a9ea1a3d88b7947ce8cadb2afceee7a54872bbc5 Mon Sep 17 00:00:00 2001
From: Ricardo Ribalda <[email protected]>
Date: Wed, 6 Nov 2024 20:36:07 +0000
Subject: [PATCH] media: uvcvideo: Fix crash during unbind if gpio unit is in
use
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.
drivers/media/usb/uvc/uvc_driver.c +21 -7
@@ -1295,14 +1295,14 @@ 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 ) -return dev_err_probe (&dev->udev->dev, irq, +return dev_err_probe (&dev->intf->dev, irq,"No IRQ for privacy GPIO\n" ); unit = uvc_alloc_new_entity(dev, UVC_EXT_GPIO_UNIT,
@@ -1329,15 +1329,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); }/* ------------------------------------------------------------------------
@@ -1934,6 +1946,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))
drivers/media/usb/uvc/uvcvideo.h +1 -0
@@ -234,6 +234,7 @@ struct uvc_entity {u8 *bmControls;struct gpio_desc *gpio_privacy;int irq; +bool initialized; } gpio; };
PATCH 1/1 media: uvcvideo: Fix crash during unbind if gpio unit is in use
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.
--- drivers/media/usb/uvc/uvc_driver.c | 35 ++++++++++++++++++++---------- drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 24 insertions(+), 12 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +23 -12
@@ -1530,18 +1530,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_new_entity (dev,UVC_EXT_GPIO_UNIT ,UVC_EXT_GPIO_UNIT_ID ,0 ,1 );
@@ -1567,15 +1564,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); }/* ------------------------------------------------------------------------
@@ -2168,6 +2177,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))
drivers/media/usb/uvc/uvcvideo.h +1 -0
@@ -368,6 +368,7 @@ struct uvc_entity {u8 *bmControls;struct gpio_desc *gpio_privacy;int irq; +bool initialized; } gpio; };
Signature · 1 line
2.48.1.711.g2feabab25a-goog
Sasha Levin
maintainerRe: [PATCH 5.15.y] media: uvcvideo: Fix crash during unbind if gpio unit is in use
[ Sasha's backport helper bot ]
Hi,
Summary of potential issues:
⚠️ Found matching upstream commit but patch is missing proper reference to it ℹ️ Patch is missing in 6.13.y (ignore if backport was sent)
⚠️ Commit missing in all newer stable branches
Found matching upstream commit: a9ea1a3d88b7947ce8cadb2afceee7a54872bbc5
Status in newer kernel trees:
6.13.y | Present (different SHA1: 5d2e65cbe53d) 6.12.y | Present (different SHA1: d2eac8b14ac6)
6.6.y | Present (different SHA1: 0b5e0445bc83) 6.1.y | Present (different SHA1: 644d4fe34bab) 5.4.y | Not found
Note: The patch differs from the upstream commit:
---
1: a9ea1a3d88b79 ! 1: 4c6203668c8f2 media: uvcvideo: Fix crash during unbind if gpio unit is in use
@@ Commit message
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Laurent Pinchart <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
+ (cherry picked from commit a9ea1a3d88b7947ce8cadb2afceee7a54872bbc5)
## drivers/media/usb/uvc/uvc_driver.c ##
@@ drivers/media/usb/uvc/uvc_driver.c: static int uvc_gpio_parse(struct uvc_device *dev)
@@ drivers/media/usb/uvc/uvc_driver.c: static int uvc_gpio_parse(struct uvc_device
return PTR_ERR_OR_ZERO(gpio_privacy);
irq = gpiod_to_irq(gpio_privacy);
- if (irq < 0)
-- return dev_err_probe(&dev->udev->dev, irq,
+- 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");
++ "No IRQ for privacy GPIO\n");
unit = uvc_alloc_new_entity(dev, UVC_EXT_GPIO_UNIT,
+ UVC_EXT_GPIO_UNIT_ID, 0, 1);
@@ drivers/media/usb/uvc/uvc_driver.c: static int uvc_gpio_parse(struct uvc_device *dev)
static int uvc_gpio_init_irq(struct uvc_device *dev)
{---
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-5.15.y | Success | Success |