Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: linux-hwmon@vger.kernel.org
Cc: Jean Delvare <jdelvare@suse.com>,
	linux-kernel@vger.kernel.org, Guenter Roeck <linux@roeck-us.net>,
	Dmitry Osipenko <dmitry.osipenko@collabora.com>
Subject: [PATCH] hwmon: (lm90) Use worker for alarm notifications
Date: Wed, 29 Jun 2022 08:42:10 -0700	[thread overview]
Message-ID: <20220629154210.2389765-1-linux@roeck-us.net> (raw)

Reporting alarms using hwmon_notify_event() may result in a callback
from the thermal subsystem. This means that such notifications must
not hold the update lock to avoid a deadlock. To avoid this situation,
use a worker to handle notifications.

Reported-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Fixes: e182cf579f0f ("hwmon: (lm90) Rework alarm/status handling")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
Dmitry,

can you give this patch a try in your system ?

Thanks,
Guenter

 drivers/hwmon/lm90.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index 9d878163a1f2..03d07da8c2dc 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -693,6 +693,7 @@ struct lm90_data {
 	struct hwmon_chip_info chip;
 	struct mutex update_lock;
 	struct delayed_work alert_work;
+	struct work_struct report_work;
 	bool valid;		/* true if register values are valid */
 	bool alarms_valid;	/* true if status register values are valid */
 	unsigned long last_updated; /* in jiffies */
@@ -1043,13 +1044,18 @@ static int lm90_update_limits(struct device *dev)
 	return 0;
 }
 
-static void lm90_report_alarms(struct device *dev, struct lm90_data *data)
+static void lm90_report_alarms(struct work_struct *work)
 {
-	u16 cleared_alarms = data->reported_alarms & ~data->current_alarms;
-	u16 new_alarms = data->current_alarms & ~data->reported_alarms;
+	struct lm90_data *data = container_of(work, struct lm90_data, report_work);
+	u16 cleared_alarms, new_alarms, current_alarms;
 	struct device *hwmon_dev = data->hwmon_dev;
+	struct device *dev = &data->client->dev;
 	int st, st2;
 
+	current_alarms = data->current_alarms;
+	cleared_alarms = data->reported_alarms & ~current_alarms;
+	new_alarms = current_alarms & ~data->reported_alarms;
+
 	if (!cleared_alarms && !new_alarms)
 		return;
 
@@ -1101,7 +1107,7 @@ static void lm90_report_alarms(struct device *dev, struct lm90_data *data)
 	if (st2 & MAX6696_STATUS2_R2OT2)
 		hwmon_notify_event(hwmon_dev, hwmon_temp, hwmon_temp_emergency_alarm, 2);
 
-	data->reported_alarms = data->current_alarms;
+	data->reported_alarms = current_alarms;
 }
 
 static int lm90_update_alarms_locked(struct lm90_data *data, bool force)
@@ -1143,7 +1149,7 @@ static int lm90_update_alarms_locked(struct lm90_data *data, bool force)
 			(data->config & 0x80);
 
 		if (force || check_enable)
-			lm90_report_alarms(&client->dev, data);
+			schedule_work(&data->report_work);
 
 		/*
 		 * Re-enable ALERT# output if it was originally enabled, relevant
@@ -2552,6 +2558,7 @@ static void lm90_restore_conf(void *_data)
 	struct i2c_client *client = data->client;
 
 	cancel_delayed_work_sync(&data->alert_work);
+	cancel_work_sync(&data->report_work);
 
 	/* Restore initial configuration */
 	if (data->flags & LM90_HAVE_CONVRATE)
@@ -2769,6 +2776,7 @@ static int lm90_probe(struct i2c_client *client)
 	i2c_set_clientdata(client, data);
 	mutex_init(&data->update_lock);
 	INIT_DELAYED_WORK(&data->alert_work, lm90_alert_work);
+	INIT_WORK(&data->report_work, lm90_report_alarms);
 
 	/* Set the device type */
 	if (client->dev.of_node)
-- 
2.35.1


             reply	other threads:[~2022-06-29 15:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-29 15:42 Guenter Roeck [this message]
2022-06-29 20:02 ` [PATCH] hwmon: (lm90) Use worker for alarm notifications Dmitry Osipenko
2022-06-29 21:18   ` 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=20220629154210.2389765-1-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=dmitry.osipenko@collabora.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox