stm class: Fix stm device initialization order
authorAlexander Shishkin <alexander.shishkin@linux.intel.com>
Fri, 4 Mar 2016 14:48:14 +0000 (16:48 +0200)
committerMathieu Poirier <mathieu.poirier@linaro.org>
Wed, 1 Jun 2016 21:42:52 +0000 (15:42 -0600)
Currently, stm_register_device() makes the device visible and then
proceeds to initializing spinlocks and other properties, which leaves
a window when the device can already be opened but is not yet fully
operational.

Fix this by reversing the initialization order.

Reported-by: Alan Cox <alan.cox@intel.com>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Reviewed-by: Laurent Fert <laurent.fert@intel.com>
(cherry picked from commit 389b6699a2aa0b457aa69986e9ddf39f3b4030fd)

drivers/hwtracing/stm/core.c

index 0ffccfdd10175e7c00129225fd48e45a9d7f4cd5..d21eb53ba19986348e926f8f1ebfcb5e3a53197f 100644 (file)
@@ -666,18 +666,11 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data,
        stm->dev.parent = parent;
        stm->dev.release = stm_device_release;
 
-       err = kobject_set_name(&stm->dev.kobj, "%s", stm_data->name);
-       if (err)
-               goto err_device;
-
-       err = device_add(&stm->dev);
-       if (err)
-               goto err_device;
-
        mutex_init(&stm->link_mutex);
        spin_lock_init(&stm->link_lock);
        INIT_LIST_HEAD(&stm->link_list);
 
+       /* initialize the object before it is accessible via sysfs */
        spin_lock_init(&stm->mc_lock);
        mutex_init(&stm->policy_mutex);
        stm->sw_nmasters = nmasters;
@@ -685,6 +678,14 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data,
        stm->data = stm_data;
        stm_data->stm = stm;
 
+       err = kobject_set_name(&stm->dev.kobj, "%s", stm_data->name);
+       if (err)
+               goto err_device;
+
+       err = device_add(&stm->dev);
+       if (err)
+               goto err_device;
+
        return 0;
 
 err_device: