Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3703183imm; Mon, 6 Aug 2018 09:08:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd1JOzT3EHWEWUczriB9VGJ4XvKIAD9WemtntSHw2bWNoUZP2ns+9XJDnhWSjyMVetf6oNZ X-Received: by 2002:a63:1e66:: with SMTP id p38-v6mr14904752pgm.376.1533571722291; Mon, 06 Aug 2018 09:08:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533571722; cv=none; d=google.com; s=arc-20160816; b=buhbjf1fwc1Xek7hhJesx686YyuLLYvp13TDc3VkeQBe+sAsvrrH4/aybEvgN+uHf4 b/RQn/sDCuwkCKmeS5Vy7qoR56TMtfbUkfUkQEO2ouGVq/CVzU4C7Apy4bipYEixL6Jb 8+3xop/z2XjAJkHgUNL99FpNlqpiiSnznvk6liaf11buisq4biNdbErMs7B7bTu68OlO q9ejbYEgzsASsypFD+KmcTEPvGOg9/ja0vO5U8o4tPUYD7+22u68xeVZCtSUM4PmCLZb kcjaRI7QvDQGwE59uz6WFhuZgjT+l7GP+6eTmLYg4SywoRAVn3/a1O9xmENkCa4zK7T5 UXyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=1jgFuqCfYUCBRmyC4bShHwUuSV2M5D/IkQhOl93lX1o=; b=RVpFNBFP8BzcbTTy7lt8nH0kkTbiJe/TxSzf/wqtjYOmScq55QO/AHXS9BYqhWqOPv NpAmCgLj8FoanG5kTfrnc/l0JgIUvhb8RVX0NMEolDQPUCuDODO+8jofYWrXmdseAJa8 npOyS+TN6J1cqD9l/BE6HSYP2JVFTt68f8SbcZOqwxQKsJLYIe9+wDmFgSyLOzXqFtGS 1bdihswKzRv2mWvsF6IINmiFfm4oCZYNapaXNEXxWPJmEX1J6IFfB6f0QS8ytU3JgYzg DYy/VNXhjefsDwtK6oLrDi7+SRBFooVc/vA+nTWDr1D3Aqro3wk5ZnY49swMPPZXpDAY 7HRQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6-v6si9783647plr.210.2018.08.06.09.08.27; Mon, 06 Aug 2018 09:08:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733196AbeHFSQu (ORCPT + 99 others); Mon, 6 Aug 2018 14:16:50 -0400 Received: from bran.ispras.ru ([83.149.199.196]:34609 "EHLO smtp.ispras.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728626AbeHFSQu (ORCPT ); Mon, 6 Aug 2018 14:16:50 -0400 Received: from myklebust.intra.ispras.ru (unknown [10.10.2.207]) by smtp.ispras.ru (Postfix) with ESMTP id 824E6203C7; Mon, 6 Aug 2018 19:07:02 +0300 (MSK) From: Anton Vasilyev To: Linus Walleij Cc: Anton Vasilyev , Chen-Yu Tsai , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] pinctrl: axp209: Fix NULL pointer dereference after allocation Date: Mon, 6 Aug 2018 19:06:35 +0300 Message-Id: <20180806160635.9293-1-vasilyev@ispras.ru> X-Mailer: git-send-email 2.18.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no check that allocation in axp20x_funcs_groups_from_mask is successful. The patch adds corresponding check and return values. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Anton Vasilyev --- drivers/pinctrl/pinctrl-axp209.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/pinctrl/pinctrl-axp209.c b/drivers/pinctrl/pinctrl-axp209.c index a52779f33ad4..afd0b533c40a 100644 --- a/drivers/pinctrl/pinctrl-axp209.c +++ b/drivers/pinctrl/pinctrl-axp209.c @@ -316,7 +316,7 @@ static const struct pinctrl_ops axp20x_pctrl_ops = { .get_group_pins = axp20x_group_pins, }; -static void axp20x_funcs_groups_from_mask(struct device *dev, unsigned int mask, +static int axp20x_funcs_groups_from_mask(struct device *dev, unsigned int mask, unsigned int mask_len, struct axp20x_pinctrl_function *func, const struct pinctrl_pin_desc *pins) @@ -331,18 +331,22 @@ static void axp20x_funcs_groups_from_mask(struct device *dev, unsigned int mask, func->groups = devm_kcalloc(dev, ngroups, sizeof(const char *), GFP_KERNEL); + if (!func->groups) + return -ENOMEM; group = func->groups; for_each_set_bit(bit, &mask_cpy, mask_len) { *group = pins[bit].name; group++; } } + + return 0; } -static void axp20x_build_funcs_groups(struct platform_device *pdev) +static int axp20x_build_funcs_groups(struct platform_device *pdev) { struct axp20x_pctl *pctl = platform_get_drvdata(pdev); - int i, pin, npins = pctl->desc->npins; + int i, ret, pin, npins = pctl->desc->npins; pctl->funcs[AXP20X_FUNC_GPIO_OUT].name = "gpio_out"; pctl->funcs[AXP20X_FUNC_GPIO_OUT].muxval = AXP20X_MUX_GPIO_OUT; @@ -366,13 +370,19 @@ static void axp20x_build_funcs_groups(struct platform_device *pdev) pctl->funcs[i].groups[pin] = pctl->desc->pins[pin].name; } - axp20x_funcs_groups_from_mask(&pdev->dev, pctl->desc->ldo_mask, + ret = axp20x_funcs_groups_from_mask(&pdev->dev, pctl->desc->ldo_mask, npins, &pctl->funcs[AXP20X_FUNC_LDO], pctl->desc->pins); + if (ret) + return ret; - axp20x_funcs_groups_from_mask(&pdev->dev, pctl->desc->adc_mask, + ret = axp20x_funcs_groups_from_mask(&pdev->dev, pctl->desc->adc_mask, npins, &pctl->funcs[AXP20X_FUNC_ADC], pctl->desc->pins); + if (ret) + return ret; + + return 0; } static const struct of_device_id axp20x_pctl_match[] = { @@ -424,7 +434,11 @@ static int axp20x_pctl_probe(struct platform_device *pdev) platform_set_drvdata(pdev, pctl); - axp20x_build_funcs_groups(pdev); + ret = axp20x_build_funcs_groups(pdev); + if (ret) { + dev_err(&pdev->dev, "failed to build groups\n"); + return ret; + } pctrl_desc = devm_kzalloc(&pdev->dev, sizeof(*pctrl_desc), GFP_KERNEL); if (!pctrl_desc) -- 2.18.0