FAILED: patch "[PATCH] media: rc: Fix race condition during rc_register_device()" failed to apply to 6.6-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.6-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-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x ec7cb49871e5c4f85d57290320c50ee0bae4db84
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026110405-cradle-clubbed-c6b7@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From ec7cb49871e5c4f85d57290320c50ee0bae4db84 Mon Sep 17 00:00:00 2001
From: Sean Young <[email protected]>
Date: Fri, 17 Jul 2026 13:36:31 +0100
Subject: [PATCH] media: rc: Fix race condition during rc_register_device()
Device drivers can call ir_raw_event_store() or ir_raw_event_handle() right after rc_allocate_device(). This means that while rc_register_device() is being called, those functions can be called from e.g. interrupt handlers.
Currently dev->raw is being allocated and populated by ir_raw_event_prepare() which is called from rc_register_device(). This is not done in a safe way, e.g. dev->raw is being set before the raw members are populated.
Call ir_raw_event_prepare() from rc_allocate_device() instead.
drivers/media/rc/rc-ir-raw.c +1 -19
@@ -71,9 +71,6 @@ static int ir_raw_event_thread(void *data)*/ int ir_raw_event_store (struct rc_dev *dev,struct ir_raw_event *ev) { -if (!dev->raw) -return -EINVAL ; -dev_dbg (&dev->dev,"sample: (%05dus %s)\n" , ev->duration,TO_STR (ev->pulse));
@@ -102,9 +99,6 @@ int ir_raw_event_store_edge(struct rc_dev *dev, bool pulse)ktime_t now;struct ir_raw_event ev = {}; -if (!dev->raw) -return -EINVAL ; - now =ktime_get (); ev.duration =ktime_to_us (ktime_sub (now, dev->raw->last_event)); ev.pulse = !pulse;
@@ -129,9 +123,6 @@ int ir_raw_event_store_with_timeout(struct rc_dev *dev, struct ir_raw_event *ev)ktime_t now;int rc =0 ; -if (!dev->raw) -return -EINVAL ; - now =ktime_get ();spin_lock (&dev->raw->edge_spinlock);
@@ -166,9 +157,6 @@ EXPORT_SYMBOL_GPL(ir_raw_event_store_with_timeout);*/ int ir_raw_event_store_with_filter (struct rc_dev *dev,struct ir_raw_event *ev) { -if (!dev->raw) -return -EINVAL ; -/* Ignore spaces in idle mode */ if (dev->idle && !ev->pulse)return 0 ;
@@ -200,9 +188,6 @@ EXPORT_SYMBOL_GPL(ir_raw_event_store_with_filter);*/ void ir_raw_event_set_idle (struct rc_dev *dev,bool idle) { -if (!dev->raw) -return ; -dev_dbg (&dev->dev,"%s idle mode\n" , idle ?"enter" :"leave" );if (idle) {
@@ -226,7 +211,7 @@ EXPORT_SYMBOL_GPL(ir_raw_event_set_idle);*/ void ir_raw_event_handle (struct rc_dev *dev) { -if (!dev->raw || !dev->raw->thread) +if (!dev->raw->thread)return ;wake_up_process (dev->raw->thread);
@@ -612,9 +597,6 @@ EXPORT_SYMBOL(ir_raw_encode_carrier);*/ int ir_raw_event_prepare (struct rc_dev *dev) { -if (!dev) -return -EINVAL ; - dev->raw =kzalloc_obj (*dev->raw);if (!dev->raw)return -ENOMEM ;
drivers/media/rc/rc-main.c +11 -8
@@ -1701,14 +1701,24 @@ static const struct device_type rc_dev_type = {struct rc_dev *rc_allocate_device (enum rc_driver_type type) {struct rc_dev *dev; +int ret; dev =kzalloc_obj (*dev);if (!dev)return NULL ; +if (type ==RC_DRIVER_IR_RAW ) { + ret =ir_raw_event_prepare (dev); +if (ret <0 ) { +kfree (dev); +return NULL ; + } + } +if (type !=RC_DRIVER_IR_RAW_TX ) { dev->input_dev =input_allocate_device ();if (!dev->input_dev) { +ir_raw_event_free (dev);kfree (dev);return NULL ; }
@@ -1724,6 +1734,7 @@ struct rc_dev *rc_allocate_device(enum rc_driver_type type)spin_lock_init (&dev->rc_map.lock);spin_lock_init (&dev->keylock); } +mutex_init (&dev->lock); dev->dev.type = &rc_dev_type;
@@ -1917,12 +1928,6 @@ int rc_register_device(struct rc_dev *dev) dev->sysfs_groups[attr++] = &rc_dev_wakeup_filter_attr_grp; dev->sysfs_groups[attr++] =NULL ; -if (dev->driver_type ==RC_DRIVER_IR_RAW ) { - rc =ir_raw_event_prepare (dev); -if (rc <0 ) - goto out_minor; - } -if (dev->driver_type !=RC_DRIVER_IR_RAW_TX ) { rc =rc_prepare_rx_device (dev);if (rc)
@@ -1979,8 +1984,6 @@ out_dev: out_rx_free:ir_free_table (&dev->rc_map); out_raw: -ir_raw_event_free (dev); -out_minor:ida_free (&rc_ida, minor);return rc; }
Sasha Levin
maintainerPATCH 1/1 media: rc: Fix race condition during rc_register_device()
From: Sean Young <[email protected]>
[ Upstream commit ec7cb49871e5c4f85d57290320c50ee0bae4db84 ]
Device drivers can call ir_raw_event_store() or ir_raw_event_handle() right after rc_allocate_device(). This means that while rc_register_device() is being called, those functions can be called from e.g. interrupt handlers.
Currently dev->raw is being allocated and populated by ir_raw_event_prepare() which is called from rc_register_device(). This is not done in a safe way, e.g. dev->raw is being set before the raw members are populated.
Call ir_raw_event_prepare() from rc_allocate_device() instead.
--- drivers/media/rc/rc-ir-raw.c | 20 +------------------- drivers/media/rc/rc-main.c | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 27 deletions(-)
drivers/media/rc/rc-ir-raw.c +1 -19
@@ -72,9 +72,6 @@ static int ir_raw_event_thread(void *data)*/ int ir_raw_event_store (struct rc_dev *dev,struct ir_raw_event *ev) { -if (!dev->raw) -return -EINVAL ; -dev_dbg (&dev->dev,"sample: (%05dus %s)\n" , ev->duration,TO_STR (ev->pulse));
@@ -103,9 +100,6 @@ int ir_raw_event_store_edge(struct rc_dev *dev, bool pulse)ktime_t now;struct ir_raw_event ev = {}; -if (!dev->raw) -return -EINVAL ; - now =ktime_get (); ev.duration =ktime_to_us (ktime_sub (now, dev->raw->last_event)); ev.pulse = !pulse;
@@ -130,9 +124,6 @@ int ir_raw_event_store_with_timeout(struct rc_dev *dev, struct ir_raw_event *ev)ktime_t now;int rc =0 ; -if (!dev->raw) -return -EINVAL ; - now =ktime_get ();spin_lock (&dev->raw->edge_spinlock);
@@ -167,9 +158,6 @@ EXPORT_SYMBOL_GPL(ir_raw_event_store_with_timeout);*/ int ir_raw_event_store_with_filter (struct rc_dev *dev,struct ir_raw_event *ev) { -if (!dev->raw) -return -EINVAL ; -/* Ignore spaces in idle mode */ if (dev->idle && !ev->pulse)return 0 ;
@@ -201,9 +189,6 @@ EXPORT_SYMBOL_GPL(ir_raw_event_store_with_filter);*/ void ir_raw_event_set_idle (struct rc_dev *dev,bool idle) { -if (!dev->raw) -return ; -dev_dbg (&dev->dev,"%s idle mode\n" , idle ?"enter" :"leave" );if (idle) {
@@ -227,7 +212,7 @@ EXPORT_SYMBOL_GPL(ir_raw_event_set_idle);*/ void ir_raw_event_handle (struct rc_dev *dev) { -if (!dev->raw || !dev->raw->thread) +if (!dev->raw->thread)return ;wake_up_process (dev->raw->thread);
@@ -605,9 +590,6 @@ EXPORT_SYMBOL(ir_raw_encode_carrier);*/ int ir_raw_event_prepare (struct rc_dev *dev) { -if (!dev) -return -EINVAL ; - dev->raw =kzalloc (sizeof (*dev->raw),GFP_KERNEL );if (!dev->raw)return -ENOMEM ;
drivers/media/rc/rc-main.c +11 -8
@@ -1701,14 +1701,24 @@ static const struct device_type rc_dev_type = {struct rc_dev *rc_allocate_device (enum rc_driver_type type) {struct rc_dev *dev; +int ret; dev =kzalloc (sizeof (*dev),GFP_KERNEL );if (!dev)return NULL ; +if (type ==RC_DRIVER_IR_RAW ) { + ret =ir_raw_event_prepare (dev); +if (ret <0 ) { +kfree (dev); +return NULL ; + } + } +if (type !=RC_DRIVER_IR_RAW_TX ) { dev->input_dev =input_allocate_device ();if (!dev->input_dev) { +ir_raw_event_free (dev);kfree (dev);return NULL ; }
@@ -1724,6 +1734,7 @@ struct rc_dev *rc_allocate_device(enum rc_driver_type type)spin_lock_init (&dev->rc_map.lock);spin_lock_init (&dev->keylock); } +mutex_init (&dev->lock); dev->dev.type = &rc_dev_type;
@@ -1922,12 +1933,6 @@ int rc_register_device(struct rc_dev *dev) dev->sysfs_groups[attr++] = &rc_dev_wakeup_filter_attr_grp; dev->sysfs_groups[attr++] =NULL ; -if (dev->driver_type ==RC_DRIVER_IR_RAW ) { - rc =ir_raw_event_prepare (dev); -if (rc <0 ) - goto out_minor; - } -if (dev->driver_type !=RC_DRIVER_IR_RAW_TX ) { rc =rc_prepare_rx_device (dev);if (rc)
@@ -1991,8 +1996,6 @@ int rc_register_device(struct rc_dev *dev) out_free_table:ir_free_table (&dev->rc_map); out_raw: -ir_raw_event_free (dev); -out_minor:ida_free (&rc_ida, minor);return rc; }
Signature · 1 line
2.53.0