提交 8fc0e48e 编写于 作者: K Krzysztof Kozlowski 提交者: Chanwoo Choi

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: NKrzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: NChanwoo Choi <cw00.choi@samsung.com>
上级 48bbf637
...@@ -60,12 +60,12 @@ static struct devfreq *find_device_devfreq(struct device *dev) ...@@ -60,12 +60,12 @@ static struct devfreq *find_device_devfreq(struct device *dev)
{ {
struct devfreq *tmp_devfreq; struct devfreq *tmp_devfreq;
lockdep_assert_held(&devfreq_list_lock);
if (IS_ERR_OR_NULL(dev)) { if (IS_ERR_OR_NULL(dev)) {
pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
WARN(!mutex_is_locked(&devfreq_list_lock),
"devfreq_list_lock must be locked.");
list_for_each_entry(tmp_devfreq, &devfreq_list, node) { list_for_each_entry(tmp_devfreq, &devfreq_list, node) {
if (tmp_devfreq->dev.parent == dev) if (tmp_devfreq->dev.parent == dev)
...@@ -258,12 +258,12 @@ static struct devfreq_governor *find_devfreq_governor(const char *name) ...@@ -258,12 +258,12 @@ static struct devfreq_governor *find_devfreq_governor(const char *name)
{ {
struct devfreq_governor *tmp_governor; struct devfreq_governor *tmp_governor;
lockdep_assert_held(&devfreq_list_lock);
if (IS_ERR_OR_NULL(name)) { if (IS_ERR_OR_NULL(name)) {
pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
WARN(!mutex_is_locked(&devfreq_list_lock),
"devfreq_list_lock must be locked.");
list_for_each_entry(tmp_governor, &devfreq_governor_list, node) { list_for_each_entry(tmp_governor, &devfreq_governor_list, node) {
if (!strncmp(tmp_governor->name, name, DEVFREQ_NAME_LEN)) if (!strncmp(tmp_governor->name, name, DEVFREQ_NAME_LEN))
...@@ -289,12 +289,12 @@ static struct devfreq_governor *try_then_request_governor(const char *name) ...@@ -289,12 +289,12 @@ static struct devfreq_governor *try_then_request_governor(const char *name)
struct devfreq_governor *governor; struct devfreq_governor *governor;
int err = 0; int err = 0;
lockdep_assert_held(&devfreq_list_lock);
if (IS_ERR_OR_NULL(name)) { if (IS_ERR_OR_NULL(name)) {
pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
WARN(!mutex_is_locked(&devfreq_list_lock),
"devfreq_list_lock must be locked.");
governor = find_devfreq_governor(name); governor = find_devfreq_governor(name);
if (IS_ERR(governor)) { if (IS_ERR(governor)) {
...@@ -392,10 +392,7 @@ int update_devfreq(struct devfreq *devfreq) ...@@ -392,10 +392,7 @@ int update_devfreq(struct devfreq *devfreq)
int err = 0; int err = 0;
u32 flags = 0; u32 flags = 0;
if (!mutex_is_locked(&devfreq->lock)) { lockdep_assert_held(&devfreq->lock);
WARN(true, "devfreq->lock must be locked by the caller.\n");
return -EINVAL;
}
if (!devfreq->governor) if (!devfreq->governor)
return -EINVAL; return -EINVAL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册