Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: "Sverdlin, Alexander (Nokia - DE/Ulm)" <alexander.sverdlin@nokia.com>
To: "Adamski,
	Krzysztof (Nokia - PL/Wroclaw)"  <krzysztof.adamski@nokia.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Jean Delvare <jdelvare@suse.com>
Cc: "linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] hwmon: pmbus: protect read-modify-write with lock
Date: Mon, 3 Jun 2019 13:11:45 +0000	[thread overview]
Message-ID: <5ecab585-7e74-ea9f-8d33-93ab024e1a14@nokia.com> (raw)
In-Reply-To: <20190530064509.GA13789@localhost.localdomain>

Hi!

On 30/05/2019 08:45, Adamski, Krzysztof (Nokia - PL/Wroclaw) wrote:
> The operation done in the pmbus_update_fan() function is a
> read-modify-write operation but it lacks any kind of lock protection
> which may cause problems if run more than once simultaneously. This
> patch uses an existing update_lock mutex to fix this problem.
> 
> Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
> ---
> 
> I'm resending this patch to proper recipients this time. Sorry if the
> previous submission confused anybody.
> 
>  drivers/hwmon/pmbus/pmbus_core.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index ef7ee90ee785..94adbede7912 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -268,6 +268,7 @@ int pmbus_update_fan(struct i2c_client *client, int page, int id,
>  	int rv;
>  	u8 to;
>  
> +	mutex_lock(&data->update_lock);
>  	from = pmbus_read_byte_data(client, page,
>  				    pmbus_fan_config_registers[id]);
>  	if (from < 0)
> @@ -278,11 +279,15 @@ int pmbus_update_fan(struct i2c_client *client, int page, int id,
>  		rv = pmbus_write_byte_data(client, page,
>  					   pmbus_fan_config_registers[id], to);
>  		if (rv < 0)
> -			return rv;
> +			goto out;
>  	}
>  
> -	return _pmbus_write_word_data(client, page,
> -				      pmbus_fan_command_registers[id], command);
> +	rv = _pmbus_write_word_data(client, page,
> +				    pmbus_fan_command_registers[id], command);
> +
> +out:
> +	mutex_lock(&data->update_lock);

This has to be mutex_unlock()...

> +	return rv;
>  }
>  EXPORT_SYMBOL_GPL(pmbus_update_fan);

-- 
Best regards,
Alexander Sverdlin.

  reply	other threads:[~2019-06-03 13:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-30  6:45 [PATCH] hwmon: pmbus: protect read-modify-write with lock Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-06-03 13:11 ` Sverdlin, Alexander (Nokia - DE/Ulm) [this message]
2019-06-03 16:18   ` Guenter Roeck
  -- strict thread matches above, loose matches on Subject: below --
2019-05-30 17:21 Guenter Roeck
2019-05-31 10:12 ` Adamski, Krzysztof (Nokia - PL/Wroclaw)

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=5ecab585-7e74-ea9f-8d33-93ab024e1a14@nokia.com \
    --to=alexander.sverdlin@nokia.com \
    --cc=jdelvare@suse.com \
    --cc=krzysztof.adamski@nokia.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox