From patchwork Sun Mar 9 06:20:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14008106 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) (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 BD92A1474B8; Sun, 9 Mar 2025 06:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.118 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741501275; cv=none; b=RP8FBJZ+U68DYv9In2IiCtQaPAnnZlS+VKSgF9TNcrBKCkmrBmtFnma0AN/AldERnPpMIWRE8HY64lq2CylkX16HrHIsd+XGka4B5HddGauz8mhLYpKhZfOSJ5H4khQZB8oDUG72joKHnDURmQWS9TWL9ED5RPsWTZYKnuSz008= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741501275; c=relaxed/simple; bh=MrawaN7KkrfIVZNNtfBPmXWNMtzSYp/iGsAxXnA5DUY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iOKqSH0fh4Cqu9NPG7X5jCYCysacyu3i8R2R5r3ip7TMXNSYTH+9H3CuTEkKV+z+u0jJB676g7ARgItNlCv7l9GEwW4nY2x1/TLclpiLrhnEgY8HSWEXQl89X7ipnGbyi6IpJVNx8xQH2Qk8TbQy/SoMAXE1RSwnPfodxLGiu4g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=Deq0mzpl; arc=none smtp.client-ip=115.124.30.118 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="Deq0mzpl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1741501261; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=/uSxC7iq4Hn8O4CX5y9Anr7rHxEe4EzcwzY/1QpIVvE=; b=Deq0mzplHfEATZd2qrLaUBrPWUxhkf15z3obpDgpfqtLeJHh9kSs9AXKaPWcn4AS7q4J4Kqx4gEb68AJAlrRmQcKmHKK0+cG8nvHWq93R22eg2fMgEmQVa3FONq8wOevfZrp/+ivwexKVPsyGkdhB6xLY4kt/tMZwyU7BIpbZNk= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WQwVyip_1741501260 cluster:ay36) by smtp.aliyun-inc.com; Sun, 09 Mar 2025 14:21:01 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, Markus.Elfring@web.de, fenghuay@nvidia.com, vkoul@kernel.org Cc: xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/9] dmaengine: idxd: fix memory leak in error handling path of idxd_setup_engines Date: Sun, 9 Mar 2025 14:20:51 +0800 Message-ID: <20250309062058.58910-3-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250309062058.58910-1-xueshuai@linux.alibaba.com> References: <20250309062058.58910-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Memory allocated for engines is not freed if an error occurs during idxd_setup_engines(). To fix it, free the allocated memory in the reverse order of allocation before exiting the function in case of an error. Fixes: 75b911309060 ("dmaengine: idxd: fix engine conf_dev lifetime") Cc: stable@vger.kernel.org Signed-off-by: Shuai Xue Reviewed-by: Dave Jiang Reviewed-by: Fenghua Yu --- drivers/dma/idxd/init.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index 8b775c4a43fc..635838a81e0f 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -275,6 +275,7 @@ static int idxd_setup_engines(struct idxd_device *idxd) rc = dev_set_name(conf_dev, "engine%d.%d", idxd->id, engine->id); if (rc < 0) { put_device(conf_dev); + kfree(engine); goto err; } @@ -288,7 +289,10 @@ static int idxd_setup_engines(struct idxd_device *idxd) engine = idxd->engines[i]; conf_dev = engine_confdev(engine); put_device(conf_dev); + kfree(engine); } + kfree(idxd->engines); + return rc; }