linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v7 0/3] locking/mutex: Mark devm_mutex_init() as __must_check
@ 2025-06-17 17:08 Thomas Weißschuh
  2025-06-17 17:08 ` [PATCH v7 1/3] spi: spi-nxp-fspi: check return value of devm_mutex_init() Thomas Weißschuh
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Thomas Weißschuh @ 2025-06-17 17:08 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Waiman Long, Boqun Feng,
	Vicentiu Galanopulo, Will Deacon, Han Xu, Haibo Chen, Yogesh Gaur,
	Mark Brown, Lee Jones, Pavel Machek, Andrew Davis
  Cc: Andy Shevchenko, linux-kernel, Bartosz Golaszewski,
	Bartosz Golaszewski, linux-spi, imx, linux-leds,
	Thomas Weißschuh

devm_mutex_init() can fail. Make sure everybody checks the return value.
All patches should go through the mutex tree together.

It would be great if this could go in through a single tree at once.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Changes in v7:
- Pick up Ack from Andrew
- Reword commit messages
- Link to v6: https://lore.kernel.org/r/20250609-must_check-devm_mutex_init-v6-0-9540d5df9704@weissschuh.net

Changes in v6:
- Rebase on v6.16-rc1
- Pick up review tag from Bartosz
- Fix up spi-nxp-fspi
- Fix up leds-lp8860
- Link to v5: https://lore.kernel.org/r/20250505-must_check-devm_mutex_init-v5-1-92fa4b793c6e@weissschuh.net

Changes in v5:
- Pick up review tag from Andy
- Link to v4: https://lore.kernel.org/r/20250407-must_check-devm_mutex_init-v4-1-587bacc9f6b3@weissschuh.net

Changes in v4:
- Drop already applied leds-1202 driver patch
- Rebase on v6.15-rc1
- Link to v3: https://lore.kernel.org/r/20250208-must_check-devm_mutex_init-v3-0-245e417dcc9e@weissschuh.net

Changes in v3:
- Introduce and use helper macro __mutex_init_ret()
- Link to v2: https://lore.kernel.org/r/20250204-must_check-devm_mutex_init-v2-0-7b6271c4b7e6@weissschuh.net

Changes in v2:
- Rebase on 6.14-rc1
- Fix up leds-1202 driver
- Link to v1: https://lore.kernel.org/r/20241202-must_check-devm_mutex_init-v1-1-e60eb97b8c72@weissschuh.net

---
Thomas Weißschuh (3):
      spi: spi-nxp-fspi: check return value of devm_mutex_init()
      leds: lp8860: Check return value of devm_mutex_init()
      locking/mutex: Mark devm_mutex_init() as __must_check

 drivers/leds/leds-lp8860.c |  4 +++-
 drivers/spi/spi-nxp-fspi.c |  4 +++-
 include/linux/mutex.h      | 11 +++++++----
 3 files changed, 13 insertions(+), 6 deletions(-)
---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20241031-must_check-devm_mutex_init-cac583bda8fe

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>


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

* [PATCH v7 1/3] spi: spi-nxp-fspi: check return value of devm_mutex_init()
  2025-06-17 17:08 [PATCH v7 0/3] locking/mutex: Mark devm_mutex_init() as __must_check Thomas Weißschuh
@ 2025-06-17 17:08 ` Thomas Weißschuh
  2025-06-17 19:02   ` Mark Brown
  2025-07-19 17:40   ` [tip: locking/core] spi: spi-nxp-fspi: Check " tip-bot2 for Thomas Weißschuh
  2025-06-17 17:08 ` [PATCH v7 2/3] leds: lp8860: " Thomas Weißschuh
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 15+ messages in thread
From: Thomas Weißschuh @ 2025-06-17 17:08 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Waiman Long, Boqun Feng,
	Vicentiu Galanopulo, Will Deacon, Han Xu, Haibo Chen, Yogesh Gaur,
	Mark Brown, Lee Jones, Pavel Machek, Andrew Davis
  Cc: Andy Shevchenko, linux-kernel, Bartosz Golaszewski,
	Bartosz Golaszewski, linux-spi, imx, linux-leds,
	Thomas Weißschuh

devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will be
marked as unusable and trigger errors on usage.

Add the missed check.

Fixes: 48900813abd2 ("spi: spi-nxp-fspi: remove the goto in probe")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/spi/spi-nxp-fspi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
index e63c77e418231cd0698ffb73eeeebfbe63cc3065..f3d5765054132cd18b7257439ece971f58e9ceb2 100644
--- a/drivers/spi/spi-nxp-fspi.c
+++ b/drivers/spi/spi-nxp-fspi.c
@@ -1273,7 +1273,9 @@ static int nxp_fspi_probe(struct platform_device *pdev)
 	if (ret)
 		return dev_err_probe(dev, ret, "Failed to request irq\n");
 
-	devm_mutex_init(dev, &f->lock);
+	ret = devm_mutex_init(dev, &f->lock);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to initialize lock\n");
 
 	ctlr->bus_num = -1;
 	ctlr->num_chipselect = NXP_FSPI_MAX_CHIPSELECT;

-- 
2.50.0


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

* [PATCH v7 2/3] leds: lp8860: Check return value of devm_mutex_init()
  2025-06-17 17:08 [PATCH v7 0/3] locking/mutex: Mark devm_mutex_init() as __must_check Thomas Weißschuh
  2025-06-17 17:08 ` [PATCH v7 1/3] spi: spi-nxp-fspi: check return value of devm_mutex_init() Thomas Weißschuh
@ 2025-06-17 17:08 ` Thomas Weißschuh
  2025-06-19 12:34   ` (subset) " Lee Jones
  2025-07-19 17:40   ` [tip: locking/core] " tip-bot2 for Thomas Weißschuh
  2025-06-17 17:08 ` [PATCH v7 3/3] locking/mutex: Mark devm_mutex_init() as __must_check Thomas Weißschuh
  2025-07-11 22:12 ` [PATCH v7 0/3] " Boqun Feng
  3 siblings, 2 replies; 15+ messages in thread
From: Thomas Weißschuh @ 2025-06-17 17:08 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Waiman Long, Boqun Feng,
	Vicentiu Galanopulo, Will Deacon, Han Xu, Haibo Chen, Yogesh Gaur,
	Mark Brown, Lee Jones, Pavel Machek, Andrew Davis
  Cc: Andy Shevchenko, linux-kernel, Bartosz Golaszewski,
	Bartosz Golaszewski, linux-spi, imx, linux-leds,
	Thomas Weißschuh

devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will be
marked as unusable and trigger errors on usage.

Add the missed check.

Fixes: 87a59548af95 ("leds: lp8860: Use new mutex guards to cleanup function exits")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Andrew Davis <afd@ti.com>
---
 drivers/leds/leds-lp8860.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/leds-lp8860.c b/drivers/leds/leds-lp8860.c
index 52b97c9f2a03567aa12d4f63a951593a5e7017d5..0962c00c215a11f555a7878a3b65824b5219a1fa 100644
--- a/drivers/leds/leds-lp8860.c
+++ b/drivers/leds/leds-lp8860.c
@@ -307,7 +307,9 @@ static int lp8860_probe(struct i2c_client *client)
 	led->client = client;
 	led->led_dev.brightness_set_blocking = lp8860_brightness_set;
 
-	devm_mutex_init(&client->dev, &led->lock);
+	ret = devm_mutex_init(&client->dev, &led->lock);
+	if (ret)
+		return dev_err_probe(&client->dev, ret, "Failed to initialize lock\n");
 
 	led->regmap = devm_regmap_init_i2c(client, &lp8860_regmap_config);
 	if (IS_ERR(led->regmap)) {

-- 
2.50.0


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

* [PATCH v7 3/3] locking/mutex: Mark devm_mutex_init() as __must_check
  2025-06-17 17:08 [PATCH v7 0/3] locking/mutex: Mark devm_mutex_init() as __must_check Thomas Weißschuh
  2025-06-17 17:08 ` [PATCH v7 1/3] spi: spi-nxp-fspi: check return value of devm_mutex_init() Thomas Weißschuh
  2025-06-17 17:08 ` [PATCH v7 2/3] leds: lp8860: " Thomas Weißschuh
@ 2025-06-17 17:08 ` Thomas Weißschuh
  2025-06-17 17:32   ` Boqun Feng
  2025-07-19 17:40   ` [tip: locking/core] " tip-bot2 for Thomas Weißschuh
  2025-07-11 22:12 ` [PATCH v7 0/3] " Boqun Feng
  3 siblings, 2 replies; 15+ messages in thread
From: Thomas Weißschuh @ 2025-06-17 17:08 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Waiman Long, Boqun Feng,
	Vicentiu Galanopulo, Will Deacon, Han Xu, Haibo Chen, Yogesh Gaur,
	Mark Brown, Lee Jones, Pavel Machek, Andrew Davis
  Cc: Andy Shevchenko, linux-kernel, Bartosz Golaszewski,
	Bartosz Golaszewski, linux-spi, imx, linux-leds,
	Thomas Weißschuh

devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will be
marked as unusable and trigger errors on usage.
Enforce all callers check the return value through the compiler.

As devm_mutex_init() itself is a macro, it can not be annotated
directly. Annotate __devm_mutex_init() instead.
Unfortunately __must_check/warn_unused_result don't propagate through
statement expression. So move the statement expression into the argument
list of the call to __devm_mutex_init() through a helper macro.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 include/linux/mutex.h | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index a039fa8c17807c700d3b61193feac0418cad1243..00afd341d293ddfcc0a427b576efdce044955e38 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -126,11 +126,11 @@ do {							\
 
 #ifdef CONFIG_DEBUG_MUTEXES
 
-int __devm_mutex_init(struct device *dev, struct mutex *lock);
+int __must_check __devm_mutex_init(struct device *dev, struct mutex *lock);
 
 #else
 
-static inline int __devm_mutex_init(struct device *dev, struct mutex *lock)
+static inline int __must_check __devm_mutex_init(struct device *dev, struct mutex *lock)
 {
 	/*
 	 * When CONFIG_DEBUG_MUTEXES is off mutex_destroy() is just a nop so
@@ -141,14 +141,17 @@ static inline int __devm_mutex_init(struct device *dev, struct mutex *lock)
 
 #endif
 
-#define devm_mutex_init(dev, mutex)			\
+#define __mutex_init_ret(mutex)				\
 ({							\
 	typeof(mutex) mutex_ = (mutex);			\
 							\
 	mutex_init(mutex_);				\
-	__devm_mutex_init(dev, mutex_);			\
+	mutex_;						\
 })
 
+#define devm_mutex_init(dev, mutex) \
+	__devm_mutex_init(dev, __mutex_init_ret(mutex))
+
 /*
  * See kernel/locking/mutex.c for detailed documentation of these APIs.
  * Also see Documentation/locking/mutex-design.rst.

-- 
2.50.0


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

* Re: [PATCH v7 3/3] locking/mutex: Mark devm_mutex_init() as __must_check
  2025-06-17 17:08 ` [PATCH v7 3/3] locking/mutex: Mark devm_mutex_init() as __must_check Thomas Weißschuh
@ 2025-06-17 17:32   ` Boqun Feng
  2025-07-19 17:40   ` [tip: locking/core] " tip-bot2 for Thomas Weißschuh
  1 sibling, 0 replies; 15+ messages in thread
From: Boqun Feng @ 2025-06-17 17:32 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Peter Zijlstra, Ingo Molnar, Waiman Long, Vicentiu Galanopulo,
	Will Deacon, Han Xu, Haibo Chen, Yogesh Gaur, Mark Brown,
	Lee Jones, Pavel Machek, Andrew Davis, Andy Shevchenko,
	linux-kernel, Bartosz Golaszewski, Bartosz Golaszewski, linux-spi,
	imx, linux-leds

On Tue, Jun 17, 2025 at 07:08:14PM +0200, Thomas Weißschuh wrote:
> devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will be
> marked as unusable and trigger errors on usage.
> Enforce all callers check the return value through the compiler.
> 
> As devm_mutex_init() itself is a macro, it can not be annotated
> directly. Annotate __devm_mutex_init() instead.
> Unfortunately __must_check/warn_unused_result don't propagate through
> statement expression. So move the statement expression into the argument
> list of the call to __devm_mutex_init() through a helper macro.
> 

Given it's Peter's suggestion [1] for __mutex_init_ret(), I think a

Suggested-by: Peter Zijlstra <peterz@infradead.org>

should be added here. No need for a new version just for that. If patch
#1 got some reviews, I would queue this in my lockdep-for-tip branch.
Hopefully these will land v6.17.

[1]: https://lore.kernel.org/all/20250204090106.GP7145@noisy.programming.kicks-ass.net/

Regards,
Boqun

> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
>  include/linux/mutex.h | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/include/linux/mutex.h b/include/linux/mutex.h
> index a039fa8c17807c700d3b61193feac0418cad1243..00afd341d293ddfcc0a427b576efdce044955e38 100644
> --- a/include/linux/mutex.h
> +++ b/include/linux/mutex.h
> @@ -126,11 +126,11 @@ do {							\
>  
>  #ifdef CONFIG_DEBUG_MUTEXES
>  
> -int __devm_mutex_init(struct device *dev, struct mutex *lock);
> +int __must_check __devm_mutex_init(struct device *dev, struct mutex *lock);
>  
>  #else
>  
> -static inline int __devm_mutex_init(struct device *dev, struct mutex *lock)
> +static inline int __must_check __devm_mutex_init(struct device *dev, struct mutex *lock)
>  {
>  	/*
>  	 * When CONFIG_DEBUG_MUTEXES is off mutex_destroy() is just a nop so
> @@ -141,14 +141,17 @@ static inline int __devm_mutex_init(struct device *dev, struct mutex *lock)
>  
>  #endif
>  
> -#define devm_mutex_init(dev, mutex)			\
> +#define __mutex_init_ret(mutex)				\
>  ({							\
>  	typeof(mutex) mutex_ = (mutex);			\
>  							\
>  	mutex_init(mutex_);				\
> -	__devm_mutex_init(dev, mutex_);			\
> +	mutex_;						\
>  })
>  
> +#define devm_mutex_init(dev, mutex) \
> +	__devm_mutex_init(dev, __mutex_init_ret(mutex))
> +
>  /*
>   * See kernel/locking/mutex.c for detailed documentation of these APIs.
>   * Also see Documentation/locking/mutex-design.rst.
> 
> -- 
> 2.50.0
> 

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

* Re: [PATCH v7 1/3] spi: spi-nxp-fspi: check return value of devm_mutex_init()
  2025-06-17 17:08 ` [PATCH v7 1/3] spi: spi-nxp-fspi: check return value of devm_mutex_init() Thomas Weißschuh
@ 2025-06-17 19:02   ` Mark Brown
  2025-07-19 17:40   ` [tip: locking/core] spi: spi-nxp-fspi: Check " tip-bot2 for Thomas Weißschuh
  1 sibling, 0 replies; 15+ messages in thread
From: Mark Brown @ 2025-06-17 19:02 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Peter Zijlstra, Ingo Molnar, Waiman Long, Boqun Feng,
	Vicentiu Galanopulo, Will Deacon, Han Xu, Haibo Chen, Yogesh Gaur,
	Lee Jones, Pavel Machek, Andrew Davis, Andy Shevchenko,
	linux-kernel, Bartosz Golaszewski, Bartosz Golaszewski, linux-spi,
	imx, linux-leds

[-- Attachment #1: Type: text/plain, Size: 272 bytes --]

On Tue, Jun 17, 2025 at 07:08:12PM +0200, Thomas Weißschuh wrote:
> devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will be
> marked as unusable and trigger errors on usage.
> 
> Add the missed check.

Reviewed-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: (subset) [PATCH v7 2/3] leds: lp8860: Check return value of devm_mutex_init()
  2025-06-17 17:08 ` [PATCH v7 2/3] leds: lp8860: " Thomas Weißschuh
@ 2025-06-19 12:34   ` Lee Jones
  2025-06-19 15:34     ` Thomas Weißschuh
  2025-07-19 17:40   ` [tip: locking/core] " tip-bot2 for Thomas Weißschuh
  1 sibling, 1 reply; 15+ messages in thread
From: Lee Jones @ 2025-06-19 12:34 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Waiman Long, Boqun Feng,
	Vicentiu Galanopulo, Will Deacon, Han Xu, Haibo Chen, Yogesh Gaur,
	Mark Brown, Lee Jones, Pavel Machek, Andrew Davis,
	Thomas Weißschuh
  Cc: Andy Shevchenko, linux-kernel, Bartosz Golaszewski,
	Bartosz Golaszewski, linux-spi, imx, linux-leds

On Tue, 17 Jun 2025 19:08:13 +0200, Thomas Weißschuh wrote:
> devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will be
> marked as unusable and trigger errors on usage.
> 
> Add the missed check.
> 
> 

Applied, thanks!

[2/3] leds: lp8860: Check return value of devm_mutex_init()
      commit: 426e0c8e8eed26b67bbbd138483bb5973724adae

--
Lee Jones [李琼斯]


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

* Re: (subset) [PATCH v7 2/3] leds: lp8860: Check return value of devm_mutex_init()
  2025-06-19 12:34   ` (subset) " Lee Jones
@ 2025-06-19 15:34     ` Thomas Weißschuh
  2025-06-25  9:04       ` Lee Jones
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Weißschuh @ 2025-06-19 15:34 UTC (permalink / raw)
  To: Lee Jones
  Cc: Peter Zijlstra, Ingo Molnar, Waiman Long, Boqun Feng,
	Vicentiu Galanopulo, Will Deacon, Han Xu, Haibo Chen, Yogesh Gaur,
	Mark Brown, Pavel Machek, Andrew Davis, Andy Shevchenko,
	linux-kernel, Bartosz Golaszewski, Bartosz Golaszewski, linux-spi,
	imx, linux-leds

Hi Lee,

On 2025-06-19 13:34:56+0100, Lee Jones wrote:
> On Tue, 17 Jun 2025 19:08:13 +0200, Thomas Weißschuh wrote:
> > devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will be
> > marked as unusable and trigger errors on usage.
> > 
> > Add the missed check.
> 
> Applied, thanks!
> 
> [2/3] leds: lp8860: Check return value of devm_mutex_init()
>       commit: 426e0c8e8eed26b67bbbd138483bb5973724adae

Thanks, but (as mentioned in the cover letter) these patches should go
together through the mutex/locking tree.
Could you drop it on your side and give an Ack instead?


Thomas

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

* Re: (subset) [PATCH v7 2/3] leds: lp8860: Check return value of devm_mutex_init()
  2025-06-19 15:34     ` Thomas Weißschuh
@ 2025-06-25  9:04       ` Lee Jones
  2025-06-26 10:54         ` Thomas Weißschuh
  0 siblings, 1 reply; 15+ messages in thread
From: Lee Jones @ 2025-06-25  9:04 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Peter Zijlstra, Ingo Molnar, Waiman Long, Boqun Feng,
	Vicentiu Galanopulo, Will Deacon, Han Xu, Haibo Chen, Yogesh Gaur,
	Mark Brown, Pavel Machek, Andrew Davis, Andy Shevchenko,
	linux-kernel, Bartosz Golaszewski, Bartosz Golaszewski, linux-spi,
	imx, linux-leds

On Thu, 19 Jun 2025, Thomas Weißschuh wrote:

> Hi Lee,
> 
> On 2025-06-19 13:34:56+0100, Lee Jones wrote:
> > On Tue, 17 Jun 2025 19:08:13 +0200, Thomas Weißschuh wrote:
> > > devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will be
> > > marked as unusable and trigger errors on usage.
> > > 
> > > Add the missed check.
> > 
> > Applied, thanks!
> > 
> > [2/3] leds: lp8860: Check return value of devm_mutex_init()
> >       commit: 426e0c8e8eed26b67bbbd138483bb5973724adae
> 
> Thanks, but (as mentioned in the cover letter) these patches should go
> together through the mutex/locking tree.
> Could you drop it on your side and give an Ack instead?

There has to be good reasons to do this.

I didn't see any dependents or dependencies in this patch.

-- 
Lee Jones [李琼斯]

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

* Re: (subset) [PATCH v7 2/3] leds: lp8860: Check return value of devm_mutex_init()
  2025-06-25  9:04       ` Lee Jones
@ 2025-06-26 10:54         ` Thomas Weißschuh
  2025-06-27 12:58           ` Lee Jones
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Weißschuh @ 2025-06-26 10:54 UTC (permalink / raw)
  To: Lee Jones
  Cc: Peter Zijlstra, Ingo Molnar, Waiman Long, Boqun Feng,
	Vicentiu Galanopulo, Will Deacon, Han Xu, Haibo Chen, Yogesh Gaur,
	Mark Brown, Pavel Machek, Andrew Davis, Andy Shevchenko,
	linux-kernel, Bartosz Golaszewski, Bartosz Golaszewski, linux-spi,
	imx, linux-leds

On 2025-06-25 10:04:39+0100, Lee Jones wrote:
> On Thu, 19 Jun 2025, Thomas Weißschuh wrote:
> > On 2025-06-19 13:34:56+0100, Lee Jones wrote:
> > > On Tue, 17 Jun 2025 19:08:13 +0200, Thomas Weißschuh wrote:
> > > > devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will be
> > > > marked as unusable and trigger errors on usage.
> > > > 
> > > > Add the missed check.
> > > 
> > > Applied, thanks!
> > > 
> > > [2/3] leds: lp8860: Check return value of devm_mutex_init()
> > >       commit: 426e0c8e8eed26b67bbbd138483bb5973724adae
> > 
> > Thanks, but (as mentioned in the cover letter) these patches should go
> > together through the mutex/locking tree.
> > Could you drop it on your side and give an Ack instead?
> 
> There has to be good reasons to do this.
>
> I didn't see any dependents or dependencies in this patch.

Patch 3 depends on patch 1 and 2.

It will break the build for each instance of an ignored return value
of devm_mutex_init(). Therefore all such instances need to be resolved
before the patch can be applied.
So the patches can't go through different trees.

In theory we could fix the drivers in this cycle and then change
devm_mutex_init() in the next one. But new regressions are introduced
over and over. This patch is already in the third cycle...


Thomas

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

* Re: (subset) [PATCH v7 2/3] leds: lp8860: Check return value of devm_mutex_init()
  2025-06-26 10:54         ` Thomas Weißschuh
@ 2025-06-27 12:58           ` Lee Jones
  0 siblings, 0 replies; 15+ messages in thread
From: Lee Jones @ 2025-06-27 12:58 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Peter Zijlstra, Ingo Molnar, Waiman Long, Boqun Feng,
	Vicentiu Galanopulo, Will Deacon, Han Xu, Haibo Chen, Yogesh Gaur,
	Mark Brown, Pavel Machek, Andrew Davis, Andy Shevchenko,
	linux-kernel, Bartosz Golaszewski, Bartosz Golaszewski, linux-spi,
	imx, linux-leds

On Thu, 26 Jun 2025, Thomas Weißschuh wrote:

> On 2025-06-25 10:04:39+0100, Lee Jones wrote:
> > On Thu, 19 Jun 2025, Thomas Weißschuh wrote:
> > > On 2025-06-19 13:34:56+0100, Lee Jones wrote:
> > > > On Tue, 17 Jun 2025 19:08:13 +0200, Thomas Weißschuh wrote:
> > > > > devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will be
> > > > > marked as unusable and trigger errors on usage.
> > > > > 
> > > > > Add the missed check.
> > > > 
> > > > Applied, thanks!
> > > > 
> > > > [2/3] leds: lp8860: Check return value of devm_mutex_init()
> > > >       commit: 426e0c8e8eed26b67bbbd138483bb5973724adae
> > > 
> > > Thanks, but (as mentioned in the cover letter) these patches should go
> > > together through the mutex/locking tree.
> > > Could you drop it on your side and give an Ack instead?
> > 
> > There has to be good reasons to do this.
> >
> > I didn't see any dependents or dependencies in this patch.
> 
> Patch 3 depends on patch 1 and 2.
> 
> It will break the build for each instance of an ignored return value
> of devm_mutex_init(). Therefore all such instances need to be resolved
> before the patch can be applied.
> So the patches can't go through different trees.
> 
> In theory we could fix the drivers in this cycle and then change
> devm_mutex_init() in the next one. But new regressions are introduced
> over and over. This patch is already in the third cycle...

Fair point.

Acked-by: Lee Jones <lee@kernel.org>

And patch removed from LEDs.

-- 
Lee Jones [李琼斯]

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

* Re: [PATCH v7 0/3] locking/mutex: Mark devm_mutex_init() as __must_check
  2025-06-17 17:08 [PATCH v7 0/3] locking/mutex: Mark devm_mutex_init() as __must_check Thomas Weißschuh
                   ` (2 preceding siblings ...)
  2025-06-17 17:08 ` [PATCH v7 3/3] locking/mutex: Mark devm_mutex_init() as __must_check Thomas Weißschuh
@ 2025-07-11 22:12 ` Boqun Feng
  3 siblings, 0 replies; 15+ messages in thread
From: Boqun Feng @ 2025-07-11 22:12 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Peter Zijlstra, Ingo Molnar, Waiman Long, Vicentiu Galanopulo,
	Will Deacon, Han Xu, Haibo Chen, Yogesh Gaur, Mark Brown,
	Lee Jones, Pavel Machek, Andrew Davis, Andy Shevchenko,
	linux-kernel, Bartosz Golaszewski, Bartosz Golaszewski, linux-spi,
	imx, linux-leds

On Tue, Jun 17, 2025 at 07:08:11PM +0200, Thomas Weißschuh wrote:
> devm_mutex_init() can fail. Make sure everybody checks the return value.
> All patches should go through the mutex tree together.
> 
> It would be great if this could go in through a single tree at once.
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

Queued for v6.17, thank you all!

Regards,
Boqun

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

* [tip: locking/core] locking/mutex: Mark devm_mutex_init() as __must_check
  2025-06-17 17:08 ` [PATCH v7 3/3] locking/mutex: Mark devm_mutex_init() as __must_check Thomas Weißschuh
  2025-06-17 17:32   ` Boqun Feng
@ 2025-07-19 17:40   ` tip-bot2 for Thomas Weißschuh
  1 sibling, 0 replies; 15+ messages in thread
From: tip-bot2 for Thomas Weißschuh @ 2025-07-19 17:40 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Peter Zijlstra, linux, Andy Shevchenko, Bartosz Golaszewski,
	Boqun Feng, x86, linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     daec29dcc8731b7596690ab9f647839e4584a86d
Gitweb:        https://git.kernel.org/tip/daec29dcc8731b7596690ab9f647839e4584a86d
Author:        Thomas Weißschuh <linux@weissschuh.net>
AuthorDate:    Tue, 17 Jun 2025 19:08:14 +02:00
Committer:     Boqun Feng <boqun.feng@gmail.com>
CommitterDate: Fri, 11 Jul 2025 15:11:54 -07:00

locking/mutex: Mark devm_mutex_init() as __must_check

devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will be
marked as unusable and trigger errors on usage.
Enforce all callers check the return value through the compiler.

As devm_mutex_init() itself is a macro, it can not be annotated
directly. Annotate __devm_mutex_init() instead.
Unfortunately __must_check/warn_unused_result don't propagate through
statement expression. So move the statement expression into the argument
list of the call to __devm_mutex_init() through a helper macro.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250617-must_check-devm_mutex_init-v7-3-d9e449f4d224@weissschuh.net
---
 include/linux/mutex.h | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index a039fa8..00afd34 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -126,11 +126,11 @@ do {							\
 
 #ifdef CONFIG_DEBUG_MUTEXES
 
-int __devm_mutex_init(struct device *dev, struct mutex *lock);
+int __must_check __devm_mutex_init(struct device *dev, struct mutex *lock);
 
 #else
 
-static inline int __devm_mutex_init(struct device *dev, struct mutex *lock)
+static inline int __must_check __devm_mutex_init(struct device *dev, struct mutex *lock)
 {
 	/*
 	 * When CONFIG_DEBUG_MUTEXES is off mutex_destroy() is just a nop so
@@ -141,14 +141,17 @@ static inline int __devm_mutex_init(struct device *dev, struct mutex *lock)
 
 #endif
 
-#define devm_mutex_init(dev, mutex)			\
+#define __mutex_init_ret(mutex)				\
 ({							\
 	typeof(mutex) mutex_ = (mutex);			\
 							\
 	mutex_init(mutex_);				\
-	__devm_mutex_init(dev, mutex_);			\
+	mutex_;						\
 })
 
+#define devm_mutex_init(dev, mutex) \
+	__devm_mutex_init(dev, __mutex_init_ret(mutex))
+
 /*
  * See kernel/locking/mutex.c for detailed documentation of these APIs.
  * Also see Documentation/locking/mutex-design.rst.

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

* [tip: locking/core] leds: lp8860: Check return value of devm_mutex_init()
  2025-06-17 17:08 ` [PATCH v7 2/3] leds: lp8860: " Thomas Weißschuh
  2025-06-19 12:34   ` (subset) " Lee Jones
@ 2025-07-19 17:40   ` tip-bot2 for Thomas Weißschuh
  1 sibling, 0 replies; 15+ messages in thread
From: tip-bot2 for Thomas Weißschuh @ 2025-07-19 17:40 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux, Andrew Davis, Lee Jones, Boqun Feng, x86, linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     3b07bb900af7f43f13f9ff398b4c6ca1dee217cd
Gitweb:        https://git.kernel.org/tip/3b07bb900af7f43f13f9ff398b4c6ca1dee217cd
Author:        Thomas Weißschuh <linux@weissschuh.net>
AuthorDate:    Tue, 17 Jun 2025 19:08:13 +02:00
Committer:     Boqun Feng <boqun.feng@gmail.com>
CommitterDate: Fri, 11 Jul 2025 15:11:19 -07:00

leds: lp8860: Check return value of devm_mutex_init()

devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will be
marked as unusable and trigger errors on usage.

Add the missed check.

Fixes: 87a59548af95 ("leds: lp8860: Use new mutex guards to cleanup function exits")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Andrew Davis <afd@ti.com>
Acked-by: Lee Jones <lee@kernel.org>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250617-must_check-devm_mutex_init-v7-2-d9e449f4d224@weissschuh.net
---
 drivers/leds/leds-lp8860.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/leds-lp8860.c b/drivers/leds/leds-lp8860.c
index 52b97c9..0962c00 100644
--- a/drivers/leds/leds-lp8860.c
+++ b/drivers/leds/leds-lp8860.c
@@ -307,7 +307,9 @@ static int lp8860_probe(struct i2c_client *client)
 	led->client = client;
 	led->led_dev.brightness_set_blocking = lp8860_brightness_set;
 
-	devm_mutex_init(&client->dev, &led->lock);
+	ret = devm_mutex_init(&client->dev, &led->lock);
+	if (ret)
+		return dev_err_probe(&client->dev, ret, "Failed to initialize lock\n");
 
 	led->regmap = devm_regmap_init_i2c(client, &lp8860_regmap_config);
 	if (IS_ERR(led->regmap)) {

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

* [tip: locking/core] spi: spi-nxp-fspi: Check return value of devm_mutex_init()
  2025-06-17 17:08 ` [PATCH v7 1/3] spi: spi-nxp-fspi: check return value of devm_mutex_init() Thomas Weißschuh
  2025-06-17 19:02   ` Mark Brown
@ 2025-07-19 17:40   ` tip-bot2 for Thomas Weißschuh
  1 sibling, 0 replies; 15+ messages in thread
From: tip-bot2 for Thomas Weißschuh @ 2025-07-19 17:40 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux, Mark Brown, Boqun Feng, x86, linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     d24a54e032021cf381af3c3cf119cc5cf6b3c1be
Gitweb:        https://git.kernel.org/tip/d24a54e032021cf381af3c3cf119cc5cf6b3c1be
Author:        Thomas Weißschuh <linux@weissschuh.net>
AuthorDate:    Tue, 17 Jun 2025 19:08:12 +02:00
Committer:     Boqun Feng <boqun.feng@gmail.com>
CommitterDate: Fri, 11 Jul 2025 15:02:07 -07:00

spi: spi-nxp-fspi: Check return value of devm_mutex_init()

devm_mutex_init() can fail. With CONFIG_DEBUG_MUTEXES=y the mutex will
be marked as unusable and trigger errors on usage.

Add the missed check.

Fixes: 48900813abd2 ("spi: spi-nxp-fspi: remove the goto in probe")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250617-must_check-devm_mutex_init-v7-1-d9e449f4d224@weissschuh.net
---
 drivers/spi/spi-nxp-fspi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
index e63c77e..f3d5765 100644
--- a/drivers/spi/spi-nxp-fspi.c
+++ b/drivers/spi/spi-nxp-fspi.c
@@ -1273,7 +1273,9 @@ static int nxp_fspi_probe(struct platform_device *pdev)
 	if (ret)
 		return dev_err_probe(dev, ret, "Failed to request irq\n");
 
-	devm_mutex_init(dev, &f->lock);
+	ret = devm_mutex_init(dev, &f->lock);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to initialize lock\n");
 
 	ctlr->bus_num = -1;
 	ctlr->num_chipselect = NXP_FSPI_MAX_CHIPSELECT;

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

end of thread, other threads:[~2025-07-19 17:40 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-17 17:08 [PATCH v7 0/3] locking/mutex: Mark devm_mutex_init() as __must_check Thomas Weißschuh
2025-06-17 17:08 ` [PATCH v7 1/3] spi: spi-nxp-fspi: check return value of devm_mutex_init() Thomas Weißschuh
2025-06-17 19:02   ` Mark Brown
2025-07-19 17:40   ` [tip: locking/core] spi: spi-nxp-fspi: Check " tip-bot2 for Thomas Weißschuh
2025-06-17 17:08 ` [PATCH v7 2/3] leds: lp8860: " Thomas Weißschuh
2025-06-19 12:34   ` (subset) " Lee Jones
2025-06-19 15:34     ` Thomas Weißschuh
2025-06-25  9:04       ` Lee Jones
2025-06-26 10:54         ` Thomas Weißschuh
2025-06-27 12:58           ` Lee Jones
2025-07-19 17:40   ` [tip: locking/core] " tip-bot2 for Thomas Weißschuh
2025-06-17 17:08 ` [PATCH v7 3/3] locking/mutex: Mark devm_mutex_init() as __must_check Thomas Weißschuh
2025-06-17 17:32   ` Boqun Feng
2025-07-19 17:40   ` [tip: locking/core] " tip-bot2 for Thomas Weißschuh
2025-07-11 22:12 ` [PATCH v7 0/3] " Boqun Feng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).