Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2473919ybk; Mon, 11 May 2020 23:44:14 -0700 (PDT) X-Google-Smtp-Source: APiQypKOpTeZCKJd0tuOvg4dXm67LhBjlixNL0ALtCq7kSaIC4rjrGOsG92dTJRCCsvW5dEYn014 X-Received: by 2002:a05:6402:1515:: with SMTP id f21mr16967041edw.370.1589265854284; Mon, 11 May 2020 23:44:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589265854; cv=none; d=google.com; s=arc-20160816; b=S7eZ3iG61adwTRIUddcYtcPJMB432kZvWq4tZsNm9+IYVpropQo6HcrZgurYHPDcES C3ywZ5yE/U7RQhcbYRmingVT2HYUdpFEd2nftyFcSDuapsVz+26b7FXxwq2X1oVd6mzY ZmUcW79mOcoX9xk4rTTKFd1MtTINKu2XaHjFrudBSs0QTDY9PdngyV5crexddHAQK4YF ymWrwS95SLrCj15PIBN1LJX0kLWFYgrg+r+QldPDZi6lIGHSWqyyJQISv4RT8QjPuQAK AmSm7fYIkpX90OMQo6GMD1fYk5+gjEVEmKMKTYjZfAw0rINCqVWitL/iQ97je5bsnama 0GNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=rHOs/Lrhrmfj6ym52g/IWhafoGeg4Fi8w+3qw9YN5TA=; b=FKSYqsWyi//qy2Pa+DrZIvIdzwI3hav34QTy0WRQuPOH9q+mEdosEjRXC7h656OsiN t0tAIUWIf/KQlCJQnORj274HXT8gY9Vip9E3Qd2NFvjqKIG5VjUU8v7kY7qW/XHQ8O+b P0KdJwv7M9M698VIlDUIevG07VlcuLWRPjvby0Kj+aksTOX8/qwK1qUKgEhoKZ9pRX7k wJg5Lowoh8MLZP5LbxrcFNGLPKivAAQ7j4c7TE36sgRvHLvKUufGnFqTHNUmDQoXgIIh bTcIOPkZGPfv1yyhG+hYtibsoBLfy4/v/KsROYeninAA+/u1Przr7ZV4jpZ069JW3+yt TOLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=taEzXckU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i18si6895667edr.464.2020.05.11.23.43.51; Mon, 11 May 2020 23:44:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=taEzXckU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728697AbgELGmJ (ORCPT + 99 others); Tue, 12 May 2020 02:42:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:45632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725536AbgELGmI (ORCPT ); Tue, 12 May 2020 02:42:08 -0400 Received: from kozik-lap.mshome.net (unknown [194.230.155.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AE03B20575; Tue, 12 May 2020 06:42:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589265728; bh=/twyJJ9dZnGQh92dBReEWJHuGeydxSxiQp7BLmW7c7o=; h=From:To:Cc:Subject:Date:From; b=taEzXckUt0vlcJ9f68oz31J364YSwNW5+KCBizpQ4D4/vsC34fDLCcLBk7STZEc/F HyNU4ON4ZTdftIASirnYBNZHzkM0WcuNsi5YP3/kUJbMLARc3piOna09c6+XrbeLTM gahpFbWGga3D8ejRHtplh60Zq23alEdJbzz/+yWk= From: Krzysztof Kozlowski To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski Subject: [PATCH] devfreq: Use lockdep asserts instead of manual checks for locked mutex Date: Tue, 12 May 2020 08:41:58 +0200 Message-Id: <20200512064158.7957-1-krzk@kernel.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/devfreq/devfreq.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index ef3d2bc3d1ac..52b9c3e141f3 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -60,12 +60,12 @@ static struct devfreq *find_device_devfreq(struct device *dev) { struct devfreq *tmp_devfreq; + lockdep_assert_held(&devfreq_list_lock); + if (IS_ERR_OR_NULL(dev)) { pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); 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) { if (tmp_devfreq->dev.parent == dev) @@ -258,12 +258,12 @@ static struct devfreq_governor *find_devfreq_governor(const char *name) { struct devfreq_governor *tmp_governor; + lockdep_assert_held(&devfreq_list_lock); + if (IS_ERR_OR_NULL(name)) { pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); 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) { if (!strncmp(tmp_governor->name, name, DEVFREQ_NAME_LEN)) @@ -289,12 +289,12 @@ static struct devfreq_governor *try_then_request_governor(const char *name) struct devfreq_governor *governor; int err = 0; + lockdep_assert_held(&devfreq_list_lock); + if (IS_ERR_OR_NULL(name)) { pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); return ERR_PTR(-EINVAL); } - WARN(!mutex_is_locked(&devfreq_list_lock), - "devfreq_list_lock must be locked."); governor = find_devfreq_governor(name); if (IS_ERR(governor)) { @@ -392,10 +392,7 @@ int update_devfreq(struct devfreq *devfreq) int err = 0; u32 flags = 0; - if (!mutex_is_locked(&devfreq->lock)) { - WARN(true, "devfreq->lock must be locked by the caller.\n"); - return -EINVAL; - } + lockdep_assert_held(&devfreq->lock); if (!devfreq->governor) return -EINVAL; -- 2.17.1