From patchwork Thu Aug 17 07:47:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liao Chang X-Patchwork-Id: 135925 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp875721vqi; Thu, 17 Aug 2023 10:57:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGK/uz0t33mlBV//CexI8PiEZxfTCKsnHOhZJg23KAV3NgpI+tricGwtyL6o2K3y+svAPky X-Received: by 2002:a05:6402:60f:b0:525:7cd4:34da with SMTP id n15-20020a056402060f00b005257cd434damr334329edv.40.1692295021823; Thu, 17 Aug 2023 10:57:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692295021; cv=none; d=google.com; s=arc-20160816; b=LexzIdVR3XIgUzEiVmhTDY8Y0AACcVHEgTU3m4ebBL+Cb3Ju4fsqXX/SgQexHIuZqW eDX7s0lGOMU7LqWfWlxzq+twFYz6N1ZyvhbBgy6U3vgYtO6AN0GsM8p6P/IXlQ4bkhhj kuFmldVPLyr3lGV0Xk4DE39EAJvXkHWRHVQYt183Qiw0LaER98jTYHaeObmL2ykchURP gsqMWu3iaMceYZP3KoEB1ho7YPnyUtRyltACnwqZomYeu0jVt0th3fsWMTMJ2Dm59Dvd Kkm1JxdCxzeQDUMkgeo9JTKcj/U2Jz88+R4TUeY8JMK7/c5B0bEt4oCXeswODM5Femrq eIug== 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 :message-id:date:subject:cc:to:from; bh=ujOeVXhaA43Y2QAasB9Zt8rvOifZ2gvbl911JGAmDVM=; fh=MkjW1f1ixasRiKuzf2PaYxsdrg4RoFahP+0zEUjLGHA=; b=WZAmOfuASjGBkqrEqIhNlIAvrQOISs96R4lrxJAWPjLmIctwA4TrFrA7laZrLUEptl j7v6hgMLJhrqCPRXYIBOCQ6zgeSMpE5bDgdSRwABqPpvP4P7namo1QzMvJiPz+h7Isxg Ap5nqFY4301OrKW5BxNZwPblcxEAENCGoq1eh2HJ5JGdmJggaezs1IXGqWMsU5b4J7bk FZr+IHZJCHh5dVv0YSdjmVdl2rretXrZMe4tZ1T1SdUe0brc29TXyRs2F2+p3qp2sLkt 2kTRYqkujka2pPn3ChOwxdlJwzp66lhtqwr6E7A1cvWhzcULXU2TXHlCqfLE9FcFA6h/ Hgwg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b20-20020a056402139400b005279bf9fb6csi49911edv.138.2023.08.17.10.56.38; Thu, 17 Aug 2023 10:57:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348607AbjHQHuF (ORCPT + 99 others); Thu, 17 Aug 2023 03:50:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348646AbjHQHts (ORCPT ); Thu, 17 Aug 2023 03:49:48 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E25D2D7B; Thu, 17 Aug 2023 00:49:44 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RRHDg5yrXzrSqN; Thu, 17 Aug 2023 15:48:19 +0800 (CST) Received: from huawei.com (10.67.174.28) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Thu, 17 Aug 2023 15:49:41 +0800 From: Liao Chang To: , CC: , Subject: [PATCH v3] cpufreq: cppc: Set fie_disabled to FIE_DISABLED if fails to create kworker_fie Date: Thu, 17 Aug 2023 07:47:56 +0000 Message-ID: <20230817074756.883380-1-liaochang1@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.28] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774499944642824633 X-GMAIL-MSGID: 1774499944642824633 The function cppc_freq_invariance_init() may failed to create kworker_fie, make it more robust by setting fie_disabled to FIE_DISBALED to prevent an invalid pointer dereference in kthread_destroy_worker(), which called from cppc_freq_invariance_exit(). v3: Simplify cleanup code when invariance initialization fails. v2: Set fie_disabled to FIE_DISABLED when invariance initialization fails. Link: https://lore.kernel.org/all/20230816034630.a4hvsj373q6aslk3@vireshk-i7/ Signed-off-by: Liao Chang --- drivers/cpufreq/cppc_cpufreq.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 022e3555407c..4d501f0bf55d 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -249,15 +249,19 @@ static void __init cppc_freq_invariance_init(void) return; kworker_fie = kthread_create_worker(0, "cppc_fie"); - if (IS_ERR(kworker_fie)) + if (IS_ERR(kworker_fie)) { + pr_warn("%s: failed to create kworker_fie: %ld\n", __func__, + PTR_ERR(kworker_fie)); + fie_disabled = FIE_DISABLED; return; + } ret = sched_setattr_nocheck(kworker_fie->task, &attr); if (ret) { pr_warn("%s: failed to set SCHED_DEADLINE: %d\n", __func__, ret); kthread_destroy_worker(kworker_fie); - return; + fie_disabled = FIE_DISABLED; } } @@ -267,7 +271,6 @@ static void cppc_freq_invariance_exit(void) return; kthread_destroy_worker(kworker_fie); - kworker_fie = NULL; } #else