Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4690923iob; Sun, 8 May 2022 22:09:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpjDbsaluAHgLin88mr+Dfw2vKZKtX1XmYe/SeJZ3NC+Skl04CFkACSMVvTGAZv3kZgvzY X-Received: by 2002:a17:903:11c4:b0:15f:14df:a919 with SMTP id q4-20020a17090311c400b0015f14dfa919mr2716326plh.21.1652072942314; Sun, 08 May 2022 22:09:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652072942; cv=none; d=google.com; s=arc-20160816; b=OMeis1jODTRY+qMDUuPJxgg1fr/WV786I3uYE/dmNhJD9DOJiEybmZLAORdrm2lc1l pn/jvExEqR9kWYpD/hbSz1CeomhPRhpAb2HZ5XpSJq3Bs69nnPvj/ed3OqmFhSD3P+9K vYyrzduHuF7ywDEdaq/PLDI49f3h3J/z6EeFypL7byVwt0jwZFe2GuZNHTG3RrTzNSxv StvE7GJzUy+tr5Fx7UcoctHf70sxITRY1hy0/EuGHKnLX+T1E6af1QI+WJq7Rn0ghhqU mXSHhrikG9wVAe0Si7HrVfLL1avZmVPo7Jfp8ypAG+AmB9m3tauwwkiIKLjZwCEkzml5 IvSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3hv4at3JYf4y09rWLgIApsDSX2KKaSl4kYTsB/P5mJ0=; b=Vt0ymqvQ+EVonew/c/NRF7UO5hCzZxC+0jaX1dRJdF3LN9rM1aE+qnuaDAXR5SxKsJ zPGj+2R9fYosQOjr36TaodDSzHCpABSHGmJ0SjkcBvtHGVi8GhH3HnDbjltEmnzzzWqT 2VZ6A8+0F36YZQy4NN/AmGbBqseja9eDKcb91eb1Zf5FTBOsPtK733EAhW8Ul75q5Goq 6eVPFm+XOETA1ZaD3S2yRTHqM86/kfjRWCuHKdjVwrCM0p2tw5j9UITKVYCMoBEf2Q1p UWd5zTZHvovh2A2NHQ+Wf56zpHMxLVX/WzQG4SrWOJ47/eBe8DpYt58GcLfiIUvPk56S SosA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gua7RI8q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id ay8-20020a1709028b8800b0015c96aea0c1si9632833plb.270.2022.05.08.22.09.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 22:09:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gua7RI8q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 80B593A5CE; Sun, 8 May 2022 22:02:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444029AbiEFREe (ORCPT + 99 others); Fri, 6 May 2022 13:04:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382740AbiEFREd (ORCPT ); Fri, 6 May 2022 13:04:33 -0400 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C477423BF2; Fri, 6 May 2022 10:00:49 -0700 (PDT) Received: by mail-il1-x131.google.com with SMTP id z12so5163450ilp.8; Fri, 06 May 2022 10:00:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3hv4at3JYf4y09rWLgIApsDSX2KKaSl4kYTsB/P5mJ0=; b=gua7RI8qZk25ZAewCZAiAJMawwqFhhz80joRswrrSwHhsVDCOOYu8i13fjCzBt77/h NbNLUJDn8YVcp1T+41qtfChmCn5sms9aEYSKHPEUFPjKcWBvSgi2cSMdHJb/lJ8Rkvz+ X2anB5H7ASVH7YcisrXDldbK8a3ib96x3P5dL08H/Rcybuo+zLoc9AA6dRB1m/ubO4dF Fha/oqnTvNexNyXgQgkDoLs44Yt0NUj037nxdZaV2JfHyv3ZxHmgu7FeN5koqiKFiSwp IX7eH+Yic3HhFj4z4mEikD/Zhgyb0iSyeRznbJVTZhpmXlFiF8PCQ0akxhk6PRcU/cge PEmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3hv4at3JYf4y09rWLgIApsDSX2KKaSl4kYTsB/P5mJ0=; b=bk0GOKLQu4+KMDvfYPa3X/7/QFTMe/TdtM2kuM3ZskuL2W/UZP/rW7/gijgdySK+iH DwgTGyZ3r4WJ+LDPE5dSvQ8BkCC1vc/h0HHRyvEcrZ6Nkt9d4pkuOEom4fj4R7iiday6 qZw7lkd7iGfGW3XvtlYpubxbB4VkfiszkbfgnSSz30A8jBEDhcfQrz4EW5deiy+Xls5p HNfQtxoBX5rgei47Y8gnqZURXg0Q5iA+/gu/KTU6PA9onE9NDaSMrz6IIsjA/WMQVgus uBDSTMuw7mDDAMvMSZ1QQ3L22cltQ1jn/jtE/8zBhfHMCT6K4Q3onjzg2hcObwr0fMaU eGTA== X-Gm-Message-State: AOAM530JUse//jvhNiUFPz+pMFUbpTLt3YbJbpAZwb+QkzXYf5lPCJ1l nq9oixlea94EOvyi0WQ245ODiGbGG3TguXxK X-Received: by 2002:a05:6e02:198e:b0:2cf:4a7a:faf8 with SMTP id g14-20020a056e02198e00b002cf4a7afaf8mr1589453ilf.206.1651856449165; Fri, 06 May 2022 10:00:49 -0700 (PDT) Received: from localhost (ec2-13-59-0-164.us-east-2.compute.amazonaws.com. [13.59.0.164]) by smtp.gmail.com with UTF8SMTPSA id f21-20020a05660215d500b0065a47e16f63sm1411863iow.53.2022.05.06.10.00.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 May 2022 10:00:48 -0700 (PDT) From: Schspa Shi To: rafael@kernel.org, viresh.kumar@linaro.org, dan.carpenter@oracle.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, schspa@gmail.com Subject: [PATCH] cpufreq: fix double unlock when cpufreq online Date: Sat, 7 May 2022 01:00:35 +0800 Message-Id: <20220506170035.32115-1-schspa@gmail.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20220506072146.GD4031@kadam> References: <20220506072146.GD4031@kadam> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch f346e96267cd: ("cpufreq: Fix possible race in cpufreq online error path") expand the critical region. But policy->rwsem is not held when calling cpufreq_driver->online and cpufreq_driver->init calls, which lead to bad unlock. And it's well to hold this lock when calling cpufreq_driver->online, which provide more protects without bad influence. Fixes: f346e96267cd: ("cpufreq: Fix possible race in cpufreq online error path") Link: https://lore.kernel.org/all/YnKZCGaig+EXSowf@kili/ Reported-by: Dan Carpenter Signed-off-by: Schspa Shi --- drivers/cpufreq/cpufreq.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 0d58b0f8f3af..43dfaa8124e2 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1337,12 +1337,12 @@ static int cpufreq_online(unsigned int cpu) down_write(&policy->rwsem); policy->cpu = cpu; policy->governor = NULL; - up_write(&policy->rwsem); } else { new_policy = true; policy = cpufreq_policy_alloc(cpu); if (!policy) return -ENOMEM; + down_write(&policy->rwsem); } if (!new_policy && cpufreq_driver->online) { @@ -1382,7 +1382,6 @@ static int cpufreq_online(unsigned int cpu) cpumask_copy(policy->related_cpus, policy->cpus); } - down_write(&policy->rwsem); /* * affected cpus must always be the one, which are online. We aren't * managing offline cpus here. @@ -1542,9 +1541,9 @@ static int cpufreq_online(unsigned int cpu) cpufreq_driver->exit(policy); cpumask_clear(policy->cpus); - up_write(&policy->rwsem); out_free_policy: + up_write(&policy->rwsem); cpufreq_policy_free(policy); return ret; } -- 2.24.3 (Apple Git-128)