diff mbox series

[1/2] fsi: core: Lock scan mutex for master index removal

Message ID 20230412185602.1592629-2-eajames@linux.ibm.com
State New
Headers show
Series fsi: core: Lock scan mutex for master index removal | expand

Commit Message

Eddie James April 12, 2023, 6:56 p.m. UTC
If a master scan occurs while the master is being unregistered,
the devicecs may end up with incorrect and possibly duplicate names,
resulting in kernel warnings. Ensure the master index isn't changed
outside of the scan mutex.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
 drivers/fsi/fsi-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Joel Stanley May 31, 2023, 7:47 a.m. UTC | #1
On Wed, 12 Apr 2023 at 18:56, Eddie James <eajames@linux.ibm.com> wrote:
>
> If a master scan occurs while the master is being unregistered,
> the devicecs may end up with incorrect and possibly duplicate names,

typo: devices

> resulting in kernel warnings. Ensure the master index isn't changed
> outside of the scan mutex.
>
> Signed-off-by: Eddie James <eajames@linux.ibm.com>
> ---
>  drivers/fsi/fsi-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
> index fcbf0469ce3f..18d4d68482d7 100644
> --- a/drivers/fsi/fsi-core.c
> +++ b/drivers/fsi/fsi-core.c
> @@ -1354,12 +1354,12 @@ EXPORT_SYMBOL_GPL(fsi_master_register);
>
>  void fsi_master_unregister(struct fsi_master *master)
>  {
> +       mutex_lock(&master->scan_lock);

The ida functions are supposed to not require locking, but protecting
against the test and changing of ->idx makes sense.

Do you want to add a Fixes: line?

>         if (master->idx >= 0) {
>                 ida_simple_remove(&master_ida, master->idx);

the ida_simple functions are depreciated, at some point we should
replace them with ida_alloc/ida_free.

>                 master->idx = -1;
>         }
>
> -       mutex_lock(&master->scan_lock);
>         fsi_master_unscan(master);
>         mutex_unlock(&master->scan_lock);
>         device_unregister(&master->dev);
> --
> 2.31.1
>
Eddie James June 8, 2023, 4:45 p.m. UTC | #2
On 5/31/23 02:47, Joel Stanley wrote:
> On Wed, 12 Apr 2023 at 18:56, Eddie James <eajames@linux.ibm.com> wrote:
>> If a master scan occurs while the master is being unregistered,
>> the devicecs may end up with incorrect and possibly duplicate names,
> typo: devices


Thanks...



>
>> resulting in kernel warnings. Ensure the master index isn't changed
>> outside of the scan mutex.
>>
>> Signed-off-by: Eddie James <eajames@linux.ibm.com>
>> ---
>>   drivers/fsi/fsi-core.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
>> index fcbf0469ce3f..18d4d68482d7 100644
>> --- a/drivers/fsi/fsi-core.c
>> +++ b/drivers/fsi/fsi-core.c
>> @@ -1354,12 +1354,12 @@ EXPORT_SYMBOL_GPL(fsi_master_register);
>>
>>   void fsi_master_unregister(struct fsi_master *master)
>>   {
>> +       mutex_lock(&master->scan_lock);
> The ida functions are supposed to not require locking, but protecting
> against the test and changing of ->idx makes sense.
>
> Do you want to add a Fixes: line?


Sure.


>
>>          if (master->idx >= 0) {
>>                  ida_simple_remove(&master_ida, master->idx);
> the ida_simple functions are depreciated, at some point we should
> replace them with ida_alloc/ida_free.


OK, I'll see if it makes sense to do that now.

Thanks!

Eddie


>
>>                  master->idx = -1;
>>          }
>>
>> -       mutex_lock(&master->scan_lock);
>>          fsi_master_unscan(master);
>>          mutex_unlock(&master->scan_lock);
>>          device_unregister(&master->dev);
>> --
>> 2.31.1
>>
diff mbox series

Patch

diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
index fcbf0469ce3f..18d4d68482d7 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -1354,12 +1354,12 @@  EXPORT_SYMBOL_GPL(fsi_master_register);
 
 void fsi_master_unregister(struct fsi_master *master)
 {
+	mutex_lock(&master->scan_lock);
 	if (master->idx >= 0) {
 		ida_simple_remove(&master_ida, master->idx);
 		master->idx = -1;
 	}
 
-	mutex_lock(&master->scan_lock);
 	fsi_master_unscan(master);
 	mutex_unlock(&master->scan_lock);
 	device_unregister(&master->dev);