Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5870768pxb; Sun, 7 Nov 2021 22:30:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJw25d4ono0cQfLMjw5TLIKtvs0xSMz2N/t7W9Bc0d3Rw7DJiSRwwrFschPbLqEm6/luJG6a X-Received: by 2002:a05:6e02:148d:: with SMTP id n13mr20805397ilk.100.1636353051435; Sun, 07 Nov 2021 22:30:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636353051; cv=none; d=google.com; s=arc-20160816; b=uHueM1cM1XYXV0V9vEmzpSzDMZgY8TKke7IA5kYKXGja+QAmp1/WFZGirClwdcXu0I /i8+DRIVqkmD0EX1vkmn4N9xjBRbosVf86T+B5NkrdjjZQgP2p2pOGCjl59V/Ay95IAn AMoKfJgP/wG0Vq3CCZqKM9+5hq8bGrtEVy671BDZADlWjyZ/y/3b/Z6kh8v9Tb9ATRrB 5Dpa5rOuRs7GAmedftUHQEmRm19AuMZ1jezbBWXDW7EDQ1E02DLw5FNb0JlwakuX0Gvk loUpp+e5k7A5xto9zyoHGrBohwqvrRbQ9cE27/0TTQgZkMA3aVwqDlW40GyvZapDrV8N mmAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=0xr2aH1oyqMnCG5sZbRwnK/ZucosCRevU1YYGZplaUA=; b=UoIIRhwpzoqeSU2VxjsQeg+OPN80sXaKZ7xtZaOz18J5RQO8qfI2CKWCKUNHEh94Om gAI/qA5udD8vegTIMrMEP1/WW2tQ3Sw7BFPqqoxF9eWYUhjnLgJdeMV04SZf54oIVXZ1 uDcZ+a0X/tAs0enczK9iUChWGQqOZjR1BPUHvqTMdzToRZniBuN8cJxTQJhGX6IZLXy4 FTUlmfIabvrvyk3C5lXuQ4hNcKaXPhSDWXCJzLYmEVlmEBA2rEn1etO28KW9vRNiKUBV O/lUzLxlz+2qm76sHGonuyTwsQZZ0ykm9cmUx8SFwye0No/gX6zvj3KWDJ+wYOYgKBzP 1M8Q== 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 a2si21500708ilj.138.2021.11.07.22.30.36; Sun, 07 Nov 2021 22:30:51 -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 S232818AbhKHAeh (ORCPT + 99 others); Sun, 7 Nov 2021 19:34:37 -0500 Received: from mail-wm1-f53.google.com ([209.85.128.53]:51080 "EHLO mail-wm1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229807AbhKHAeg (ORCPT ); Sun, 7 Nov 2021 19:34:36 -0500 Received: by mail-wm1-f53.google.com with SMTP id 133so11737079wme.0; Sun, 07 Nov 2021 16:31:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=0xr2aH1oyqMnCG5sZbRwnK/ZucosCRevU1YYGZplaUA=; b=ax1kkJQ50jkcnRXjP+i+DY2o/J9aL77QupPV/AOO6IVlvPzG2F4/D0CEsq1pb/6gbQ cDSR2aLjHdB62o+Hv/eWLIhESMNoD5zD4Gu1kS7nOpT9hYguoWknNE2e1Be1j492KX0a AFr2//6JWfa8NG7AUrN4yzLvdn4VvvxrEczgbz6zD8Vjai/v3AabKjbX/h76G6j5eeE7 49s0X1AIng54doYWceSy4iuIor1GoxdKyAwG/WD2AOwj0siqc3UP89YLEXxL1VXU02nM a38Ef14dFCZZJV+PtexREVStdah+X56AhgNOPn4Crrup+dTUAHYbRk/rTqpj1npx7CJk QlUw== X-Gm-Message-State: AOAM533dBtSipW0UYQ7ZXNcrf9o7QjPR4plKtf3tG751w26ivIPMnK1E RMaRyzhVHgZNZ2pbEJy0I+E= X-Received: by 2002:a05:600c:4f02:: with SMTP id l2mr30578157wmq.26.1636331511978; Sun, 07 Nov 2021 16:31:51 -0800 (PST) Received: from rocinante ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j8sm14361672wrh.16.2021.11.07.16.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 16:31:51 -0800 (PST) Date: Mon, 8 Nov 2021 01:31:50 +0100 From: Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= To: Christophe JAILLET Cc: lorenzo.pieralisi@arm.com, robh@kernel.org, bhelgaas@google.com, michal.simek@xilinx.com, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH] PCI: xilinx-nwl: Simplify code and fix a memory leak Message-ID: References: <5483f10a44b06aad55728576d489adfa16c3be91.1636279388.git.christophe.jaillet@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5483f10a44b06aad55728576d489adfa16c3be91.1636279388.git.christophe.jaillet@wanadoo.fr> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Christophe, > 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. Just to confirm - you mean potentially leaking when the driver would be unloaded? Not the error handling path, correct? > --- 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; Thank you! Reviewed-by: Krzysztof WilczyƄski Krzysztof