All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Adamski, Krzysztof (Nokia - PL/Wroclaw)"  <krzysztof.adamski@nokia.com>
To: Guenter Roeck <linux@roeck-us.net>, Jean Delvare <jdelvare@suse.com>
Cc: "linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>,
	"Sverdlin,
	Alexander (Nokia - DE/Ulm)" <alexander.sverdlin@nokia.com>
Subject: [PATCH v2 1/2] pmbus: (core) mutex_lock write in pmbus_set_samples
Date: Wed, 29 May 2019 14:33:52 +0000	[thread overview]
Message-ID: <25c0f33fa281e8fb9781b71bda9e2f570113df85.1559140351.git.krzysztof.adamski@nokia.com> (raw)

update_lock is a mutex intended to protect write operations. It was not
taken, however, when _pmbus_write_word_data is called from
pmbus_set_samples() function which may cause problems especially when
some PMBUS_VIRT_* operation is implemented as a read-modify-write cycle.

This patch makes sure the lock is held during the operation.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
---
 drivers/hwmon/pmbus/pmbus_core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index ef7ee90ee785..62cd213cc260 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -1946,7 +1946,9 @@ static ssize_t pmbus_set_samples(struct device *dev,
 	if (kstrtol(buf, 0, &val) < 0)
 		return -EINVAL;
 
+	mutex_lock(&data->update_lock);
 	ret = _pmbus_write_word_data(client, reg->page, reg->attr->reg, val);
+	mutex_unlock(&data->update_lock);
 
 	return ret ? : count;
 }
-- 
2.20.1


             reply	other threads:[~2019-05-29 14:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-29 14:33 Adamski, Krzysztof (Nokia - PL/Wroclaw) [this message]
2019-05-29 14:36 ` [PATCH v2 2/2] adm1275: support PMBUS_VIRT_*_SAMPLES Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-06-03 13:34   ` Sverdlin, Alexander (Nokia - DE/Ulm)
2019-06-05 20:40   ` Guenter Roeck
2019-06-03 13:08 ` [PATCH v2 1/2] pmbus: (core) mutex_lock write in pmbus_set_samples Sverdlin, Alexander (Nokia - DE/Ulm)
2019-06-05 20:25 ` 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=25c0f33fa281e8fb9781b71bda9e2f570113df85.1559140351.git.krzysztof.adamski@nokia.com \
    --to=krzysztof.adamski@nokia.com \
    --cc=alexander.sverdlin@nokia.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /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.