From patchwork Sun Mar 9 06:20:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14008107 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) (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 11D7A176ADE; Sun, 9 Mar 2025 06:21:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.119 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741501276; cv=none; b=CDL/EdHXgjzbrBKFFzvoruq90oiwMbcPjlZ3/c0O1jlTutsuLYZ/LvwZAFwGDQSI9odFB1lRprybM3Gp2Lu2fw3B9SuMO9Db+dN3+CmR+I8xlY34HzYkIT4Jj7qLV/U0k0c/E7AybjT+vETRD3JQg6b4Lm6O2umzpbmu6OeSFqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741501276; c=relaxed/simple; bh=gY2Smb49h55S+qKpFP4S5W3YeAKaTE14aPjQPneKzbc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aEmQkC1gx1qNyfVaLFpMAMaLubV3xWTUgec9L9XBDxnouPcePqxRPrqI5Zo9Y04r9GRDntcIiU1C7tYz38n8FYTQ7tA1/6kksl4fI2tob2RSxp+CTgX0fOqBLSPwnQaTsky89c8VB8j4GInWG58widCgeg7W6G6j7BW2bATm0v0= 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=Y9IT+jA3; arc=none smtp.client-ip=115.124.30.119 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="Y9IT+jA3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1741501265; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=903xs1u93RQs3NTNioOicHzaxetM1ecxaDIAmMV5tpA=; b=Y9IT+jA3qMEwHUHnUEmlj7xm6zcp1NFG9a+zOZpqBYcWCl9QP78eM/G2z+DkFBiX64wtg0DM0xS2JZISovTwbc5VXvtkcr68ZlygsjgpLWr07rW4rraGVeuYsGMeC9h71y0E/8M0J3csWDZ3k/IdgLOLHpLlneL6KEHLxuMMiMo= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WQwVykV_1741501264 cluster:ay36) by smtp.aliyun-inc.com; Sun, 09 Mar 2025 14:21:04 +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 7/9] dmaengine: idxd: fix memory leak in error handling path of idxd_pci_probe Date: Sun, 9 Mar 2025 14:20:56 +0800 Message-ID: <20250309062058.58910-8-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 idxd is not freed if an error occurs during idxd_pci_probe(). To fix it, free the allocated memory in the reverse order of allocation before exiting the function in case of an error. Fixes: bfe1d56091c1 ("dmaengine: idxd: Init and probe for Intel data accelerators") Cc: stable@vger.kernel.org Signed-off-by: Shuai Xue Reviewed-by: Dave Jiang --- drivers/dma/idxd/init.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index 71d92c05c0c6..890b2bbd2c5e 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -588,6 +588,17 @@ static void idxd_read_caps(struct idxd_device *idxd) idxd->hw.iaa_cap.bits = ioread64(idxd->reg_base + IDXD_IAACAP_OFFSET); } +static void idxd_free(struct idxd_device *idxd) +{ + if (!idxd) + return; + + put_device(idxd_confdev(idxd)); + bitmap_free(idxd->opcap_bmap); + ida_free(&idxd_ida, idxd->id); + kfree(idxd); +} + static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_data *data) { struct device *dev = &pdev->dev; @@ -1257,7 +1268,7 @@ int idxd_pci_probe_alloc(struct idxd_device *idxd, struct pci_dev *pdev, err: pci_iounmap(pdev, idxd->reg_base); err_iomap: - put_device(idxd_confdev(idxd)); + idxd_free(idxd); err_idxd_alloc: pci_disable_device(pdev); return rc;