From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C68A7CD4F24 for ; Wed, 13 May 2026 09:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=j/v9nDfgdE59ic82vqcYy/v3exAROoZS7Ig6DxjZpqo=; b=AHOLzQNSIhxC7f5NDcOLPtifMz J2awnNVds91Ra3lnzgo0MIfULhtLnljlYN3H4+lZQZBypZ/4IrISbJa6bupp+p25ej6IyFtxuNKXD c3nSUgC4GgCN2sCo/1P8DZrfGeLQAwDF1BsX700UN+NXcJsLUVu7ikrfNgJOG8GyN2KVGbQn8n1B6 fZwdD+rbKjIuac5T9SVHfybVfGSbGEPK2oXj7POvPD39gUifpz+2sTQVXQ0xzlaonV2uNthYb4t/z HTULos9uSStkLcyeiH8JrS6awZuz+qsRd4++uGAO6eVJBknn4Mnr15OUquowTPoftUm4lcuz4MU9m 6hoSNMZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wN67o-00000001xkz-2LNz; Wed, 13 May 2026 09:43:32 +0000 Received: from canpmsgout02.his.huawei.com ([113.46.200.217]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wN67i-00000001xhB-0kRI for linux-arm-kernel@lists.infradead.org; Wed, 13 May 2026 09:43:28 +0000 Received: from mail.maildlp.com (unknown [172.19.162.144]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4gFpHK0V9lzcZyh; Wed, 13 May 2026 17:35:57 +0800 (CST) Received: from kwepemf200017.china.huawei.com (unknown [7.202.181.10]) by mail.maildlp.com (Postfix) with ESMTPS id 615BB40538; Wed, 13 May 2026 17:43:18 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by kwepemf200017.china.huawei.com (7.202.181.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 13 May 2026 17:43:17 +0800 From: Jie Zhan To: , , , , , CC: , , , , , , Subject: [PATCH v2 1/6] devfreq: Use mutex guard in governor_store() Date: Wed, 13 May 2026 17:38:27 +0800 Message-ID: <20260513093832.1645890-2-zhanjie9@hisilicon.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260513093832.1645890-1-zhanjie9@hisilicon.com> References: <20260513093832.1645890-1-zhanjie9@hisilicon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemf200017.china.huawei.com (7.202.181.10) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260513_024326_532719_F2D1786C X-CRM114-Status: GOOD ( 12.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use mutex guard in governor_store() so as to simplify the locking logic. No functional impact intended. Signed-off-by: Jie Zhan --- drivers/devfreq/devfreq.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index f08fc6966eae..7a70dd051644 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -1394,23 +1394,20 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr, if (ret != 1) return -EINVAL; - mutex_lock(&devfreq_list_lock); + guard(mutex)(&devfreq_list_lock); governor = try_then_request_governor(str_governor); - if (IS_ERR(governor)) { - ret = PTR_ERR(governor); - goto out; - } + if (IS_ERR(governor)) + return PTR_ERR(governor); + if (!df->governor) goto start_new_governor; - if (df->governor == governor) { - ret = 0; - goto out; - } else if (IS_SUPPORTED_FLAG(df->governor->flags, IMMUTABLE) - || IS_SUPPORTED_FLAG(governor->flags, IMMUTABLE)) { - ret = -EINVAL; - goto out; - } + if (df->governor == governor) + return count; + + if (IS_SUPPORTED_FLAG(df->governor->flags, IMMUTABLE) || + IS_SUPPORTED_FLAG(governor->flags, IMMUTABLE)) + return -EINVAL; /* * Stop the current governor and remove the specific sysfs files @@ -1420,7 +1417,7 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr, if (ret) { dev_warn(dev, "%s: Governor %s not stopped(%d)\n", __func__, df->governor->name, ret); - goto out; + return ret; } start_new_governor: @@ -1438,7 +1435,7 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr, /* Restore previous governor */ df->governor = prev_governor; if (!df->governor) - goto out; + return ret; ret = df->governor->event_handler(df, DEVFREQ_GOV_START, NULL); if (ret) { @@ -1446,7 +1443,7 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr, "%s: reverting to Governor %s failed (%d)\n", __func__, prev_governor->name, ret); df->governor = NULL; - goto out; + return ret; } } @@ -1455,13 +1452,10 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr, * the new governor, restore the sysfs files of previous governor. */ ret = sysfs_update_group(&df->dev.kobj, &gov_attr_group); + if (ret) + return ret; -out: - mutex_unlock(&devfreq_list_lock); - - if (!ret) - ret = count; - return ret; + return count; } static DEVICE_ATTR_RW(governor); -- 2.43.0