fsi: Lock mutex for master device registration
authorEddie James <eajames@linux.ibm.com>
Wed, 9 Aug 2023 18:08:14 +0000 (13:08 -0500)
committerJoel Stanley <joel@jms.id.au>
Fri, 11 Aug 2023 04:02:14 +0000 (13:32 +0930)
Because master device registration may cause hub master scans, or
user scans may begin before device registration has ended, so the
master scan lock must be held while registering the device.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
Link: https://lore.kernel.org/r/20230809180814.151984-3-eajames@linux.ibm.com
Signed-off-by: Joel Stanley <joel@jms.id.au>
drivers/fsi/fsi-core.c

index 90872e2e78d1bf6b2bb309fc42959a5b7a0bc9c4..097d5a780264c61800003880277572394b172fa3 100644 (file)
@@ -1326,20 +1326,20 @@ int fsi_master_register(struct fsi_master *master)
 
        master->dev.class = &fsi_master_class;
 
+       mutex_lock(&master->scan_lock);
        rc = device_register(&master->dev);
        if (rc) {
                ida_free(&master_ida, master->idx);
-               return rc;
+               goto out;
        }
 
        np = dev_of_node(&master->dev);
        if (!of_property_read_bool(np, "no-scan-on-init")) {
-               mutex_lock(&master->scan_lock);
                fsi_master_scan(master);
-               mutex_unlock(&master->scan_lock);
        }
-
-       return 0;
+out:
+       mutex_unlock(&master->scan_lock);
+       return rc;
 }
 EXPORT_SYMBOL_GPL(fsi_master_register);