fsi: Don't use device_unregister() in fsi_master_register()
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>
Thu, 28 Jun 2018 06:26:19 +0000 (16:26 +1000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Thu, 12 Jul 2018 02:05:11 +0000 (12:05 +1000)
In the error path of fsi_master_register(), we currently
use device_unregister(). This will cause the last reference
to the structure to be dropped, thus freeing the enclosing
structure, which isn't what the callers want.

Use device_del() instead so that we return to the caller
with a refcount of 1. The caller can then assume that it
must use put_device() after a call to fsi_master_register()
regardless of whether the latter suceeded or failed.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
drivers/fsi/fsi-core.c

index 372a9d8a89906cf424ce478a2b431ee2d939874f..e9f8813b75e6e4cdd977b7aba4caf6c07cd542ad 100644 (file)
@@ -977,9 +977,6 @@ int fsi_master_register(struct fsi_master *master)
        int rc;
        struct device_node *np;
 
-       if (!master)
-               return -EINVAL;
-
        master->idx = ida_simple_get(&master_ida, 0, INT_MAX, GFP_KERNEL);
        dev_set_name(&master->dev, "fsi%d", master->idx);
 
@@ -991,14 +988,14 @@ int fsi_master_register(struct fsi_master *master)
 
        rc = device_create_file(&master->dev, &dev_attr_rescan);
        if (rc) {
-               device_unregister(&master->dev);
+               device_del(&master->dev);
                ida_simple_remove(&master_ida, master->idx);
                return rc;
        }
 
        rc = device_create_file(&master->dev, &dev_attr_break);
        if (rc) {
-               device_unregister(&master->dev);
+               device_del(&master->dev);
                ida_simple_remove(&master_ida, master->idx);
                return rc;
        }