Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2168061rwd; Sun, 28 May 2023 09:25:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ63RjpQOUm9MmCswQD7z2jYWRm5O8xwj7mDTC/Au8u58a0joJA7zi1/98awjwS4Zrr2kK9t X-Received: by 2002:a05:6a20:a11f:b0:10a:b2a2:a301 with SMTP id q31-20020a056a20a11f00b0010ab2a2a301mr6833163pzk.12.1685291101147; Sun, 28 May 2023 09:25:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685291101; cv=none; d=google.com; s=arc-20160816; b=yPqaZnbouTIu5VBSBg+vxAgzoygS6sJ1a+Qal+VrTOfwOV9S8MD8CWIAp0Wk4kW6aF EsAo1dmAtuGhbqRo0SsYVebQ1qrAv6WamX7YTOGc5rr4kP/3AN01gr9LXY9VWukY1ZWB 6Kwj2qqIE5IAQli3QHbQKt4PMhscvGPZ9+RpIBAybRpvHEvo0isqNug58iGXXsLU0zT8 R22oHHKqyXPaHvLzDM4dLuNab7wimc7qzN6hVa27e1uWJMiYxSDd3qKCpH2U+pb1dqik YQSZkRcUuIUIyoB0xHHdmjI0dpbONjjcviR1Gv1RFVebxugVUKNScDhQawoSE5Y2XTTw oaGQ== 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:date:from; bh=gWxo71sWXVXqKhtPAiTVDxvvbnfTiifumjjhG+Tq57Y=; b=K/HW9yIbJXvznwZOW9kX8/i9XV4fK/51CQ1V4n7sWRS6t8ykz7SoiA4THKVsqRHL1Q JwUvYX1aXEfPgwcE/EHpcd8dEwGbPwPUrfhJ8rIP1oHmKefQGs6ME/+6MyXfs3zgGWPx 6VtKHHLd3SmwETNAtL9PrT5eqEi+lT9wy6XUPYGKuUa/IriIy8PpPJP8DF1sYojM7FCh BM+gByHDeGlBGismKuaFjat6r01Z5iERIkmjy16FuFsJq1mUjzA9YYu6hPymcjsY/Sql bvXSa8sCP349o6MWRtWaYnDj2UX2ubMiszTqq/OY7Iz8KWbMp2EXzVTvqmVX7wAI10wf Ev5A== 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m5-20020a633f05000000b0053f3e6ec82bsi6596754pga.774.2023.05.28.09.24.49; Sun, 28 May 2023 09:25: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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229559AbjE1PCi (ORCPT + 99 others); Sun, 28 May 2023 11:02:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbjE1PCe (ORCPT ); Sun, 28 May 2023 11:02:34 -0400 Received: from fgw23-7.mail.saunalahti.fi (fgw23-7.mail.saunalahti.fi [62.142.5.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9324FB2 for ; Sun, 28 May 2023 08:02:29 -0700 (PDT) Received: from localhost (88-113-26-95.elisa-laajakaista.fi [88.113.26.95]) by fgw23.mail.saunalahti.fi (Halon) with ESMTP id a4b9b0ec-fd68-11ed-b972-005056bdfda7; Sun, 28 May 2023 18:02:20 +0300 (EEST) From: andy.shevchenko@gmail.com Date: Sun, 28 May 2023 18:02:19 +0300 To: Wells Lu Cc: linus.walleij@linaro.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, wells.lu@sunplus.com Subject: Re: [PATCH v2] pinctrl:sunplus: Add check for kmalloc Message-ID: References: <1685277277-12209-1-git-send-email-wellslutw@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1685277277-12209-1-git-send-email-wellslutw@gmail.com> X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,SPF_SOFTFAIL, T_SCC_BODY_TEXT_LINE,T_SPF_HELO_TEMPERROR 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 Sun, May 28, 2023 at 08:34:37PM +0800, Wells Lu kirjoitti: > Fix Smatch static checker warning: > potential null dereference 'configs'. (kmalloc returns null) > Changes in v2: > 1. Add free allocated memory before returned -ENOMEM. > 2. Add call of_node_put() before returned -ENOMEM. The placeholder for this is after the cutter '---' line. I think it may be fixed during application by Linus W. Otherwise LGTM, Reviewed-by: Andy Shevchenko > Fixes: aa74c44be19c ("pinctrl: Add driver for Sunplus SP7021") > Signed-off-by: Wells Lu > --- > drivers/pinctrl/sunplus/sppctl.c | 24 ++++++++++++++++++------ > 1 file changed, 18 insertions(+), 6 deletions(-) > > diff --git a/drivers/pinctrl/sunplus/sppctl.c b/drivers/pinctrl/sunplus/sppctl.c > index 6bbbab3..e91ce5b 100644 > --- a/drivers/pinctrl/sunplus/sppctl.c > +++ b/drivers/pinctrl/sunplus/sppctl.c > @@ -834,11 +834,6 @@ static int sppctl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node > int i, size = 0; > > list = of_get_property(np_config, "sunplus,pins", &size); > - > - if (nmG <= 0) > - nmG = 0; > - > - parent = of_get_parent(np_config); > *num_maps = size / sizeof(*list); > > /* > @@ -866,10 +861,14 @@ static int sppctl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node > } > } > > + if (nmG <= 0) > + nmG = 0; > + > *map = kcalloc(*num_maps + nmG, sizeof(**map), GFP_KERNEL); > - if (*map == NULL) > + if (!(*map)) > return -ENOMEM; > > + parent = of_get_parent(np_config); > for (i = 0; i < (*num_maps); i++) { > dt_pin = be32_to_cpu(list[i]); > pin_num = FIELD_GET(GENMASK(31, 24), dt_pin); > @@ -883,6 +882,8 @@ static int sppctl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node > (*map)[i].data.configs.num_configs = 1; > (*map)[i].data.configs.group_or_pin = pin_get_name(pctldev, pin_num); > configs = kmalloc(sizeof(*configs), GFP_KERNEL); > + if (!configs) > + goto sppctl_map_err; > *configs = FIELD_GET(GENMASK(7, 0), dt_pin); > (*map)[i].data.configs.configs = configs; > > @@ -896,6 +897,8 @@ static int sppctl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node > (*map)[i].data.configs.num_configs = 1; > (*map)[i].data.configs.group_or_pin = pin_get_name(pctldev, pin_num); > configs = kmalloc(sizeof(*configs), GFP_KERNEL); > + if (!configs) > + goto sppctl_map_err; > *configs = SPPCTL_IOP_CONFIGS; > (*map)[i].data.configs.configs = configs; > > @@ -965,6 +968,15 @@ static int sppctl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node > of_node_put(parent); > dev_dbg(pctldev->dev, "%d pins mapped\n", *num_maps); > return 0; > + > +sppctl_map_err: > + for (i = 0; i < (*num_maps); i++) > + if (((*map)[i].type == PIN_MAP_TYPE_CONFIGS_PIN) && > + (*map)[i].data.configs.configs) > + kfree((*map)[i].data.configs.configs); > + kfree(*map); > + of_node_put(parent); > + return -ENOMEM; > } > > static const struct pinctrl_ops sppctl_pctl_ops = { > -- > 2.7.4 > -- With Best Regards, Andy Shevchenko