linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwmon: (occ) Lock mutex in shutdown to prevent race with occ_active
@ 2022-06-06 18:54 Eddie James
  2022-06-07 12:46 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Eddie James @ 2022-06-06 18:54 UTC (permalink / raw)
  To: linux-hwmon; +Cc: linux, Eddie James

Unbinding the driver or removing the parent device at the same time
as using the OCC active sysfs file can cause the driver to unregister
the hwmon device twice. Prevent this by locking the occ mutex in the
shutdown function.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
 drivers/hwmon/occ/common.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/hwmon/occ/common.c b/drivers/hwmon/occ/common.c
index d78f4bebc718..ea070b91e5b9 100644
--- a/drivers/hwmon/occ/common.c
+++ b/drivers/hwmon/occ/common.c
@@ -1228,10 +1228,15 @@ EXPORT_SYMBOL_GPL(occ_setup);
 
 void occ_shutdown(struct occ *occ)
 {
+	mutex_lock(&occ->lock);
+
 	occ_shutdown_sysfs(occ);
 
 	if (occ->hwmon)
 		hwmon_device_unregister(occ->hwmon);
+	occ->hwmon = NULL;
+
+	mutex_unlock(&occ->lock);
 }
 EXPORT_SYMBOL_GPL(occ_shutdown);
 
-- 
2.31.1


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

* Re: [PATCH] hwmon: (occ) Lock mutex in shutdown to prevent race with occ_active
  2022-06-06 18:54 [PATCH] hwmon: (occ) Lock mutex in shutdown to prevent race with occ_active Eddie James
@ 2022-06-07 12:46 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2022-06-07 12:46 UTC (permalink / raw)
  To: Eddie James; +Cc: linux-hwmon

On Mon, Jun 06, 2022 at 01:54:55PM -0500, Eddie James wrote:
> Unbinding the driver or removing the parent device at the same time
> as using the OCC active sysfs file can cause the driver to unregister
> the hwmon device twice. Prevent this by locking the occ mutex in the
> shutdown function.
> 
> Signed-off-by: Eddie James <eajames@linux.ibm.com>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/occ/common.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/hwmon/occ/common.c b/drivers/hwmon/occ/common.c
> index d78f4bebc718..ea070b91e5b9 100644
> --- a/drivers/hwmon/occ/common.c
> +++ b/drivers/hwmon/occ/common.c
> @@ -1228,10 +1228,15 @@ EXPORT_SYMBOL_GPL(occ_setup);
>  
>  void occ_shutdown(struct occ *occ)
>  {
> +	mutex_lock(&occ->lock);
> +
>  	occ_shutdown_sysfs(occ);
>  
>  	if (occ->hwmon)
>  		hwmon_device_unregister(occ->hwmon);
> +	occ->hwmon = NULL;
> +
> +	mutex_unlock(&occ->lock);
>  }
>  EXPORT_SYMBOL_GPL(occ_shutdown);
>  

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

end of thread, other threads:[~2022-06-07 12:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-06 18:54 [PATCH] hwmon: (occ) Lock mutex in shutdown to prevent race with occ_active Eddie James
2022-06-07 12:46 ` Guenter Roeck

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).