Message ID | 20221119054858.178629-1-tanghui20@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp572832wrr; Fri, 18 Nov 2022 21:59:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf7KHEU70p37gWPchssiQwbUaQRT34gDrWKlboV+5cVaJWNeY7Ccn2blx/MRxOt4s6GGa1hc X-Received: by 2002:a17:906:fa19:b0:78d:9002:fe3b with SMTP id lo25-20020a170906fa1900b0078d9002fe3bmr4924865ejb.769.1668837550595; Fri, 18 Nov 2022 21:59:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668837550; cv=none; d=google.com; s=arc-20160816; b=ZoP+aclRoALiTDpvK5FZxGki8ns7crkaLDfaynrBQ0FbWYIFHGGj3S/jwQna+sJxGz fkW8S4tjpe9yeLS+B5XZThdfpCa1LAW4pMz0iO0dyicJIf4ZDsLCa7s/ywou/SwLz0uo lHkEjQCUYzx48M4BLVpCWqdOyGhWMReBdGiN4lzmg6zpYkOuV5/VzX+QaH+eVtykOLNU qBxKg5B2SLOA4v57r3eAq6f5nTOGqM42NkHFBjUx7tWRQ8DzCAeuI2eA/u9JCuY1upfJ OkxxH+xP7cNGiv1Yw73NYpCCg1BDtRd9XCd1VC3qPhknEJY9Z9ekbNYeLFLz7eqXwA87 neig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=xr6viXH4Xz9wb/Pn8TXUGV2JL21jXHuhpc3wHTIfOPo=; b=emo+LO0OGDdp6KhHqagbR89M5A0JJg56CE1EuNlKNC/AbP1QgyXbRCq6zeiiuJcSGg z/MWj4IZNLmsa/h6oNt+9NeRbzcMssniYHhPg/hbLS1UamNdIfIqet0QrWLUGkA0iJJM hsyqkdAv2z2/9JokcFIB4rEtzr+ApBsvmWmOX+fWljErWoBsDVvZ02Yyq4GDtrb+BG+v LRnuJG1681joy1kUpmImStKRJ4whl796eADpN0UmSkQZIBYngmXj/smiIjeZwhHAZy0d UGmsRW+mbxH0+EZiin3DSSdubdSj22SIyzTMR2YWSdNRP0vvRQ1/tfS2uhu2Oreo8Z1l ZPJw== 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 gn42-20020a1709070d2a00b007ada3808562si4910180ejc.737.2022.11.18.21.58.44; Fri, 18 Nov 2022 21:59:10 -0800 (PST) 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 S231954AbiKSFwO (ORCPT <rfc822;kkmonlee@gmail.com> + 99 others); Sat, 19 Nov 2022 00:52:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229878AbiKSFwL (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 19 Nov 2022 00:52:11 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CD348FE4E; Fri, 18 Nov 2022 21:52:10 -0800 (PST) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NDjPF3JfKzqSVS; Sat, 19 Nov 2022 13:48:17 +0800 (CST) Received: from kwepemm600005.china.huawei.com (7.193.23.191) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 19 Nov 2022 13:52:08 +0800 Received: from ubuntu1804.huawei.com (10.67.175.30) by kwepemm600005.china.huawei.com (7.193.23.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 19 Nov 2022 13:52:07 +0800 From: Hui Tang <tanghui20@huawei.com> To: <mturquette@baylibre.com>, <sboyd@kernel.org> CC: <linux-clk@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <yusongping@huawei.com>, <claudiu.beznea@microchip.com>, <conor.dooley@microchip.com> Subject: [PATCH] clk: microchip: check for null return of devm_kzalloc() Date: Sat, 19 Nov 2022 13:48:58 +0800 Message-ID: <20221119054858.178629-1-tanghui20@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.175.30] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600005.china.huawei.com (7.193.23.191) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749903003302377675?= X-GMAIL-MSGID: =?utf-8?q?1749903003302377675?= |
Series |
clk: microchip: check for null return of devm_kzalloc()
|
|
Commit Message
Hui Tang
Nov. 19, 2022, 5:48 a.m. UTC
Because of the possilble failure of devm_kzalloc(), name might be NULL and
will cause null pointer derefrence later.
Therefore, it might be better to check it and directly return -ENOMEM.
Fixes: d39fb172760e ("clk: microchip: add PolarFire SoC fabric clock support")
Signed-off-by: Hui Tang <tanghui20@huawei.com>
---
drivers/clk/microchip/clk-mpfs-ccc.c | 6 ++++++
1 file changed, 6 insertions(+)
Comments
On Sat, Nov 19, 2022 at 01:48:58PM +0800, Hui Tang wrote: > Because of the possilble failure of devm_kzalloc(), name might be NULL and > will cause null pointer derefrence later. In theory, yeah? (note to self, s/refrence/reference/, s/possilble/possible) > Therefore, it might be better to check it and directly return -ENOMEM. I agree with your use of might here. If the allocations do fail, we likely aren't getting the system off the ground anyway - but there is no harm in checking. Reviewed-by: Conor Dooley <conor.dooley@microchip.com> @Claudiu, supposedly I can push to the at91 repo now so I will try to do that. Thanks, Conor. > > Fixes: d39fb172760e ("clk: microchip: add PolarFire SoC fabric clock support") > Signed-off-by: Hui Tang <tanghui20@huawei.com> > --- > drivers/clk/microchip/clk-mpfs-ccc.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/drivers/clk/microchip/clk-mpfs-ccc.c b/drivers/clk/microchip/clk-mpfs-ccc.c > index 7be028dced63..32aae880a14f 100644 > --- a/drivers/clk/microchip/clk-mpfs-ccc.c > +++ b/drivers/clk/microchip/clk-mpfs-ccc.c > @@ -166,6 +166,9 @@ static int mpfs_ccc_register_outputs(struct device *dev, struct mpfs_ccc_out_hw_ > struct mpfs_ccc_out_hw_clock *out_hw = &out_hws[i]; > char *name = devm_kzalloc(dev, 23, GFP_KERNEL); > > + if (!name) > + return -ENOMEM; > + > snprintf(name, 23, "%s_out%u", parent->name, i); > out_hw->divider.hw.init = CLK_HW_INIT_HW(name, &parent->hw, &clk_divider_ops, 0); > out_hw->divider.reg = data->pll_base[i / MPFS_CCC_OUTPUTS_PER_PLL] + > @@ -200,6 +203,9 @@ static int mpfs_ccc_register_plls(struct device *dev, struct mpfs_ccc_pll_hw_clo > struct mpfs_ccc_pll_hw_clock *pll_hw = &pll_hws[i]; > char *name = devm_kzalloc(dev, 18, GFP_KERNEL); > > + if (!name) > + return -ENOMEM; > + > pll_hw->base = data->pll_base[i]; > snprintf(name, 18, "ccc%s_pll%u", strchrnul(dev->of_node->full_name, '@'), i); > pll_hw->name = (const char *)name; > -- > 2.17.1 >
On 2022/11/19 18:43, Conor Dooley wrote: > On Sat, Nov 19, 2022 at 01:48:58PM +0800, Hui Tang wrote: >> Because of the possilble failure of devm_kzalloc(), name might be NULL and >> will cause null pointer derefrence later. > > In theory, yeah? > > (note to self, s/refrence/reference/, s/possilble/possible) Sorry, I make spelling mistakes. Thanks.
On 19.11.2022 12:43, Conor Dooley wrote: > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe > > On Sat, Nov 19, 2022 at 01:48:58PM +0800, Hui Tang wrote: >> Because of the possilble failure of devm_kzalloc(), name might be NULL and >> will cause null pointer derefrence later. > > In theory, yeah? > > (note to self, s/refrence/reference/, s/possilble/possible) Applied to clk-microchip-fixes with these adjustments, thanks! > >> Therefore, it might be better to check it and directly return -ENOMEM. > > I agree with your use of might here. If the allocations do fail, we > likely aren't getting the system off the ground anyway - but there is > no harm in checking. > > Reviewed-by: Conor Dooley <conor.dooley@microchip.com> > > @Claudiu, supposedly I can push to the at91 repo now so I will try to do > that. > > Thanks, > Conor. > >> >> Fixes: d39fb172760e ("clk: microchip: add PolarFire SoC fabric clock support") >> Signed-off-by: Hui Tang <tanghui20@huawei.com> >> --- >> drivers/clk/microchip/clk-mpfs-ccc.c | 6 ++++++ >> 1 file changed, 6 insertions(+) >> >> diff --git a/drivers/clk/microchip/clk-mpfs-ccc.c b/drivers/clk/microchip/clk-mpfs-ccc.c >> index 7be028dced63..32aae880a14f 100644 >> --- a/drivers/clk/microchip/clk-mpfs-ccc.c >> +++ b/drivers/clk/microchip/clk-mpfs-ccc.c >> @@ -166,6 +166,9 @@ static int mpfs_ccc_register_outputs(struct device *dev, struct mpfs_ccc_out_hw_ >> struct mpfs_ccc_out_hw_clock *out_hw = &out_hws[i]; >> char *name = devm_kzalloc(dev, 23, GFP_KERNEL); >> >> + if (!name) >> + return -ENOMEM; >> + >> snprintf(name, 23, "%s_out%u", parent->name, i); >> out_hw->divider.hw.init = CLK_HW_INIT_HW(name, &parent->hw, &clk_divider_ops, 0); >> out_hw->divider.reg = data->pll_base[i / MPFS_CCC_OUTPUTS_PER_PLL] + >> @@ -200,6 +203,9 @@ static int mpfs_ccc_register_plls(struct device *dev, struct mpfs_ccc_pll_hw_clo >> struct mpfs_ccc_pll_hw_clock *pll_hw = &pll_hws[i]; >> char *name = devm_kzalloc(dev, 18, GFP_KERNEL); >> >> + if (!name) >> + return -ENOMEM; >> + >> pll_hw->base = data->pll_base[i]; >> snprintf(name, 18, "ccc%s_pll%u", strchrnul(dev->of_node->full_name, '@'), i); >> pll_hw->name = (const char *)name; >> -- >> 2.17.1 >>
diff --git a/drivers/clk/microchip/clk-mpfs-ccc.c b/drivers/clk/microchip/clk-mpfs-ccc.c index 7be028dced63..32aae880a14f 100644 --- a/drivers/clk/microchip/clk-mpfs-ccc.c +++ b/drivers/clk/microchip/clk-mpfs-ccc.c @@ -166,6 +166,9 @@ static int mpfs_ccc_register_outputs(struct device *dev, struct mpfs_ccc_out_hw_ struct mpfs_ccc_out_hw_clock *out_hw = &out_hws[i]; char *name = devm_kzalloc(dev, 23, GFP_KERNEL); + if (!name) + return -ENOMEM; + snprintf(name, 23, "%s_out%u", parent->name, i); out_hw->divider.hw.init = CLK_HW_INIT_HW(name, &parent->hw, &clk_divider_ops, 0); out_hw->divider.reg = data->pll_base[i / MPFS_CCC_OUTPUTS_PER_PLL] + @@ -200,6 +203,9 @@ static int mpfs_ccc_register_plls(struct device *dev, struct mpfs_ccc_pll_hw_clo struct mpfs_ccc_pll_hw_clock *pll_hw = &pll_hws[i]; char *name = devm_kzalloc(dev, 18, GFP_KERNEL); + if (!name) + return -ENOMEM; + pll_hw->base = data->pll_base[i]; snprintf(name, 18, "ccc%s_pll%u", strchrnul(dev->of_node->full_name, '@'), i); pll_hw->name = (const char *)name;