[PATCH] spi: Use non-atomic xxx_bit() functions

Christophe JAILLET posted 1 patch 2 years, 9 months ago
drivers/spi/spidev.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] spi: Use non-atomic xxx_bit() functions
Posted by Christophe JAILLET 2 years, 9 months ago
Accesses to 'minors' are guarded by the 'device_list_lock' mutex. So, it is
safe to use the non-atomic version of (set|clear)_bit() in the
corresponding sections.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/spi/spidev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 39d94c850839..132fecc02eba 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -812,7 +812,7 @@ static int spidev_probe(struct spi_device *spi)
 		status = -ENODEV;
 	}
 	if (status == 0) {
-		set_bit(minor, minors);
+		__set_bit(minor, minors);
 		list_add(&spidev->device_entry, &device_list);
 	}
 	mutex_unlock(&device_list_lock);
@@ -840,7 +840,7 @@ static void spidev_remove(struct spi_device *spi)
 
 	list_del(&spidev->device_entry);
 	device_destroy(spidev_class, spidev->devt);
-	clear_bit(MINOR(spidev->devt), minors);
+	__clear_bit(MINOR(spidev->devt), minors);
 	if (spidev->users == 0)
 		kfree(spidev);
 	mutex_unlock(&device_list_lock);
-- 
2.34.1
Re: [PATCH] spi: Use non-atomic xxx_bit() functions
Posted by Mark Brown 2 years, 9 months ago
On Sun, Apr 30, 2023 at 11:35:35AM +0200, Christophe JAILLET wrote:

> Accesses to 'minors' are guarded by the 'device_list_lock' mutex. So, it is
> safe to use the non-atomic version of (set|clear)_bit() in the
> corresponding sections.

Is it a problem to use the atomic version?

>  	if (status == 0) {
> -		set_bit(minor, minors);
> +		__set_bit(minor, minors);
>  		list_add(&spidev->device_entry, &device_list);

The __ usually means something is the more complicated and less
preferred API.
Re: [PATCH] spi: Use non-atomic xxx_bit() functions
Posted by Christophe JAILLET 2 years, 9 months ago
Le 30/04/2023 à 17:49, Mark Brown a écrit :
> On Sun, Apr 30, 2023 at 11:35:35AM +0200, Christophe JAILLET wrote:
> 
>> Accesses to 'minors' are guarded by the 'device_list_lock' mutex. So, it is
>> safe to use the non-atomic version of (set|clear)_bit() in the
>> corresponding sections.
> 
> Is it a problem to use the atomic version?

Not at all. It just wastes a few cycles (in a place where it doesn't 
matter).

I spotted it while looking for some other patterns, so I sent a patch 
for it.

> 
>>   	if (status == 0) {
>> -		set_bit(minor, minors);
>> +		__set_bit(minor, minors);
>>   		list_add(&spidev->device_entry, &device_list);
> 
> The __ usually means something is the more complicated and less
> preferred API.

Ok, let keep things as-is and simple then.
Performance doesn't matter here, anyway.

CJ