Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5334172pxb; Sun, 7 Nov 2021 10:00:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXxtUVQiAm+lejnV2tdVqC+9T61AKHlccSmLvt1n1CbqWCO0KaYaLQIX6OMljSN3W69z97 X-Received: by 2002:a17:906:5804:: with SMTP id m4mr89649506ejq.295.1636308043556; Sun, 07 Nov 2021 10:00:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636308043; cv=none; d=google.com; s=arc-20160816; b=HucKf1+HUBG8eeXT9E0LtlavoHfdbrdL2FDH5gXaCyaedKCqeuaSPtbjuUDIQNopuc pO6WvJBiuwluAKrgTkU/MwSRbkyOSA4p/Dasmpggqi4w85vzTs1/yLQmk7GbqbVsDK8o YuJxQbGzsVyspzzKuopk1lOMJ2D8V3uV2JysyYbBKlj7tgj2vHa6Nz8CFHlyHYMfKdTl +zMbFQXoviZfia09QpZ+nypg7++mbaBkxTi+CwQn8FUgYK7ZvHulgnbxSGWJ7fZvA9sQ MyeTBKmWRwfd7hDhPa1Wts0DDg7/KBmWfqhPsm9Urt8nn+RmVCKI9MMopNsMX5VlnCPx cL7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=bCBPPRv0rjZEK4Jxiwfhg5ZLDEd5+zy+P//hLzF+lSw=; b=WCvMzo38RPPCqUf9WdDY5EsGuZko17ycpsqLa+nDdAaH192N2e+B5Y5ijHGEPZ18H5 M0jqQVL189cCKNPFf23UYhIWWNShKrAL9MreDKBcQYyN0E5Ka+8iitvzqKPW4ibAnzxy sshnilkheCSpfvGW9UcG+J8i3QyC7Ygvt5OG4vgc5ia4uMoPBssvOL/pSWt2sM2exiBw NlVPNyNj6ujAjkrBRDx3c95Gz4ZLt8yu5KFLkOiXifvE8IlHiHwHChuK+W8YvNiwSUQb mFo5tO3WoMDfJeuo41gven0jPbYK1HrrL/dXGW2P+fRBU3d26/dOGEqar4WAR5RlrvVd NxQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp7si28109832ejc.755.2021.11.07.10.00.20; Sun, 07 Nov 2021 10:00:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230234AbhKGKHf (ORCPT + 99 others); Sun, 7 Nov 2021 05:07:35 -0500 Received: from smtp06.smtpout.orange.fr ([80.12.242.128]:61808 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230023AbhKGKHe (ORCPT ); Sun, 7 Nov 2021 05:07:34 -0500 Received: from pop-os.home ([86.243.171.122]) by smtp.orange.fr with ESMTPA id jf2ami9tyTdRTjf2bm7YIn; Sun, 07 Nov 2021 11:04:50 +0100 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Sun, 07 Nov 2021 11:04:50 +0100 X-ME-IP: 86.243.171.122 From: Christophe JAILLET To: lorenzo.pieralisi@arm.com, robh@kernel.org, kw@linux.com, bhelgaas@google.com, michal.simek@xilinx.com Cc: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH] PCI: xilinx-nwl: Simplify code and fix a memory leak Date: Sun, 7 Nov 2021 11:04:43 +0100 Message-Id: <5483f10a44b06aad55728576d489adfa16c3be91.1636279388.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allocate space for 'bitmap' in 'struct nwl_msi' at build time instead of dynamically allocating the memory at runtime. This simplifies code (especially error handling paths) and avoid some open-coded arithmetic in allocator arguments This also fixes a potential memory leak. The bitmap was never freed. It is now part of a managed resource. Signed-off-by: Christophe JAILLET --- drivers/pci/controller/pcie-xilinx-nwl.c | 30 ++++++------------------ 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/drivers/pci/controller/pcie-xilinx-nwl.c b/drivers/pci/controller/pcie-xilinx-nwl.c index a72b4f9a2b00..40d070e54ad2 100644 --- a/drivers/pci/controller/pcie-xilinx-nwl.c +++ b/drivers/pci/controller/pcie-xilinx-nwl.c @@ -146,7 +146,7 @@ struct nwl_msi { /* MSI information */ struct irq_domain *msi_domain; - unsigned long *bitmap; + DECLARE_BITMAP(bitmap, INT_PCI_MSI_NR); struct irq_domain *dev_domain; struct mutex lock; /* protect bitmap variable */ int irq_msi0; @@ -335,12 +335,10 @@ static void nwl_pcie_leg_handler(struct irq_desc *desc) static void nwl_pcie_handle_msi_irq(struct nwl_pcie *pcie, u32 status_reg) { - struct nwl_msi *msi; + struct nwl_msi *msi = &pcie->msi; unsigned long status; u32 bit; - msi = &pcie->msi; - while ((status = nwl_bridge_readl(pcie, status_reg)) != 0) { for_each_set_bit(bit, &status, 32) { nwl_bridge_writel(pcie, 1 << bit, status_reg); @@ -560,30 +558,21 @@ static int nwl_pcie_enable_msi(struct nwl_pcie *pcie) struct nwl_msi *msi = &pcie->msi; unsigned long base; int ret; - int size = BITS_TO_LONGS(INT_PCI_MSI_NR) * sizeof(long); mutex_init(&msi->lock); - msi->bitmap = kzalloc(size, GFP_KERNEL); - if (!msi->bitmap) - return -ENOMEM; - /* Get msi_1 IRQ number */ msi->irq_msi1 = platform_get_irq_byname(pdev, "msi1"); - if (msi->irq_msi1 < 0) { - ret = -EINVAL; - goto err; - } + if (msi->irq_msi1 < 0) + return -EINVAL; irq_set_chained_handler_and_data(msi->irq_msi1, nwl_pcie_msi_handler_high, pcie); /* Get msi_0 IRQ number */ msi->irq_msi0 = platform_get_irq_byname(pdev, "msi0"); - if (msi->irq_msi0 < 0) { - ret = -EINVAL; - goto err; - } + if (msi->irq_msi0 < 0) + return -EINVAL; irq_set_chained_handler_and_data(msi->irq_msi0, nwl_pcie_msi_handler_low, pcie); @@ -592,8 +581,7 @@ static int nwl_pcie_enable_msi(struct nwl_pcie *pcie) ret = nwl_bridge_readl(pcie, I_MSII_CAPABILITIES) & MSII_PRESENT; if (!ret) { dev_err(dev, "MSI not present\n"); - ret = -EIO; - goto err; + return -EIO; } /* Enable MSII */ @@ -632,10 +620,6 @@ static int nwl_pcie_enable_msi(struct nwl_pcie *pcie) nwl_bridge_writel(pcie, MSGF_MSI_SR_LO_MASK, MSGF_MSI_MASK_LO); return 0; -err: - kfree(msi->bitmap); - msi->bitmap = NULL; - return ret; } static int nwl_pcie_bridge_init(struct nwl_pcie *pcie) -- 2.30.2