From patchwork Fri Apr 4 12:02:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14038365 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (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 526EE1DE2A1; Fri, 4 Apr 2025 12:02:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768149; cv=none; b=BN6C9rjNIT8tOv7mGR5mtVN6YKqas84WSEFFurh3bOw8iFReFMfaqBbNAzRPFDndWHW9DM9y32ihgR2l60K1+u3tlfUlRNdF+TpPH5gC4+zGZiT3oE1pHU+l0qMbhsv//MzE9pU/szzTfgpJFanc2pCIxwrLEBRhiFn/++DEsl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743768149; c=relaxed/simple; bh=SHZwFqeIre1l+vXt4R2dOG0+l9d01xd1QFM7+k8cqRs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=anTe2T1aevN6UlY7m/D8BvG4P58w/R7AAmysJBrbUGMHn8azfTZVxxcCbezhuPXn8X4cbgPCuEJkhSuEmKeuGvkGzOqnhy/BFBko2L35n3iqJXk3t0F0pk0DvfbctcQ5HrTe11ub8AC2wLz7cSYBSho3vfsn0+846jTnRS1TW0A= 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=a1sPR0BN; arc=none smtp.client-ip=115.124.30.131 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="a1sPR0BN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1743768143; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=/cQyfBM4ou0asWHVRISENFgpbvJOOzovwlkHeg81JOI=; b=a1sPR0BNo1UmKQIXDFGGp9N0epItIAZFIBMROcLz2j1FauzIdUtZujLmholW4Wmavm5fOWWMYALDS+r0/RuHQVYYvCK4NXsc2x26YjW6+TDPIaWKHi82cDecp6hlPvcs1oRQQnTyCWZyVWCwAtJZroNwD9MC4YjnHS/pVdG1SG8= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WUyld5x_1743768142 cluster:ay36) by smtp.aliyun-inc.com; Fri, 04 Apr 2025 20:02:23 +0800 From: Shuai Xue To: vinicius.gomes@intel.com, dave.jiang@intel.com, fenghuay@nvidia.com, vkoul@kernel.org Cc: xueshuai@linux.alibaba.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 7/9] dmaengine: idxd: fix memory leak in error handling path of idxd_pci_probe Date: Fri, 4 Apr 2025 20:02:15 +0800 Message-ID: <20250404120217.48772-8-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250404120217.48772-1-xueshuai@linux.alibaba.com> References: <20250404120217.48772-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 Reviewed-by: Fenghua Yu --- 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 302d8983ed8c..f2b5b17538c0 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -587,6 +587,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; @@ -1255,7 +1266,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;