mirror of
https://github.com/torvalds/linux.git
synced 2026-07-31 03:27:03 +02:00
coresight-stm: fix list_add double add issue
In race condition, when stm_source_link_add is called, the link from stm_source to stm device has been established, src->Link_entry has been added to STM->link_list, this is the root cause for this isse. this change add a mutex lock to ensure that only one thread can enter stm_source_link_store(). Change-Id: I8abf4275c590508f316a1337e604a4ed58563626 Signed-off-by: Yuanfang Zhang <quic_yuanfang@quicinc.com>
This commit is contained in:
parent
cb5ed64bbf
commit
c7d62ab557
|
|
@ -1171,12 +1171,14 @@ static ssize_t stm_source_link_store(struct device *dev,
|
|||
struct stm_device *link;
|
||||
int err;
|
||||
|
||||
mutex_lock(&src->link_mutex);
|
||||
stm_source_link_drop(src);
|
||||
|
||||
link = stm_find_device(buf);
|
||||
if (!link)
|
||||
if (!link) {
|
||||
mutex_unlock(&src->link_mutex);
|
||||
return -EINVAL;
|
||||
|
||||
}
|
||||
pm_runtime_get(&link->dev);
|
||||
|
||||
err = stm_source_link_add(src, link);
|
||||
|
|
@ -1185,7 +1187,7 @@ static ssize_t stm_source_link_store(struct device *dev,
|
|||
/* matches the stm_find_device() above */
|
||||
stm_put_device(link);
|
||||
}
|
||||
|
||||
mutex_unlock(&src->link_mutex);
|
||||
return err ? : count;
|
||||
}
|
||||
|
||||
|
|
@ -1251,6 +1253,7 @@ int stm_source_register_device(struct device *parent,
|
|||
|
||||
stm_output_init(&src->output);
|
||||
spin_lock_init(&src->link_lock);
|
||||
mutex_init(&src->link_mutex);
|
||||
INIT_LIST_HEAD(&src->link_entry);
|
||||
src->data = data;
|
||||
data->src = src;
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ void stm_put_device(struct stm_device *stm);
|
|||
struct stm_source_device {
|
||||
struct device dev;
|
||||
struct stm_source_data *data;
|
||||
struct mutex link_mutex;
|
||||
spinlock_t link_lock;
|
||||
struct stm_device __rcu *link;
|
||||
struct list_head link_entry;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user