All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: "Rafael J . Wysocki" <rafael@kernel.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Amit Kucheria <amitk@kernel.org>, Zhang Rui <rui.zhang@intel.com>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH v2 2/9] thermal/core: Delete device under thermal device zone lock
Date: Thu, 10 Nov 2022 07:24:53 -0800	[thread overview]
Message-ID: <20221110152500.3032655-3-linux@roeck-us.net> (raw)
In-Reply-To: <20221110152500.3032655-1-linux@roeck-us.net>

Thermal device attributes may still be opened after unregistering
the thermal zone and deleting the thermal device.

Currently there is no protection against accessing thermal device
operations after unregistering a thermal zone. To enable adding
such protection, protect the device delete operation with the
thermal zone device mutex. This requires splitting the call to
device_unregister() into its components, device_del() and put_device().
Only the first call can be executed under mutex protection, since
put_device() may result in releasing the thermal zone device memory.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v2: No change

 drivers/thermal/thermal_core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index f548875a016d..562ece8d16aa 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1391,7 +1391,12 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
 	thermal_remove_hwmon_sysfs(tz);
 	ida_free(&thermal_tz_ida, tz->id);
 	ida_destroy(&tz->ida);
-	device_unregister(&tz->device);
+
+	mutex_lock(&tz->lock);
+	device_del(&tz->device);
+	mutex_unlock(&tz->lock);
+
+	put_device(&tz->device);
 
 	thermal_notify_tz_delete(tz_id);
 }
-- 
2.36.2


  parent reply	other threads:[~2022-11-10 15:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10 15:24 [PATCH v2 0/9] thermal/core: Protect thermal device operations against removal Guenter Roeck
2022-11-10 15:24 ` [PATCH v2 1/9] thermal/core: Destroy thermal zone device mutex in release function Guenter Roeck
2022-11-10 15:24 ` Guenter Roeck [this message]
2022-11-10 15:24 ` [PATCH v2 3/9] thermal/core: Ensure that thermal device is registered in thermal_zone_get_temp Guenter Roeck
2022-11-10 15:24 ` [PATCH v2 4/9] thermal/core: Move parameter validation from __thermal_zone_get_temp to thermal_zone_get_temp Guenter Roeck
2022-11-10 15:24 ` [PATCH v2 5/9] thermal/core: Introduce locked version of thermal_zone_device_update Guenter Roeck
2022-11-10 15:24 ` [PATCH v2 6/9] thermal/core: Protect hwmon accesses to thermal operations with thermal zone mutex Guenter Roeck
2022-11-10 15:24 ` [PATCH v2 7/9] thermal/core: Protect sysfs " Guenter Roeck
2022-11-10 15:24 ` [PATCH v2 8/9] thermal/core: Remove thermal_zone_set_trips() Guenter Roeck
2022-11-10 15:25 ` [PATCH v2 9/9] thermal/core: Protect thermal device operations against thermal device removal Guenter Roeck
2022-11-14 18:06 ` [PATCH v2 0/9] thermal/core: Protect thermal device operations against removal Rafael J. Wysocki
2022-11-15 13:31   ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221110152500.3032655-3-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=amitk@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.