Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp394264rdb; Mon, 22 Jan 2024 07:29:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGsVMfJHdPiLiGgj9sh4aKHidzTc055DYJNcG7A4+BmsyrD8xnXgYKU4Ec+Vyysdi9bmzgw X-Received: by 2002:a05:6a20:938a:b0:19a:ef41:eb0f with SMTP id x10-20020a056a20938a00b0019aef41eb0fmr2002904pzh.79.1705937387454; Mon, 22 Jan 2024 07:29:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705937387; cv=pass; d=google.com; s=arc-20160816; b=nnsjCi14z2DtG9ToWC8K4pg8O0aaiuIunWWtkDNFT87oI+FOPyk9Wy+4dstXjcSFB/ Q8XKR4X2x7OOyTR/CPbGyBd2yhXyTTxKhpTf1+ZultXkW1FUGdqF5Yc/LDqZas4j/0HU Ab4u66M7r0m5wY9sQKi38BsTMte21aOrfG/xXtnpu2zCLyYamnsG9egOHNyTNlYrB2B7 TtlGS2EBrgjvj5GwN9XeW3rgxqMDMCCEycv8K8GbyJi7Y4AN9XSLkMLbNAbLli3AUczO eVG+X92xa/GFZ6AOtM5djoDfIzuc0XOYT1qsK4HP2kCMIFtmGAnhJkeoKwA/OiAqmpgD h7tQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=CML1MUR3spjxh8DsiViz6Yo71uY5ENhY/FlU1v2JPGo=; fh=CejwAlf2gGCJoJTiEHlj/iU8+KK33TMjLOH3IzzCzCA=; b=xcSz9PEYXoLPjb84FCTSvfDjSAAmAt+zLoF1OQOcRV8gHWyMisMUoMtcGJXMJBl5dn ZvBgwxLwdme7S55tqkBy9Dpd3IE5RFv0WTBB+o+jxeXf9s0xJizlpDtF7jJLCEdl643x Nh+pzUu2wd9chd5qBYPATfXYFT/fmpT7gwxbkEKy0ZQ+EsSbJshPQ7PzGyRFpKq6NrFA P1xpUgOlgLg8rGKHgf3OLcJn343rxJryZqk53oWY9mE0w6J5tDq7xkauCWb4xlWJKDfh HSNlZId8ndSSatRwWGHDMwuYEtjywvSo0E8kb7nAeTW1gw7JyVLHkyP9gPa9pJ0UfBUG tvsw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IZBrIRWX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-33281-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33281-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a41-20020a056a001d2900b006dbd7f1a189si3137247pfx.334.2024.01.22.07.29.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 07:29:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33281-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IZBrIRWX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-33281-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33281-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C2FA42896BB for ; Mon, 22 Jan 2024 15:22:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1FAE85B5AA; Mon, 22 Jan 2024 14:59:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IZBrIRWX" 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 47CB05B5A9; Mon, 22 Jan 2024 14:59:55 +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=1705935596; cv=none; b=B8IcQcIeEbG/l3V+USm6qq0cr1QtuBLwizmSxXTyBEaIRqIS/RO681RCZOxo0upyxtiZsRaQHIvlsyBeKb5Ng/rvsVv4tSAAvGIBxe7ioDBxZS+erB01jkqhVZFuJ7EI+OxCgfRDIZ1zhkbsgLANEbnLzcFZuCC29BNn8kbnvrY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705935596; c=relaxed/simple; bh=fOsTqgZAd0vrP6tVW5esPMiUQEc5a6uhT+FU1ciBxb4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VN3BBoIPGR7JBhjZT1iNNG/YtmOxmW72qkuTYa831BHtHuGTtgPmc+7FWwouy9PsHaPNBt7vYpnLjkiMPkWSPpc4E3Xu482yGYuNqy8FhQ+Vjj4dmw5MuHQFcmBHziMfciRlko5MNK8cIn/reX+o/FReOI8ramHREWuVQWbSvUQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IZBrIRWX; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C4CFC43394; Mon, 22 Jan 2024 14:59:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705935595; bh=fOsTqgZAd0vrP6tVW5esPMiUQEc5a6uhT+FU1ciBxb4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IZBrIRWXC1j1zUoEO9MDjQslkO5/IQI0bObH2KZ5dHUjh6WvG1oCdLEN5hoy3hUdn BCbneDUxTYA2AFO1DoI0mi21ZUL5YPXQBi/tyvgB9JTSzSoPvxkhPTNpXTjJNe0UkO y4sGGV7FSsXbA3kMDag78kQs6u3o5O95gw/ZbTmKl4zERHfulzzkUQpKDQzXSVgIaa 40X6EnYZWw5X3wJQiKyqOwCJugpvm27hGaIpsLX57XXcV/hf9lYGSMzUvFpVKbrbVG 9v54PD+6rvvsYtERRo1DsFt3Y9qdMhsU90WDmbTmhGUuqhdoBq7yBNkF6BIUsXHsRY 56kZDiwZhrx5Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kuan-Wei Chiu , Stephen Boyd , Sasha Levin , mturquette@baylibre.com, angelogioacchino.delregno@collabora.com, krzysztof.kozlowski@linaro.org, luca.ceresoli@bootlin.com, robh@kernel.org, linux-clk@vger.kernel.org Subject: [PATCH AUTOSEL 6.7 59/88] clk: hi3620: Fix memory leak in hi3620_mmc_clk_init() Date: Mon, 22 Jan 2024 09:51:32 -0500 Message-ID: <20240122145608.990137-59-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122145608.990137-1-sashal@kernel.org> References: <20240122145608.990137-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.7.1 Content-Transfer-Encoding: 8bit From: Kuan-Wei Chiu [ Upstream commit bfbea9e5667cfa9552c3d88f023386f017f6c308 ] In cases where kcalloc() fails for the 'clk_data->clks' allocation, the code path does not handle the failure gracefully, potentially leading to a memory leak. This fix ensures proper cleanup by freeing the allocated memory for 'clk_data' before returning. Signed-off-by: Kuan-Wei Chiu Link: https://lore.kernel.org/r/20231210165040.3407545-1-visitorckw@gmail.com Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- drivers/clk/hisilicon/clk-hi3620.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/clk/hisilicon/clk-hi3620.c b/drivers/clk/hisilicon/clk-hi3620.c index 2d7186905abd..5d0226530fdb 100644 --- a/drivers/clk/hisilicon/clk-hi3620.c +++ b/drivers/clk/hisilicon/clk-hi3620.c @@ -466,8 +466,10 @@ static void __init hi3620_mmc_clk_init(struct device_node *node) return; clk_data->clks = kcalloc(num, sizeof(*clk_data->clks), GFP_KERNEL); - if (!clk_data->clks) + if (!clk_data->clks) { + kfree(clk_data); return; + } for (i = 0; i < num; i++) { struct hisi_mmc_clock *mmc_clk = &hi3620_mmc_clks[i]; -- 2.43.0