Skip to content

Commit 8fc0e48

Browse files
krzkchanwoochoi
authored andcommitted
PM / devfreq: Use lockdep asserts instead of manual checks for locked mutex
Instead of warning when mutex_is_locked(), just use the lockdep framework. The code is smaller and checks could be disabled for production environments (it is useful only during development). Put asserts at beginning of function, even before validating arguments. The behavior of update_devfreq() is now changed because lockdep assert will only print a warning, not return with EINVAL. Signed-off-by: Krzysztof Kozlowski <[email protected]> Signed-off-by: Chanwoo Choi <[email protected]>
1 parent 48bbf63 commit 8fc0e48

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

drivers/devfreq/devfreq.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ static struct devfreq *find_device_devfreq(struct device *dev)
6060
{
6161
struct devfreq *tmp_devfreq;
6262

63+
lockdep_assert_held(&devfreq_list_lock);
64+
6365
if (IS_ERR_OR_NULL(dev)) {
6466
pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
6567
return ERR_PTR(-EINVAL);
6668
}
67-
WARN(!mutex_is_locked(&devfreq_list_lock),
68-
"devfreq_list_lock must be locked.");
6969

7070
list_for_each_entry(tmp_devfreq, &devfreq_list, node) {
7171
if (tmp_devfreq->dev.parent == dev)
@@ -258,12 +258,12 @@ static struct devfreq_governor *find_devfreq_governor(const char *name)
258258
{
259259
struct devfreq_governor *tmp_governor;
260260

261+
lockdep_assert_held(&devfreq_list_lock);
262+
261263
if (IS_ERR_OR_NULL(name)) {
262264
pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
263265
return ERR_PTR(-EINVAL);
264266
}
265-
WARN(!mutex_is_locked(&devfreq_list_lock),
266-
"devfreq_list_lock must be locked.");
267267

268268
list_for_each_entry(tmp_governor, &devfreq_governor_list, node) {
269269
if (!strncmp(tmp_governor->name, name, DEVFREQ_NAME_LEN))
@@ -289,12 +289,12 @@ static struct devfreq_governor *try_then_request_governor(const char *name)
289289
struct devfreq_governor *governor;
290290
int err = 0;
291291

292+
lockdep_assert_held(&devfreq_list_lock);
293+
292294
if (IS_ERR_OR_NULL(name)) {
293295
pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
294296
return ERR_PTR(-EINVAL);
295297
}
296-
WARN(!mutex_is_locked(&devfreq_list_lock),
297-
"devfreq_list_lock must be locked.");
298298

299299
governor = find_devfreq_governor(name);
300300
if (IS_ERR(governor)) {
@@ -392,10 +392,7 @@ int update_devfreq(struct devfreq *devfreq)
392392
int err = 0;
393393
u32 flags = 0;
394394

395-
if (!mutex_is_locked(&devfreq->lock)) {
396-
WARN(true, "devfreq->lock must be locked by the caller.\n");
397-
return -EINVAL;
398-
}
395+
lockdep_assert_held(&devfreq->lock);
399396

400397
if (!devfreq->governor)
401398
return -EINVAL;

0 commit comments

Comments
 (0)