diff --git a/drivers/devfreq/governor_bw_hwmon.c b/drivers/devfreq/governor_bw_hwmon.c index 77a91e8f65ca..fe0071b3db4f 100644 --- a/drivers/devfreq/governor_bw_hwmon.c +++ b/drivers/devfreq/governor_bw_hwmon.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2013-2017, 2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2013-2018, 2019, The Linux Foundation. All rights reserved. */ #define pr_fmt(fmt) "bw-hwmon: " fmt @@ -66,6 +66,7 @@ struct hwmon_node { struct bw_hwmon *hw; struct devfreq_governor *gov; struct attribute_group *attr_grp; + struct mutex mon_lock; }; #define UP_WAKE 1 @@ -493,9 +494,11 @@ int update_bw_hwmon(struct bw_hwmon *hwmon) if (!node) return -ENODEV; - if (!node->mon_started) + mutex_lock(&node->mon_lock); + if (!node->mon_started) { + mutex_unlock(&node->mon_lock); return -EBUSY; - + } dev_dbg(df->dev.parent, "Got update request\n"); devfreq_monitor_stop(df); @@ -507,6 +510,7 @@ int update_bw_hwmon(struct bw_hwmon *hwmon) mutex_unlock(&df->lock); devfreq_monitor_start(df); + mutex_unlock(&node->mon_lock); return 0; } @@ -554,7 +558,9 @@ static void stop_monitor(struct devfreq *df, bool init) struct hwmon_node *node = df->data; struct bw_hwmon *hw = node->hw; + mutex_lock(&node->mon_lock); node->mon_started = false; + mutex_unlock(&node->mon_lock); if (init) { devfreq_monitor_stop(df); @@ -941,6 +947,7 @@ int register_bw_hwmon(struct device *dev, struct bw_hwmon *hwmon) node->mbps_zones[0] = 0; node->hw = hwmon; + mutex_init(&node->mon_lock); mutex_lock(&list_lock); list_add_tail(&node->list, &hwmon_list); mutex_unlock(&list_lock);