Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3487110imu; Sun, 11 Nov 2018 16:12:20 -0800 (PST) X-Google-Smtp-Source: AJdET5dq6fw2sJUPdCagbaCkxHSeNUQVkNrglyN9spCYgnB+O3KZBceXlLqhQse/qZA4/waH9kvD X-Received: by 2002:a17:902:2006:: with SMTP id n6-v6mr18106077pla.131.1541981540169; Sun, 11 Nov 2018 16:12:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981540; cv=none; d=google.com; s=arc-20160816; b=YekwlJEbDrtJc/ZDbSPsscaydkkz+QysBSYuYP4y1polJ4NGFFsU1Dx+J71x4mwnEU boqaSEcNBZdEfqsxZqFJckUlbY9yrePf7CM3osfJoNpcJSxkCQz4/m37MBZ+teZFesfn BAm/BoAZTfb3D7A15B5LMGI+q0NxsNkfyVhwmyQJJSLdCHP119c/xYAZErdrDOKcvgov hmv6X/pAYelb3yM7aBvwlZuHJa7pmvv8R8RLzjLE5kc3QOWuEKV3QPOjx5eUpTmOVjFS Qhuqkl/YQ5k8TJ85MLyIR+kl+GZ7bnSo9qePUhSakOYPqbSf6385WZt6RCkcmnO3RfuM Gjvw== 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:dkim-signature; bh=Hj69iNgedD5odfJJ2yC3gTFs7UagxH135nYmS2TyusI=; b=ucQ8/oguIZWIWZRs0qO0+8euBcuhTg3faI1LsUzqkmQ5PxTSf2hwMD9ZX5nOU9Sb4n /GDnVVQm7n9qoB0Z8mxivwadnOs9wt66g5o2c2NkgUJnmDZ2XG+cgMWi+Y6UjSDxqFZn 9NpAJXKS8gkUDgsxsFwEKYgTFlkP8D37cCP8CV/2Y/KBEW1VE6hjEjVVsr4MGv1Lr76J FL03T8vQ/Yaa5YFuiYuHgPmqj5XQqTuSjOwJ5cA2KbkPlxZepcA3Tzdf6GLAYLkaX/cD IGenKJn0DNvMrBGyac+q6ZbfP7Dshep0uMeJg9fIOU4FQZFCqPB6OHARuASAkevkTMuU UQFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FGftDiM0; 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 12-v6si4736113plb.324.2018.11.11.16.12.05; Sun, 11 Nov 2018 16:12:20 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=FGftDiM0; 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 S1731195AbeKLKCN (ORCPT + 99 others); Mon, 12 Nov 2018 05:02:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:59904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730614AbeKLIRV (ORCPT ); Mon, 12 Nov 2018 03:17:21 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 833AB223C6; Sun, 11 Nov 2018 22:27:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975245; bh=odsMFJBQJxzePXoAD2iaFw/CfQnvp7a1Q0kjSHqh6uI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FGftDiM0xdIA7ZG+NPvpDfVOsxZtMWJpSYuqlDGLBf3WrNYLktY0bTmkKsQaCsksb ccJI7R5KqVEcscKtqf327/2EbMthzFzFB0skF8Uiopm4rwCDMCeecNYxsDN3IxH+IT pLvM3mcpq781RREZw0mtyWBlWsg+nUlM4GdqkqOM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, YueHaibing , Maxime Ripard , Linus Walleij , Sasha Levin Subject: [PATCH 4.19 097/361] pinctrl: sunxi: fix pctrl->functions allocation in sunxi_pinctrl_build_state Date: Sun, 11 Nov 2018 14:17:24 -0800 Message-Id: <20181111221633.326725777@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@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.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: YueHaibing [ Upstream commit a4925311a5443126ecc90671a1604ea7b0f5b32e ] fixes following Smatch static check warning: ./drivers/pinctrl/sunxi/pinctrl-sunxi.c:1112 sunxi_pinctrl_build_state() warn: passing devm_ allocated variable to kfree. 'pctrl->functions' As we will be calling krealloc() on pointer 'pctrl->functions', which means kfree() will be called in there, devm_kzalloc() shouldn't be used with the allocation in the first place. Fix the warning by calling kcalloc() and managing the free procedure in error path on our own. Fixes: 0e37f88d9ad8 ("ARM: sunxi: Add pinctrl driver for Allwinner SoCs") Signed-off-by: YueHaibing Acked-by: Maxime Ripard Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/pinctrl/sunxi/pinctrl-sunxi.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c @@ -1079,10 +1079,9 @@ static int sunxi_pinctrl_build_state(str * We suppose that we won't have any more functions than pins, * we'll reallocate that later anyway */ - pctl->functions = devm_kcalloc(&pdev->dev, - pctl->ngroups, - sizeof(*pctl->functions), - GFP_KERNEL); + pctl->functions = kcalloc(pctl->ngroups, + sizeof(*pctl->functions), + GFP_KERNEL); if (!pctl->functions) return -ENOMEM; @@ -1133,8 +1132,10 @@ static int sunxi_pinctrl_build_state(str func_item = sunxi_pinctrl_find_function_by_name(pctl, func->name); - if (!func_item) + if (!func_item) { + kfree(pctl->functions); return -EINVAL; + } if (!func_item->groups) { func_item->groups = @@ -1142,8 +1143,10 @@ static int sunxi_pinctrl_build_state(str func_item->ngroups, sizeof(*func_item->groups), GFP_KERNEL); - if (!func_item->groups) + if (!func_item->groups) { + kfree(pctl->functions); return -ENOMEM; + } } func_grp = func_item->groups;