public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] iio: light: opt3001: fix deadlock due to concurrent flag" failed to apply to 6.12-stable tree
@ 2025-05-12 10:05 gregkh
  2025-05-15 20:21 ` [PATCH 6.12.y] iio: light: opt3001: fix deadlock due to concurrent flag access Luca Ceresoli
  2025-05-16 18:41 ` [PATCH 6.12.y v2] " Luca Ceresoli
  0 siblings, 2 replies; 6+ messages in thread
From: gregkh @ 2025-05-12 10:05 UTC (permalink / raw)
  To: luca.ceresoli, Jonathan.Cameron; +Cc: stable


The patch below does not apply to the 6.12-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 <stable@vger.kernel.org>.

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.12.y
git checkout FETCH_HEAD
git cherry-pick -x f063a28002e3350088b4577c5640882bf4ea17ea
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2025051215-economist-traffic-fa57@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..

Possible dependencies:



thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From f063a28002e3350088b4577c5640882bf4ea17ea Mon Sep 17 00:00:00 2001
From: Luca Ceresoli <luca.ceresoli@bootlin.com>
Date: Fri, 21 Mar 2025 19:10:00 +0100
Subject: [PATCH] iio: light: opt3001: fix deadlock due to concurrent flag
 access

The threaded IRQ function in this driver is reading the flag twice: once to
lock a mutex and once to unlock it. Even though the code setting the flag
is designed to prevent it, there are subtle cases where the flag could be
true at the mutex_lock stage and false at the mutex_unlock stage. This
results in the mutex not being unlocked, resulting in a deadlock.

Fix it by making the opt3001_irq() code generally more robust, reading the
flag into a variable and using the variable value at both stages.

Fixes: 94a9b7b1809f ("iio: light: add support for TI's opt3001 light sensor")
Cc: stable@vger.kernel.org
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Link: https://patch.msgid.link/20250321-opt3001-irq-fix-v1-1-6c520d851562@bootlin.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index 65b295877b41..393a3d2fbe1d 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -788,8 +788,9 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
 	int ret;
 	bool wake_result_ready_queue = false;
 	enum iio_chan_type chan_type = opt->chip_info->chan_type;
+	bool ok_to_ignore_lock = opt->ok_to_ignore_lock;
 
-	if (!opt->ok_to_ignore_lock)
+	if (!ok_to_ignore_lock)
 		mutex_lock(&opt->lock);
 
 	ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
@@ -826,7 +827,7 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
 	}
 
 out:
-	if (!opt->ok_to_ignore_lock)
+	if (!ok_to_ignore_lock)
 		mutex_unlock(&opt->lock);
 
 	if (wake_result_ready_queue)


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 6.12.y] iio: light: opt3001: fix deadlock due to concurrent flag access
  2025-05-12 10:05 FAILED: patch "[PATCH] iio: light: opt3001: fix deadlock due to concurrent flag" failed to apply to 6.12-stable tree gregkh
@ 2025-05-15 20:21 ` Luca Ceresoli
  2025-05-16 18:26   ` Sasha Levin
  2025-05-16 18:41 ` [PATCH 6.12.y v2] " Luca Ceresoli
  1 sibling, 1 reply; 6+ messages in thread
From: Luca Ceresoli @ 2025-05-15 20:21 UTC (permalink / raw)
  To: stable; +Cc: Luca Ceresoli, Jonathan Cameron

The threaded IRQ function in this driver is reading the flag twice: once to
lock a mutex and once to unlock it. Even though the code setting the flag
is designed to prevent it, there are subtle cases where the flag could be
true at the mutex_lock stage and false at the mutex_unlock stage. This
results in the mutex not being unlocked, resulting in a deadlock.

Fix it by making the opt3001_irq() code generally more robust, reading the
flag into a variable and using the variable value at both stages.

Fixes: 94a9b7b1809f ("iio: light: add support for TI's opt3001 light sensor")
Cc: stable@vger.kernel.org
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Link: https://patch.msgid.link/20250321-opt3001-irq-fix-v1-1-6c520d851562@bootlin.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
(cherry picked from commit f063a28002e3350088b4577c5640882bf4ea17ea)
[Fixed conflict while applying on 6.12]
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
 drivers/iio/light/opt3001.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index 176e54bb48c3..d5ca75b12883 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -692,8 +692,9 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
 	struct opt3001 *opt = iio_priv(iio);
 	int ret;
 	bool wake_result_ready_queue = false;
+	bool ok_to_ignore_lock = opt->ok_to_ignore_lock;
 
-	if (!opt->ok_to_ignore_lock)
+	if (!ok_to_ignore_lock)
 		mutex_lock(&opt->lock);
 
 	ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
@@ -730,7 +731,7 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
 	}
 
 out:
-	if (!opt->ok_to_ignore_lock)
+	if (!ok_to_ignore_lock)
 		mutex_unlock(&opt->lock);
 
 	if (wake_result_ready_queue)
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 6.12.y] iio: light: opt3001: fix deadlock due to concurrent flag access
  2025-05-15 20:21 ` [PATCH 6.12.y] iio: light: opt3001: fix deadlock due to concurrent flag access Luca Ceresoli
@ 2025-05-16 18:26   ` Sasha Levin
  2025-05-16 18:43     ` Luca Ceresoli
  0 siblings, 1 reply; 6+ messages in thread
From: Sasha Levin @ 2025-05-16 18:26 UTC (permalink / raw)
  To: stable, luca.ceresoli; +Cc: Sasha Levin

[ Sasha's backport helper bot ]

Hi,

Summary of potential issues:
⚠️ Found matching upstream commit but patch is missing proper reference to it

Found matching upstream commit: f063a28002e3350088b4577c5640882bf4ea17ea

Status in newer kernel trees:
6.14.y | Present (different SHA1: 3950887ff9a9)

Note: The patch differs from the upstream commit:
---
1:  f063a28002e33 ! 1:  e2c338535328d iio: light: opt3001: fix deadlock due to concurrent flag access
    @@ Commit message
         Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
         Link: https://patch.msgid.link/20250321-opt3001-irq-fix-v1-1-6c520d851562@bootlin.com
         Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    +    (cherry picked from commit f063a28002e3350088b4577c5640882bf4ea17ea)
    +    [Fixed conflict while applying on 6.12]
    +    Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
     
      ## drivers/iio/light/opt3001.c ##
     @@ drivers/iio/light/opt3001.c: static irqreturn_t opt3001_irq(int irq, void *_iio)
    + 	struct opt3001 *opt = iio_priv(iio);
      	int ret;
      	bool wake_result_ready_queue = false;
    - 	enum iio_chan_type chan_type = opt->chip_info->chan_type;
     +	bool ok_to_ignore_lock = opt->ok_to_ignore_lock;
      
     -	if (!opt->ok_to_ignore_lock)
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.12.y       |  Success    |  Success   |

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 6.12.y v2] iio: light: opt3001: fix deadlock due to concurrent flag access
  2025-05-12 10:05 FAILED: patch "[PATCH] iio: light: opt3001: fix deadlock due to concurrent flag" failed to apply to 6.12-stable tree gregkh
  2025-05-15 20:21 ` [PATCH 6.12.y] iio: light: opt3001: fix deadlock due to concurrent flag access Luca Ceresoli
@ 2025-05-16 18:41 ` Luca Ceresoli
  2025-05-17 13:08   ` Sasha Levin
  1 sibling, 1 reply; 6+ messages in thread
From: Luca Ceresoli @ 2025-05-16 18:41 UTC (permalink / raw)
  To: stable; +Cc: Sasha Levin, Luca Ceresoli, Jonathan Cameron

[ Upstream commit f063a28002e3350088b4577c5640882bf4ea17ea ]

The threaded IRQ function in this driver is reading the flag twice: once to
lock a mutex and once to unlock it. Even though the code setting the flag
is designed to prevent it, there are subtle cases where the flag could be
true at the mutex_lock stage and false at the mutex_unlock stage. This
results in the mutex not being unlocked, resulting in a deadlock.

Fix it by making the opt3001_irq() code generally more robust, reading the
flag into a variable and using the variable value at both stages.

Fixes: 94a9b7b1809f ("iio: light: add support for TI's opt3001 light sensor")
Cc: stable@vger.kernel.org
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Link: https://patch.msgid.link/20250321-opt3001-irq-fix-v1-1-6c520d851562@bootlin.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
(cherry picked from commit f063a28002e3350088b4577c5640882bf4ea17ea)
[Fixed conflict while applying on 6.12]
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
 drivers/iio/light/opt3001.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index 176e54bb48c3..d5ca75b12883 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -692,8 +692,9 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
 	struct opt3001 *opt = iio_priv(iio);
 	int ret;
 	bool wake_result_ready_queue = false;
+	bool ok_to_ignore_lock = opt->ok_to_ignore_lock;
 
-	if (!opt->ok_to_ignore_lock)
+	if (!ok_to_ignore_lock)
 		mutex_lock(&opt->lock);
 
 	ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
@@ -730,7 +731,7 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
 	}
 
 out:
-	if (!opt->ok_to_ignore_lock)
+	if (!ok_to_ignore_lock)
 		mutex_unlock(&opt->lock);
 
 	if (wake_result_ready_queue)
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 6.12.y] iio: light: opt3001: fix deadlock due to concurrent flag access
  2025-05-16 18:26   ` Sasha Levin
@ 2025-05-16 18:43     ` Luca Ceresoli
  0 siblings, 0 replies; 6+ messages in thread
From: Luca Ceresoli @ 2025-05-16 18:43 UTC (permalink / raw)
  To: Sasha Levin; +Cc: stable

On Fri, 16 May 2025 14:26:41 -0400
Sasha Levin <sashal@kernel.org> wrote:

> [ Sasha's backport helper bot ]
> 
> Hi,
> 
> Summary of potential issues:
> ⚠️ Found matching upstream commit but patch is missing proper reference to it

Apologies, I had missed the [ Upstream commit <sha> ].

Sent v2.

Luca

-- 
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 6.12.y v2] iio: light: opt3001: fix deadlock due to concurrent flag access
  2025-05-16 18:41 ` [PATCH 6.12.y v2] " Luca Ceresoli
@ 2025-05-17 13:08   ` Sasha Levin
  0 siblings, 0 replies; 6+ messages in thread
From: Sasha Levin @ 2025-05-17 13:08 UTC (permalink / raw)
  To: stable; +Cc: Luca Ceresoli, Sasha Levin

[ Sasha's backport helper bot ]

Hi,

✅ All tests passed successfully. No issues detected.
No action required from the submitter.

The upstream commit SHA1 provided is correct: f063a28002e3350088b4577c5640882bf4ea17ea

Status in newer kernel trees:
6.14.y | Present (different SHA1: 3950887ff9a9)

Note: The patch differs from the upstream commit:
---
1:  f063a28002e33 ! 1:  99a94f9f0a69a iio: light: opt3001: fix deadlock due to concurrent flag access
    @@ Metadata
      ## Commit message ##
         iio: light: opt3001: fix deadlock due to concurrent flag access
     
    +    [ Upstream commit f063a28002e3350088b4577c5640882bf4ea17ea ]
    +
         The threaded IRQ function in this driver is reading the flag twice: once to
         lock a mutex and once to unlock it. Even though the code setting the flag
         is designed to prevent it, there are subtle cases where the flag could be
    @@ Commit message
         Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
         Link: https://patch.msgid.link/20250321-opt3001-irq-fix-v1-1-6c520d851562@bootlin.com
         Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    +    (cherry picked from commit f063a28002e3350088b4577c5640882bf4ea17ea)
    +    [Fixed conflict while applying on 6.12]
    +    Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
     
      ## drivers/iio/light/opt3001.c ##
     @@ drivers/iio/light/opt3001.c: static irqreturn_t opt3001_irq(int irq, void *_iio)
    + 	struct opt3001 *opt = iio_priv(iio);
      	int ret;
      	bool wake_result_ready_queue = false;
    - 	enum iio_chan_type chan_type = opt->chip_info->chan_type;
     +	bool ok_to_ignore_lock = opt->ok_to_ignore_lock;
      
     -	if (!opt->ok_to_ignore_lock)
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.12.y       |  Success    |  Success   |

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-05-17 13:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-12 10:05 FAILED: patch "[PATCH] iio: light: opt3001: fix deadlock due to concurrent flag" failed to apply to 6.12-stable tree gregkh
2025-05-15 20:21 ` [PATCH 6.12.y] iio: light: opt3001: fix deadlock due to concurrent flag access Luca Ceresoli
2025-05-16 18:26   ` Sasha Levin
2025-05-16 18:43     ` Luca Ceresoli
2025-05-16 18:41 ` [PATCH 6.12.y v2] " Luca Ceresoli
2025-05-17 13:08   ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox