All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hwmon: pmbus: protect read-modify-write with lock
@ 2019-05-30  6:45 Adamski, Krzysztof (Nokia - PL/Wroclaw)
  2019-06-03 13:11 ` Sverdlin, Alexander (Nokia - DE/Ulm)
  0 siblings, 1 reply; 13+ messages in thread
From: Adamski, Krzysztof (Nokia - PL/Wroclaw) @ 2019-05-30  6:45 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare; +Cc: linux-hwmon, linux-kernel

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);
+	return rv;
 }
 EXPORT_SYMBOL_GPL(pmbus_update_fan);
 
-- 
2.20.1


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

* Re: [PATCH] hwmon: pmbus: protect read-modify-write with lock
  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)
  2019-06-03 16:18   ` Guenter Roeck
  0 siblings, 1 reply; 13+ messages in thread
From: Sverdlin, Alexander (Nokia - DE/Ulm) @ 2019-06-03 13:11 UTC (permalink / raw)
  To: Adamski, Krzysztof (Nokia - PL/Wroclaw), Guenter Roeck, Jean Delvare
  Cc: linux-hwmon, linux-kernel

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.

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

* Re: [PATCH] hwmon: pmbus: protect read-modify-write with lock
  2019-06-03 13:11 ` Sverdlin, Alexander (Nokia - DE/Ulm)
@ 2019-06-03 16:18   ` Guenter Roeck
  0 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2019-06-03 16:18 UTC (permalink / raw)
  To: Sverdlin, Alexander (Nokia - DE/Ulm)
  Cc: Adamski, Krzysztof (Nokia - PL/Wroclaw),
	Jean Delvare, linux-hwmon, linux-kernel

On Mon, Jun 03, 2019 at 01:11:45PM +0000, Sverdlin, Alexander (Nokia - DE/Ulm) wrote:
> 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()...
> 

Not only that - it is also recursive.

Guenter

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

* Re: [PATCH] hwmon: pmbus: protect read-modify-write with lock
  2019-06-10  6:36     ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
@ 2019-06-10  7:04       ` Wolfram Sang
  -1 siblings, 0 replies; 13+ messages in thread
From: Wolfram Sang @ 2019-06-10  7:04 UTC (permalink / raw)
  To: Adamski, Krzysztof (Nokia - PL/Wroclaw); +Cc: linux-kernel, linux-i2c

[-- Attachment #1: Type: text/plain, Size: 195 bytes --]

Hi Krzysztof,

> patch and send it to the wrong list of people. You can ignore this
> patchset, it was resent to the proper mailing list instead.

Thanks for the heads up.

Regards,

   Wolfram


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] hwmon: pmbus: protect read-modify-write with lock
@ 2019-06-10  7:04       ` Wolfram Sang
  0 siblings, 0 replies; 13+ messages in thread
From: Wolfram Sang @ 2019-06-10  7:04 UTC (permalink / raw)
  To: Adamski, Krzysztof (Nokia - PL/Wroclaw); +Cc: linux-kernel, linux-i2c

[-- Attachment #1: Type: text/plain, Size: 195 bytes --]

Hi Krzysztof,

> patch and send it to the wrong list of people. You can ignore this
> patchset, it was resent to the proper mailing list instead.

Thanks for the heads up.

Regards,

   Wolfram


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] hwmon: pmbus: protect read-modify-write with lock
  2019-06-07 22:32   ` Wolfram Sang
@ 2019-06-10  6:36     ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
  -1 siblings, 0 replies; 13+ messages in thread
From: Adamski, Krzysztof (Nokia - PL/Wroclaw) @ 2019-06-10  6:36 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-kernel, linux-i2c

On Sat, Jun 08, 2019 at 12:32:18AM +0200, Wolfram Sang wrote:
>On Tue, May 28, 2019 at 09:08:21AM +0000, 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>
>
>Please use get_maintainer to find the people responsible for this file.
>It is not my realm.
>
>> +out:
>> +	mutex_lock(&data->update_lock);
>
>Despite the above, have you tested the code? This likely should be
>mutex_unlock?
>

Sorry for that, I made a mistake and used wrong command to generate the
patch and send it to the wrong list of people. You can ignore this
patchset, it was resent to the proper mailing list instead.

Krzysztof

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

* Re: [PATCH] hwmon: pmbus: protect read-modify-write with lock
@ 2019-06-10  6:36     ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
  0 siblings, 0 replies; 13+ messages in thread
From: Adamski, Krzysztof (Nokia - PL/Wroclaw) @ 2019-06-10  6:36 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-kernel, linux-i2c

On Sat, Jun 08, 2019 at 12:32:18AM +0200, Wolfram Sang wrote:
>On Tue, May 28, 2019 at 09:08:21AM +0000, 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>
>
>Please use get_maintainer to find the people responsible for this file.
>It is not my realm.
>
>> +out:
>> +	mutex_lock(&data->update_lock);
>
>Despite the above, have you tested the code? This likely should be
>mutex_unlock?
>

Sorry for that, I made a mistake and used wrong command to generate the
patch and send it to the wrong list of people. You can ignore this
patchset, it was resent to the proper mailing list instead.

Krzysztof

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

* Re: [PATCH] hwmon: pmbus: protect read-modify-write with lock
  2019-05-28  9:08 ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
@ 2019-06-07 22:32   ` Wolfram Sang
  -1 siblings, 0 replies; 13+ messages in thread
From: Wolfram Sang @ 2019-06-07 22:32 UTC (permalink / raw)
  To: Adamski, Krzysztof (Nokia - PL/Wroclaw); +Cc: linux-kernel, linux-i2c

[-- Attachment #1: Type: text/plain, Size: 661 bytes --]

On Tue, May 28, 2019 at 09:08:21AM +0000, 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>

Please use get_maintainer to find the people responsible for this file.
It is not my realm.

> +out:
> +	mutex_lock(&data->update_lock);

Despite the above, have you tested the code? This likely should be
mutex_unlock?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] hwmon: pmbus: protect read-modify-write with lock
@ 2019-06-07 22:32   ` Wolfram Sang
  0 siblings, 0 replies; 13+ messages in thread
From: Wolfram Sang @ 2019-06-07 22:32 UTC (permalink / raw)
  To: Adamski, Krzysztof (Nokia - PL/Wroclaw); +Cc: linux-kernel, linux-i2c

[-- Attachment #1: Type: text/plain, Size: 661 bytes --]

On Tue, May 28, 2019 at 09:08:21AM +0000, 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>

Please use get_maintainer to find the people responsible for this file.
It is not my realm.

> +out:
> +	mutex_lock(&data->update_lock);

Despite the above, have you tested the code? This likely should be
mutex_unlock?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] hwmon: pmbus: protect read-modify-write with lock
  2019-05-30 17:21 Guenter Roeck
@ 2019-05-31 10:12 ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
  0 siblings, 0 replies; 13+ messages in thread
From: Adamski, Krzysztof (Nokia - PL/Wroclaw) @ 2019-05-31 10:12 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Jean Delvare, linux-hwmon, linux-kernel

On Thu, May 30, 2019 at 10:21:20AM -0700, Guenter Roeck wrote:
>Hi,
>
>On Thu, May 30, 2019 at 06:45:48AM +0000, 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);
>
>Should be mutex_unlock(), meaning you have not tested this ;-).
>
>Either case, I think this is unnecessary. The function is (or should be)
>always called with the lock already taken (ie with pmbus_set_sensor()
>in the call path). If not, we would need a locked and an unlocked version
>of this function to avoid lock recursion.

You've got me :) I did not test that as I do not have a workflow using
this. I just stumbled opon this when looking at the code related to my
other patches. So it was more like a - "hey, shouldn't there be a lock
here?". But I was wrong, thanks.

Krzysztof


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

* Re: [PATCH] hwmon: pmbus: protect read-modify-write with lock
@ 2019-05-30 17:21 Guenter Roeck
  2019-05-31 10:12 ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
  0 siblings, 1 reply; 13+ messages in thread
From: Guenter Roeck @ 2019-05-30 17:21 UTC (permalink / raw)
  To: Adamski, Krzysztof (Nokia - PL/Wroclaw)
  Cc: Jean Delvare, linux-hwmon, linux-kernel

Hi,

On Thu, May 30, 2019 at 06:45:48AM +0000, 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);

Should be mutex_unlock(), meaning you have not tested this ;-).

Either case, I think this is unnecessary. The function is (or should be)
always called with the lock already taken (ie with pmbus_set_sensor()
in the call path). If not, we would need a locked and an unlocked version
of this function to avoid lock recursion.

Thanks,
Guenter

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

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

* [PATCH] hwmon: pmbus: protect read-modify-write with lock
@ 2019-05-28  9:08 ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
  0 siblings, 0 replies; 13+ messages in thread
From: Adamski, Krzysztof (Nokia - PL/Wroclaw) @ 2019-05-28  9:08 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-kernel, linux-i2c

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>
---
 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);
+	return rv;
 }
 EXPORT_SYMBOL_GPL(pmbus_update_fan);
 
-- 
2.20.1


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

* [PATCH] hwmon: pmbus: protect read-modify-write with lock
@ 2019-05-28  9:08 ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
  0 siblings, 0 replies; 13+ messages in thread
From: Adamski, Krzysztof (Nokia - PL/Wroclaw) @ 2019-05-28  9:08 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-kernel, linux-i2c

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>
---
 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);
+	return rv;
 }
 EXPORT_SYMBOL_GPL(pmbus_update_fan);
 
-- 
2.20.1

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

end of thread, other threads:[~2019-06-10  7:04 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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)
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)
2019-05-28  9:08 Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-05-28  9:08 ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-06-07 22:32 ` Wolfram Sang
2019-06-07 22:32   ` Wolfram Sang
2019-06-10  6:36   ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-06-10  6:36     ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-06-10  7:04     ` Wolfram Sang
2019-06-10  7:04       ` Wolfram Sang

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.