From 389b6699a2aa0b457aa69986e9ddf39f3b4030fd Mon Sep 17 00:00:00 2001 From: Alexander Shishkin Date: Fri, 4 Mar 2016 16:48:14 +0200 Subject: [PATCH] stm class: Fix stm device initialization order 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 Signed-off-by: Alexander Shishkin Reviewed-by: Laurent Fert --- drivers/hwtracing/stm/core.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c index e55ed6714223..2591442e2c5b 100644 --- a/drivers/hwtracing/stm/core.c +++ b/drivers/hwtracing/stm/core.c @@ -666,6 +666,18 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data, stm->dev.parent = parent; stm->dev.release = stm_device_release; + 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; + stm->owner = owner; + stm->data = stm_data; + stm_data->stm = stm; + err = kobject_set_name(&stm->dev.kobj, "%s", stm_data->name); if (err) goto err_device; @@ -674,17 +686,6 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data, if (err) goto err_device; - mutex_init(&stm->link_mutex); - spin_lock_init(&stm->link_lock); - INIT_LIST_HEAD(&stm->link_list); - - spin_lock_init(&stm->mc_lock); - mutex_init(&stm->policy_mutex); - stm->sw_nmasters = nmasters; - stm->owner = owner; - stm->data = stm_data; - stm_data->stm = stm; - return 0; err_device: