Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1751114rwb; Sat, 19 Nov 2022 02:55:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ri9MvKsb0/lAxBy6SvYnronVdbxvVP65IdJKoqCrTi5rpDkqWAY80kkBg+QxYzO+34/OY X-Received: by 2002:a62:1d13:0:b0:56b:a672:6299 with SMTP id d19-20020a621d13000000b0056ba6726299mr11917183pfd.10.1668855337615; Sat, 19 Nov 2022 02:55:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668855337; cv=none; d=google.com; s=arc-20160816; b=tP+hx9blU0845k4l4425fzVmkPG1BRiULWlthu54TZ8fTRrWVOXDZtXmnkTqFHr8Pd 7wNWVFHhu9KE7pwIZgkEORWA4X6TgEvbuxR7+/ZS7Pj2eAN5z5sRVtIP6YNM39uG23KM S/1EomW+qJ608cc8F8zZWbcnpo+nlmrPE5be3QNhNcUIJQy0PQdh47xTOqVnMFjQWpTL XUiOZzBZuNmUJWX+huoVsWGvo2GIBzzoxtYxPDqd6i4v7dKEpVW6ST3OMeeGgGjGDXxj /nhofGZ2RVvlX6zS9bBUPokM4ncofaQNRXJGw5n11rIs5AuBUmyp/yxBqszRiRM0EmqZ 49cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ztZgeYBbiORvZ6Ix7uJT7Zw+L+zsr0tPLWv3IyLmgZY=; b=NlIuFlY6U+RKzi38/NPZRBNel5zLdlJFcBybxu0sjA8EDblIY7t4rtf9o43ceHLsJU sp7H5En+IWBUMLjqWjcPNb13U/MV3NwjTbHFy+zuupM6nFPhPH5Msp5bTNO1tXtnfCmE jVTPDfkh6CrES//kTF8FgFGyWUb1DPItdNS6vxhsRslS67qQnUfynL++g+2WK+RI1IMy rPnyDpgO2T0UFTwZ0cCkCEUGSQZxt8QEa7Btj9HPp120ULEp4op+5cbOhUNrzmRHy6nr 2ivDx6zKqBmihnNVyOAJ9WUe8QITX0naP30vSy+k7FwVsq3VHOe4ZqhbNkRgPB5QHCtk W3yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="CG/RU7Ua"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b20-20020a056a000a9400b0053e0d9dfee5si6659301pfl.217.2022.11.19.02.55.23; Sat, 19 Nov 2022 02:55:37 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="CG/RU7Ua"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230244AbiKSKnP (ORCPT + 91 others); Sat, 19 Nov 2022 05:43:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbiKSKnN (ORCPT ); Sat, 19 Nov 2022 05:43:13 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5081484824; Sat, 19 Nov 2022 02:43:12 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D73C560959; Sat, 19 Nov 2022 10:43:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E3B3C433C1; Sat, 19 Nov 2022 10:43:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668854591; bh=/+iRDvo5pjoK/3d+uFgmlFaUxqq5N45gM/Zxq/W3Tx4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CG/RU7Ua81xKFWKG+czQ5Up/u88hGSTpEFf58HsFm8vLhhdQoX5CH1Oa72ZPfo7zI HqxL5pMi8jh/j2iu0aJftZ92NsL3tyCeYLUpRSaj5EEOOPC53JaRaxVK+lxNtvCJ5y ruZpj20hvwbi5OxiBR7S2At6nPJqnyZ0hUu5XcmCU5SbYAwlgN+1sMsWAAwuHA+4FX 7ZMS/E0xsoOmkYGurwLtppLUNR3qb+YYa0pllt0r0mDz4YDRx4yE7QenBdGOEJq+Pc 8/fWrS9DoMoZnjLYCrOEXIf9S2ftIaFluWjGQye+fXGKhVC/CamnocqI+n7ckXXrXt 5bb91z8TzpwCQ== Date: Sat, 19 Nov 2022 10:43:06 +0000 From: Conor Dooley To: Hui Tang Cc: mturquette@baylibre.com, sboyd@kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, yusongping@huawei.com, claudiu.beznea@microchip.com, conor.dooley@microchip.com Subject: Re: [PATCH] clk: microchip: check for null return of devm_kzalloc() Message-ID: References: <20221119054858.178629-1-tanghui20@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221119054858.178629-1-tanghui20@huawei.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 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 @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 > --- > 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 >