mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/xe/hwmon: Use devm_mutex_init()
@ 2025-09-07 13:42 Christophe JAILLET
  2025-09-08 18:47 ` Summers, Stuart
  2025-09-09 13:40 ` Lucas De Marchi
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2025-09-07 13:42 UTC (permalink / raw)
  To: Lucas De Marchi, Thomas Hellström, Rodrigo Vivi,
	David Airlie, Simona Vetter
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, intel-xe, dri-devel

Use devm_mutex_init() instead of hand-writing it.

This saves some LoC, improves readability and saves some space in the
generated .o file.

Before:
======
   text	   data	    bss	    dec	    hex	filename
  36884	  10296	     64	  47244	   b88c	drivers/gpu/drm/xe/xe_hwmon.o

After:
=====
   text	   data	    bss	    dec	    hex	filename
  36651	  10224	     64	  46939	   b75b	drivers/gpu/drm/xe/xe_hwmon.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/gpu/drm/xe/xe_hwmon.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
index 32a76ae6e9dc..e65382d4426a 100644
--- a/drivers/gpu/drm/xe/xe_hwmon.c
+++ b/drivers/gpu/drm/xe/xe_hwmon.c
@@ -1294,13 +1294,6 @@ xe_hwmon_get_preregistration_info(struct xe_hwmon *hwmon)
 			xe_hwmon_fan_input_read(hwmon, channel, &fan_speed);
 }
 
-static void xe_hwmon_mutex_destroy(void *arg)
-{
-	struct xe_hwmon *hwmon = arg;
-
-	mutex_destroy(&hwmon->hwmon_lock);
-}
-
 int xe_hwmon_register(struct xe_device *xe)
 {
 	struct device *dev = xe->drm.dev;
@@ -1319,8 +1312,7 @@ int xe_hwmon_register(struct xe_device *xe)
 	if (!hwmon)
 		return -ENOMEM;
 
-	mutex_init(&hwmon->hwmon_lock);
-	ret = devm_add_action_or_reset(dev, xe_hwmon_mutex_destroy, hwmon);
+	ret = devm_mutex_init(dev, &hwmon->hwmon_lock);
 	if (ret)
 		return ret;
 
-- 
2.51.0


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

* Re: [PATCH] drm/xe/hwmon: Use devm_mutex_init()
  2025-09-07 13:42 [PATCH] drm/xe/hwmon: Use devm_mutex_init() Christophe JAILLET
@ 2025-09-08 18:47 ` Summers, Stuart
  2025-09-09 13:40 ` Lucas De Marchi
  1 sibling, 0 replies; 3+ messages in thread
From: Summers, Stuart @ 2025-09-08 18:47 UTC (permalink / raw)
  To: simona, Vivi, Rodrigo, christophe.jaillet, De Marchi, Lucas,
	thomas.hellstrom, airlied
  Cc: intel-xe, dri-devel, kernel-janitors, linux-kernel

On Sun, 2025-09-07 at 15:42 +0200, Christophe JAILLET wrote:
> Use devm_mutex_init() instead of hand-writing it.
> 
> This saves some LoC, improves readability and saves some space in the
> generated .o file.
> 
> Before:
> ======
>    text    data     bss     dec     hex filename
>   36884   10296      64   47244    b88c drivers/gpu/drm/xe/xe_hwmon.o
> 
> After:
> =====
>    text    data     bss     dec     hex filename
>   36651   10224      64   46939    b75b drivers/gpu/drm/xe/xe_hwmon.o
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/gpu/drm/xe/xe_hwmon.c | 10 +---------
>  1 file changed, 1 insertion(+), 9 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_hwmon.c
> b/drivers/gpu/drm/xe/xe_hwmon.c
> index 32a76ae6e9dc..e65382d4426a 100644
> --- a/drivers/gpu/drm/xe/xe_hwmon.c
> +++ b/drivers/gpu/drm/xe/xe_hwmon.c
> @@ -1294,13 +1294,6 @@ xe_hwmon_get_preregistration_info(struct
> xe_hwmon *hwmon)
>                         xe_hwmon_fan_input_read(hwmon, channel,
> &fan_speed);
>  }
>  
> -static void xe_hwmon_mutex_destroy(void *arg)
> -{
> -       struct xe_hwmon *hwmon = arg;
> -
> -       mutex_destroy(&hwmon->hwmon_lock);
> -}
> -
>  int xe_hwmon_register(struct xe_device *xe)
>  {
>         struct device *dev = xe->drm.dev;
> @@ -1319,8 +1312,7 @@ int xe_hwmon_register(struct xe_device *xe)
>         if (!hwmon)
>                 return -ENOMEM;
>  
> -       mutex_init(&hwmon->hwmon_lock);
> -       ret = devm_add_action_or_reset(dev, xe_hwmon_mutex_destroy,
> hwmon);
> +       ret = devm_mutex_init(dev, &hwmon->hwmon_lock);

Thanks for the patch! Yes I agree this looks better. And we don't want
to use drmm_mutex_init() here because, as was detailed in an earlier
fix here, we can't mix devm_kzalloc with drmm_mutex_init or risk a uaf.

Reviewed-by: Stuart Summers <stuart.summers@intel.com>

>         if (ret)
>                 return ret;
>  


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

* Re: [PATCH] drm/xe/hwmon: Use devm_mutex_init()
  2025-09-07 13:42 [PATCH] drm/xe/hwmon: Use devm_mutex_init() Christophe JAILLET
  2025-09-08 18:47 ` Summers, Stuart
@ 2025-09-09 13:40 ` Lucas De Marchi
  1 sibling, 0 replies; 3+ messages in thread
From: Lucas De Marchi @ 2025-09-09 13:40 UTC (permalink / raw)
  To: Thomas Hellström, Rodrigo Vivi, David Airlie, Simona Vetter,
	Christophe JAILLET
  Cc: Lucas De Marchi, linux-kernel, kernel-janitors, intel-xe, dri-devel


On Sun, 07 Sep 2025 15:42:17 +0200, Christophe JAILLET wrote:
> Use devm_mutex_init() instead of hand-writing it.
> 
> This saves some LoC, improves readability and saves some space in the
> generated .o file.
> 
> Before:
> ======
>    text	   data	    bss	    dec	    hex	filename
>   36884	  10296	     64	  47244	   b88c	drivers/gpu/drm/xe/xe_hwmon.o
> 
> [...]

Applied to drm-xe-next, thanks!

[1/1] drm/xe/hwmon: Use devm_mutex_init()
      commit: 7b77941724628e6171a286edbf04d67a1f1c1459

Best regards,
-- 
Lucas De Marchi


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

end of thread, other threads:[~2025-09-09 13:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-07 13:42 [PATCH] drm/xe/hwmon: Use devm_mutex_init() Christophe JAILLET
2025-09-08 18:47 ` Summers, Stuart
2025-09-09 13:40 ` Lucas De Marchi

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

all inboxes | Powered by JetHome®