Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp731323imm; Thu, 13 Sep 2018 06:58:58 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZSEWQq0dL7PCjbH1FWMoydL0+wuzL0krLI3P4K89Kpbr/CnbpzBsAU9Irs/tSER+T5/eks X-Received: by 2002:a63:67c3:: with SMTP id b186-v6mr7268880pgc.5.1536847138157; Thu, 13 Sep 2018 06:58:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847138; cv=none; d=google.com; s=arc-20160816; b=f3uvQKoLT/ZYBr93evQH5ADDFpGttxadlADuGUQao0Dp35Tx5sMAaBm1c6Nus7o11x 6SzHECrfKKHKU3pU3zGCMig9NFvnb9Q+Mt5H++cmjkoE5J2roH/MsD7Dr8iCB7TMRVtn 843H6TqtVWbd0mWDn78rWK4ltswRWdkT3OpkV9Zo3xGU83UchEB2ypoep99JRtDPlCw8 XqCrwCTpSs1DZb7tFupAnsHax5NQWEgnvMCeJGfctCMIV7O06XEgwTfNFdD9C3rqHZfA 4gwdVIZGOU2969Vmw/SHENGS7N+ATGxkvUSYS+7lbRNrf05AdMwi4f0N6H1/cG2pgrVk fREQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=7xwbhYaAsWxsKpbrsfgDXYBJB9LkT6QtQKJOj9jHLIs=; b=pWWtBC4XNJTYQ44XFxCsp9b+NeG2XzAbJr495bbk94pH3dEFGrug0vZu9SPgn3meZu CcbiRf3c1QTuHzjIkqboYEK7WOMPwzOSqkeAaOueIYAJbJ3PQxLnpZYGpp2e45N/ZXmM syEoLYK2TxikVrEebri5fLXMdE8DCn6I+PkpgK3nhBnNKrxeYg4+dhFajZc6Yh9z7r8Z YkqwxXbB1uezNXuBq3eLlX1ALY8reHvD/r1VPNUgfUMHjMEmfqhjqNF465yjGrRqaAYr ATOhCefYb3iGHukC/LE9zJ4gj8S1YIows0USgf4e/uEl3GdOx8cL/tbDMP8MDTV7Okuc XN1w== 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 e22-v6si4051046pfb.185.2018.09.13.06.58.43; Thu, 13 Sep 2018 06:58:58 -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 S1731284AbeIMTG4 (ORCPT + 99 others); Thu, 13 Sep 2018 15:06:56 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34344 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728951AbeIMTG4 (ORCPT ); Thu, 13 Sep 2018 15:06:56 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B6DE5D0E; Thu, 13 Sep 2018 13:57:18 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anton Vasilyev , Chen-Yu Tsai , Linus Walleij , Sasha Levin Subject: [PATCH 4.18 096/197] pinctrl: axp209: Fix NULL pointer dereference after allocation Date: Thu, 13 Sep 2018 15:30:45 +0200 Message-Id: <20180913131845.376032824@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Anton Vasilyev [ Upstream commit 504c76979bccec66e4c2e41f6a006e49e284466f ] 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 Acked-by: Chen-Yu Tsai Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/pinctrl/pinctrl-axp209.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) --- a/drivers/pinctrl/pinctrl-axp209.c +++ b/drivers/pinctrl/pinctrl-axp209.c @@ -316,7 +316,7 @@ static const struct pinctrl_ops axp20x_p .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_mas 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(st 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 plat 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)