Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2511985ybk; Tue, 12 May 2020 00:58:59 -0700 (PDT) X-Google-Smtp-Source: APiQypJdWA6nDs74UBlel4BDDnmoufTICewPOwA/jdAICmdOzjCOnKQalgmV6EEGwKcvGHdPBx0n X-Received: by 2002:a17:906:cb98:: with SMTP id mf24mr17133609ejb.146.1589270339022; Tue, 12 May 2020 00:58:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589270339; cv=none; d=google.com; s=arc-20160816; b=eSeN+2lCuMfQWmyxtoGZgl89gkptrX6zkXqet35iwQa1T8WuNYmvgV4/nSJ3HmjNYN aymQbI7DfyDx8CyF3B+Xi2lv36O+X3hsQ+8RxhhkyGzE1XWcslSDhU6JV0bvQplTNviS 6fBzy8guef++KiRnbVGbAPlmWEDo1Z3+TaefF+X2ccS8wS/NtLFNG52PfTQ0tUzi+9jo +DzHlEgOQQzfkjYeukqpOjHZm9Mo3RySsKlUIJgTgAbh4lEDSv5YLfAsz1gm1ewCc3t7 BUqeDTnnV5zye3f2lb4WbhOAtap19Ru0Ueytd4Y2vMTOdSRH6A+V1Hr4i4d/9zy3EuhY 7Y9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type :content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:organization:from:to:subject :dkim-signature:dkim-filter; bh=DEqy8ozNTk3fR/BT9xkRbnIvwaU9IqqbHjW3XT7ouCI=; b=VZ9+li+OdoU5nCtd3giIAgnvq3vKPhuYfL/SJPCpKMDQCue4tHTNBc3lSXRNkfSxfl fSPyB+GPeYxO2fk92Hr9ErteXzvpwlGy0fz09RooA9rzkkt7bIFhH6wzIM+pw0v9D5jY 8HC67Le3sXr7nccVU5I4oysrDVyl1FkiJXzii/n+qEdIHYKbgqQj3F7DeMbtj19Fvm5C CG4jcnR7WCWM+EeB79UMsULy8/y1ewtU5jl69FigJPPBCKbYS1idjZ+18As0BmYurZb3 KuThmWcapRVa+A5W8MCk8V7+USwuWWWtXNqpZa7l1Hg8NIyGFjTEoZmbd9V8XTZW7W0F +9fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=m6gGwvf0; 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=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r20si5225175eja.234.2020.05.12.00.58.36; Tue, 12 May 2020 00:58:59 -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=@samsung.com header.s=mail20170921 header.b=m6gGwvf0; 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=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729053AbgELH42 (ORCPT + 99 others); Tue, 12 May 2020 03:56:28 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:63515 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729013AbgELH41 (ORCPT ); Tue, 12 May 2020 03:56:27 -0400 Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20200512075623epoutp031c25f79369b8691a527aa575d8389088~OOM-bqzQl2464524645epoutp03s for ; Tue, 12 May 2020 07:56:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20200512075623epoutp031c25f79369b8691a527aa575d8389088~OOM-bqzQl2464524645epoutp03s DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1589270183; bh=DEqy8ozNTk3fR/BT9xkRbnIvwaU9IqqbHjW3XT7ouCI=; h=Subject:To:From:Date:In-Reply-To:References:From; b=m6gGwvf0mCYP30oLAatibfnoy1Z7qrI2QDZgqv79rh6bc+QRMh6pmjnppL/fOYaJP S8gIFk8IVmGivTgwECaAXtiFhUyoRMlqOehV/fz+Xllg4ASfpXoEVF8wNS/xhAmwQ6 UlLc/ImjZQ8SjePxlcm6VRQYr6Di2B0o2O2tH6+Y= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20200512075623epcas1p4ed7c6f52c91f916934dbd328e66e6cb0~OOM-HTczd0206002060epcas1p4M; Tue, 12 May 2020 07:56:23 +0000 (GMT) Received: from epsmges1p3.samsung.com (unknown [182.195.40.154]) by epsnrtp1.localdomain (Postfix) with ESMTP id 49Lqr54MhMzMqYm3; Tue, 12 May 2020 07:56:21 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p3.samsung.com (Symantec Messaging Gateway) with SMTP id 48.CB.04648.1A65ABE5; Tue, 12 May 2020 16:56:18 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20200512075617epcas1p3a9e9ffd6d719bf40ecb896318392166f~OOM5czL2O1307913079epcas1p3e; Tue, 12 May 2020 07:56:17 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200512075617epsmtrp2015c83ab91834b2e82bc38e773cdda42~OOM5bxW362996129961epsmtrp2Z; Tue, 12 May 2020 07:56:17 +0000 (GMT) X-AuditID: b6c32a37-7215a9e000001228-41-5eba56a1d8a4 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id DF.BF.18461.1A65ABE5; Tue, 12 May 2020 16:56:17 +0900 (KST) Received: from [10.113.221.102] (unknown [10.113.221.102]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200512075617epsmtip2f70baffe6c18a0c8ac361984f2845228~OOM5RtRfn2865128651epsmtip2_; Tue, 12 May 2020 07:56:17 +0000 (GMT) Subject: Re: [PATCH] devfreq: Use lockdep asserts instead of manual checks for locked mutex To: Krzysztof Kozlowski , MyungJoo Ham , Kyungmin Park , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org From: Chanwoo Choi Organization: Samsung Electronics Message-ID: Date: Tue, 12 May 2020 17:06:21 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Thunderbird/59.0 MIME-Version: 1.0 In-Reply-To: <20200512064158.7957-1-krzk@kernel.org> Content-Language: en-US Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprMJsWRmVeSWpSXmKPExsWy7bCmge6isF1xBpP2M1qcP7+B3eJs0xt2 i8u75rBZfO49wmhxu3EFmwOrx6ZVnWwefVtWMXp83iQXwByVbZORmpiSWqSQmpecn5KZl26r 5B0c7xxvamZgqGtoaWGupJCXmJtqq+TiE6DrlpkDtFJJoSwxpxQoFJBYXKykb2dTlF9akqqQ kV9cYquUWpCSU2BZoFecmFtcmpeul5yfa2VoYGBkClSYkJ2xbuZr9oInYhUfJs1kaWDcI9TF yMkhIWAi8WHNaeYuRi4OIYEdjBKT7l6Dcj4xStxaMp0VwvnGKPHuxTQmmJa5U5eyQCT2Mkqs WLkHquU9o8T7RhCHk0NYIFZi058DTCAJEYGdjBJt3RfAEmwCWhL7X9xgA7H5BRQlrv54zAhi 8wrYSby5/wXMZhFQlXja/B5snahAmMTJbS1QNYISJ2c+YQGxOYHOeHh1CyuIzSwgLnHryXwm CFteYvvbOWAXSQi8ZZdYdOotK8TdLhIzpnVB2cISr45vYYewpSQ+v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1OzW1ILUIJsvEwSnVwCTfL3XzoG5vfMfEe/Xn +K6r8iwuOZtyNUsgW/enzEMBYUXOjn1f7yzj4DMqueU7oynyocomM3Gps5PvRBy5k6xYXPn+ 6rzLGipN2lHRC7gCH/qvUnaNYJP3fOS5zHjDibgdIjwHe6OkY25Gz7umyauQHHfq595JFatn XWBwXcjeM817y6z4Y4WJogdSlDjnVtU1mz75NNN++4P8Cc/fR7hNuHX8qPuTp2u7WGTNgxqm Ce1MDFFbsUZQ+8Q7pzRvh2omY+bbXDrTTXesDJ1pH8lgfnKStMTTt002xxLc/a5mnmflrv2v pX7k7mmR3XmZPNdYAwrZP26NC9z3ny3LKdyDae6zO52M7A2HnnCnKLEUZyQaajEXFScCAEhb m4L3AgAA X-CMS-MailID: 20200512075617epcas1p3a9e9ffd6d719bf40ecb896318392166f X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20200512064211epcas1p1f8e6cac8f2927bd703e133282313dd43 References: <20200512064158.7957-1-krzk@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Krzysztof, On 5/12/20 3:41 PM, Krzysztof Kozlowski wrote: > 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; > It is reasonable. It looks good. Applied it. Thank -- Best Regards, Chanwoo Choi Samsung Electronics