Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6022587ybc; Wed, 27 Nov 2019 13:33:53 -0800 (PST) X-Google-Smtp-Source: APXvYqybVVjQ+Qpq1Hu6N4o9jBHWu2bqsXqgJ93BRAq8xXJlodyiLBFVQu7Rf/L0w3tFafKAkIMv X-Received: by 2002:aa7:c1d4:: with SMTP id d20mr34422332edp.273.1574890433628; Wed, 27 Nov 2019 13:33:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574890433; cv=none; d=google.com; s=arc-20160816; b=ubLgL4dykEdzpH4+xegYGIxBq3leF6sJio99NN2hxQ+z/GOgR0jXrNmo2yauN0ZfSx KKfl5vojpyWsm+d4Nm6bNnR8iolld4GPhMXV3L1qFmFTvYmjRYymb0sK5v9VCu0uTmzw sqgQ2OAtYA2nnoxcU7hGwF81GR/UzoFYpAyVRxIMOU/z0rGlCvAdUi1gMUCw0oYuyyUC +0X3eM4IbTdaheUz1Jz2DEJ/o/LahrWH/5LBGIN8oGzUSw1ir3Z0F+OxAysN90+voapw tdd1yjZ8ZbLmP5u37HdWF76CJgAApxCy0XPMnfK9AUuWAHekFjwmnqcggw749ojA0wCv WBDQ== 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=q70FsTHhgPW8/R8jEhvkAeZ+8H6ho/35Yd8U9ikWsWc=; b=zTXe/IkJOLBDMRDalI+G1J1xH6F+bi5Qm6UvnuZ6gJLiY7tNZRO4F52G8wiqaUp0us TGyGLc4Dp8pj7CupQ7nCbgYwToYK+1icNgn6a+KTY0iKYNyqrBL7hIYwIOBNPRKsi4NJ /WsMwQVzsqeuFgTl7bkeOwXNHYo5p+KASAE1l6uduzY/hbHIguhU+SmBF29NRQ2p9eFQ Hle0ZJV3x+0GWrveiLsz0wUXGdvgORGQZFIQYEaT3MPAAoy8d43r1IC/vm+n4qj1QpQW W3VctS6Nr5nA497swHNq22h8R9PORgfHMy72hu8zUKsZnlMGwuvOzSotMcUTJrnVaOI7 k3ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CDEs2lkV; 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 e4si537481ejr.210.2019.11.27.13.33.29; Wed, 27 Nov 2019 13:33:53 -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=CDEs2lkV; 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 S1731196AbfK0U51 (ORCPT + 99 others); Wed, 27 Nov 2019 15:57:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:48408 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731180AbfK0U5X (ORCPT ); Wed, 27 Nov 2019 15:57:23 -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 824C92084D; Wed, 27 Nov 2019 20:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888243; bh=AFXHZLOietu/5Qoi+Zd8KLI2EG/uE9+32R3/Z1FPs5M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CDEs2lkV9vkj5c89ZybgG8xseDMuBvCNTMLZLGC2EsrijOoa2ZuNVveAHMfS6M7zV NcyxGRPkVDrqn1EIxodFG4Lsti92xpONzjsKHqDJUoTKFimq7x/+MNdEiRrOv6MZkS 4XDvjqekYWJVpZITWD2JZRGxrIof1Myp2nuhhiyg= 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.19 060/306] pinctrl: sunxi: Fix a memory leak in sunxi_pinctrl_build_state() Date: Wed, 27 Nov 2019 21:28:30 +0100 Message-Id: <20191127203119.143994143@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@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 26ebedc1f6d31..61aaaf58c5993 100644 --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c @@ -1042,6 +1042,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; /* @@ -1108,13 +1109,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