Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <krzk@kernel.org>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>

authored by

Krzysztof Kozlowski and committed by
Chanwoo Choi
8fc0e48e 48bbf637

+7 -10
+7 -10
drivers/devfreq/devfreq.c
··· 60 60 { 61 61 struct devfreq *tmp_devfreq; 62 62 63 + lockdep_assert_held(&devfreq_list_lock); 64 + 63 65 if (IS_ERR_OR_NULL(dev)) { 64 66 pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); 65 67 return ERR_PTR(-EINVAL); 66 68 } 67 - WARN(!mutex_is_locked(&devfreq_list_lock), 68 - "devfreq_list_lock must be locked."); 69 69 70 70 list_for_each_entry(tmp_devfreq, &devfreq_list, node) { 71 71 if (tmp_devfreq->dev.parent == dev) ··· 258 258 { 259 259 struct devfreq_governor *tmp_governor; 260 260 261 + lockdep_assert_held(&devfreq_list_lock); 262 + 261 263 if (IS_ERR_OR_NULL(name)) { 262 264 pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); 263 265 return ERR_PTR(-EINVAL); 264 266 } 265 - WARN(!mutex_is_locked(&devfreq_list_lock), 266 - "devfreq_list_lock must be locked."); 267 267 268 268 list_for_each_entry(tmp_governor, &devfreq_governor_list, node) { 269 269 if (!strncmp(tmp_governor->name, name, DEVFREQ_NAME_LEN)) ··· 289 289 struct devfreq_governor *governor; 290 290 int err = 0; 291 291 292 + lockdep_assert_held(&devfreq_list_lock); 293 + 292 294 if (IS_ERR_OR_NULL(name)) { 293 295 pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); 294 296 return ERR_PTR(-EINVAL); 295 297 } 296 - WARN(!mutex_is_locked(&devfreq_list_lock), 297 - "devfreq_list_lock must be locked."); 298 298 299 299 governor = find_devfreq_governor(name); 300 300 if (IS_ERR(governor)) { ··· 392 392 int err = 0; 393 393 u32 flags = 0; 394 394 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); 399 396 400 397 if (!devfreq->governor) 401 398 return -EINVAL;