From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 158D620E023; Tue, 12 Aug 2025 19:15:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755026125; cv=none; b=k5exblQuewjIb4NOBtIx0ND2SG2CSlW1EyBdvXr/cn6GnXkBxJFDTQk3zuWP6qTyW5j3wMLjYG+4zNMPAIh3eKmHxT9XizwTM7e2cMTOzPpf58KjxlaJFk+dSRwPI8r0sKVsAk9ghbVBB0XlIP14dA9B0+97Fa+Oxq3OJ+TJFgk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755026125; c=relaxed/simple; bh=wlEcHDONZaLHfcWyL7fxEO+yIXsWBl6ep6+Jnfk8vKc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aKVUtc7y6Pko/XdUqotWBRA8tJ0O6qwYC1/o4rghRrZKZELYrfyGOj1jrckQOiL3pxnUdohkiyFEx6bex4rypudM/GuuPNid+q6ellnZmH8SPg2bUC0xRwZ03bdIVV34dzrZvMeSaDdU9zmy2x8E2Y7+QKey8URAeF/95oOlvkU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NnU2drtT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="NnU2drtT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48E6CC4CEF0; Tue, 12 Aug 2025 19:15:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1755026124; bh=wlEcHDONZaLHfcWyL7fxEO+yIXsWBl6ep6+Jnfk8vKc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NnU2drtTQxa/aBadu556MFEKYqBeY55K+dV8LSV9DiQuFxzr5R4nFtSNwl3UEGtMn 0jT+fS17u2NM46ewKenNf/M86NEeL4Xio3k/mEvY01PmXrEdMp9o4z2rUIDU8UpFgi TFRUaExfsyGc5a2tUdhXFFEr+CWbMFzrKR/+DxR8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yuan Chen , Linus Walleij , Sasha Levin Subject: [PATCH 6.15 243/480] pinctrl: sunxi: Fix memory leak on krealloc failure Date: Tue, 12 Aug 2025 19:47:31 +0200 Message-ID: <20250812174407.483568036@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250812174357.281828096@linuxfoundation.org> References: <20250812174357.281828096@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yuan Chen [ Upstream commit e3507c56cbb208d4f160942748c527ef6a528ba1 ] In sunxi_pctrl_dt_node_to_map(), when krealloc() fails to resize the pinctrl_map array, the function returns -ENOMEM directly without freeing the previously allocated *map buffer. This results in a memory leak of the original kmalloc_array allocation. Fixes: e11dee2e98f8 ("pinctrl: sunxi: Deal with configless pins") Signed-off-by: Yuan Chen Link: https://lore.kernel.org/20250620012708.16709-1-chenyuan_fl@163.com Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/pinctrl/sunxi/pinctrl-sunxi.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c index f1c5a991cf7b..ada2ec62916f 100644 --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c @@ -408,6 +408,7 @@ static int sunxi_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev, const char *function, *pin_prop; const char *group; int ret, npins, nmaps, configlen = 0, i = 0; + struct pinctrl_map *new_map; *map = NULL; *num_maps = 0; @@ -482,9 +483,13 @@ static int sunxi_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev, * We know have the number of maps we need, we can resize our * map array */ - *map = krealloc(*map, i * sizeof(struct pinctrl_map), GFP_KERNEL); - if (!*map) - return -ENOMEM; + new_map = krealloc(*map, i * sizeof(struct pinctrl_map), GFP_KERNEL); + if (!new_map) { + ret = -ENOMEM; + goto err_free_map; + } + + *map = new_map; return 0; -- 2.39.5