Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6028195ybc; Wed, 27 Nov 2019 13:40:23 -0800 (PST) X-Google-Smtp-Source: APXvYqw8tiKeopwHP9OKJ/j+6VbBUbQFQaWbvMlLV400fw5Y7qimlMTWq06L32hDMTLi8YVr8G1W X-Received: by 2002:a17:906:390a:: with SMTP id f10mr51815485eje.310.1574890823488; Wed, 27 Nov 2019 13:40:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574890823; cv=none; d=google.com; s=arc-20160816; b=sShpiPc3ElsHWKclJ3TxmhvvNNfLD2RAAH8lW/vQ5tk1pPTYunQVVJkh/QNpPqX4Zj sDdHfD2m7ZmGUmMXbAcSO8MR2Rn4N5p0ia0KLzMS9nsVuXphCVbFIhVZF+hGwy9FbUbR vC2XWfbWEuMW45rvlX2J2l8ELwh7imGL1LbAt7Mlw98vowyFFqt/lxGprWdfhAN4YJ4n ZE1uokTnZXikM8wsArU2khhkQig115xtY/LKPtNFGp7yipMc/XitdXWvocs1sUQTqEST bPAsCwEP9/Meg0G34nkuLLseKs5InctzcpJpDju6iGDykPrRkeHyvzlW+PATl9rs1oKe na+A== 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=UfapCC70KNwDTIec87aFAnDdlSfoxi+cgCdz+GgdyS0=; b=IHEaKnsPehL7VYKWMWy9iMaVQ7gkVnTq1Q5P3MPXaO+GwgKl3+hlxUfxZj7x73dExV gHxGv7rt8vMtkHiK4x94MgYKzRk+m8jISsODH5Fxeds8/KxQiJ2PX+6v5bIKKbLVPPuj JgPBlBp2z5WfFSFB4zwsX/lXRY38hpiE/FMzFEYFZm5T9l6Kj4KUvpDKyMIRUgGow1El cc8cw2gboxFpgjIqylRSPdQjaQYbJzCeAQQuZMu5Gm9WAfcpSr8MzXiCkmENJwuVYbir YAGtY8SnFGh5JNBXVnduT+cQPI4BsBC+1UPuGLJgVEI2YNh81FredePkdW0lqfJFCkSW boAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gleg6CWa; 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 o64si91267eda.150.2019.11.27.13.40.00; Wed, 27 Nov 2019 13:40:23 -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=gleg6CWa; 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 S1730005AbfK0Urc (ORCPT + 99 others); Wed, 27 Nov 2019 15:47:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:60316 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730000AbfK0Ur1 (ORCPT ); Wed, 27 Nov 2019 15:47:27 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 C877C217C3; Wed, 27 Nov 2019 20:47:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574887647; bh=Fy1mQC6OBqM/+t1UI6JtqQ78tdA90l/4ZXB8fuX08j8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gleg6CWa3nbDjw9GFuEWpk3VXowYVKpEJVQK0hUBRCqHh/Qpmxn55bFkJWuMwYIMg rz4pHOWS3keKVYiC2W5Ki8Fd0zyjnY/JciOORX8bMbfhO+Oj7uH3LdaKIIqyf6e2me P0QV8HKkhdeyOOBwqwS8jzZM+2WHj1IyRRPRsGKc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe JAILLET , Maxime Ripard , Linus Walleij , Sasha Levin Subject: [PATCH 4.14 039/211] pinctrl: sunxi: Fix a memory leak in sunxi_pinctrl_build_state() Date: Wed, 27 Nov 2019 21:29:32 +0100 Message-Id: <20191127203055.901787185@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203049.431810767@linuxfoundation.org> References: <20191127203049.431810767@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Christophe JAILLET [ Upstream commit a93a676b079144009f55fff2ab0e34c3b7258c8a ] If 'krealloc()' fails, 'pctl->functions' is set to NULL. We should instead use a temp variable in order to be able to free the previously allocated memeory, in case of OOM. Signed-off-by: Christophe JAILLET Acked-by: Maxime Ripard Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/pinctrl/sunxi/pinctrl-sunxi.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c index 52edf3b5988d5..cc8b86a16da0d 100644 --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c @@ -1039,6 +1039,7 @@ static int sunxi_pinctrl_add_function(struct sunxi_pinctrl *pctl, static int sunxi_pinctrl_build_state(struct platform_device *pdev) { struct sunxi_pinctrl *pctl = platform_get_drvdata(pdev); + void *ptr; int i; /* @@ -1105,13 +1106,15 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev) } /* And now allocated and fill the array for real */ - pctl->functions = krealloc(pctl->functions, - pctl->nfunctions * sizeof(*pctl->functions), - GFP_KERNEL); - if (!pctl->functions) { + ptr = krealloc(pctl->functions, + pctl->nfunctions * sizeof(*pctl->functions), + GFP_KERNEL); + if (!ptr) { kfree(pctl->functions); + pctl->functions = NULL; return -ENOMEM; } + pctl->functions = ptr; for (i = 0; i < pctl->desc->npins; i++) { const struct sunxi_desc_pin *pin = pctl->desc->pins + i; -- 2.20.1