From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 4894F3C9EFB for ; Wed, 27 May 2026 11:22:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779880934; cv=none; b=dWMmCrd1Undd60WZ6SVNoXQNK+JUj3PFCSeayMLPsF+WbvDIrqRR6E3aAIOXrptbQzLcNJoUhLIddhjT+BBZpfJxR1QLmaVuWzL6OT4EvgoElpUtGdgz/XR+v/kSUTVWMjIb0KV3lPaNbCC14BZNAbspzYpyxGlcJ0/pB9s55U4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779880934; c=relaxed/simple; bh=JegOKJMbcR0b1IXki+x8m9SrUbuBE9KaEEdkjVF4SBE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=caJVoNspyQVSZTyd7bDQzJ5KbWePLPRXEojllsViY/egfx7atn0FmPIRDjh1tRTKVrdyzhcKIpFDuQgkYsBg4OJa64SWKrtX/Vi2EdKeeXHOmnMDX2XW8oco1v9kU8uhCR71oqhrW5LH2MNZz92q0Hd8MI1kxOTwVE4gseHTc6Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tCXvGmy7; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="tCXvGmy7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18B371F000E9; Wed, 27 May 2026 11:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1779880932; bh=QK3h4qOFfT6gnHkQROMoMq6ksd04MFDLxJGTVHWCrEg=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=tCXvGmy7HS92VaRVvgyM2v002IOGE74+zdSW6nkl6zOGYVrkhdbOix5V1X5ESEvjC l4KaduPq5wEH9TWiwUIV9WMgaXZ57LMThtpv6aNA8HKIdv9EbLXY+RdiZXUF8IWkcl YARwj9G9pGM9Fo9JqIG3zc2QnCA4IOIZ9UT1LlVI= Date: Wed, 27 May 2026 13:21:19 +0200 From: Greg KH To: Hongling Zeng Cc: dpenkler@gmail.com, dominik.karol.piatkowski@protonmail.com, kees@kernel.org, dan.carpenter@linaro.org, lukeyang.dev@gmail.com, linux-kernel@vger.kernel.org, zhongling0719@126.com Subject: Re: [PATCH] gpib: fmh_gpib: Fix resource leaks in fmh_gpib_attach_impl Message-ID: <2026052705-enchanted-stadium-8d4b@gregkh> References: <20260527095450.647869-1-zenghongling@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260527095450.647869-1-zenghongling@kylinos.cn> On Wed, May 27, 2026 at 05:54:50PM +0800, Hongling Zeng wrote: > The fmh_gpib_attach_impl() function has multiple resource leaks in its > error handling paths. When any initialization step fails, the function > returns early without properly releasing previously acquired resources. > > Fix by adding proper error handling labels and cleanup code that releases > resources in the reverse order they were acquired. > > Fixes: 8e4841a0888c7 ("staging: gpib: Add Frank Mori Hess FPGA PCI GPIB driver") > Signed-off-by: Hongling Zeng > --- > drivers/gpib/fmh_gpib/fmh_gpib.c | 46 ++++++++++++++++++++++++-------- > 1 file changed, 35 insertions(+), 11 deletions(-) > > diff --git a/drivers/gpib/fmh_gpib/fmh_gpib.c b/drivers/gpib/fmh_gpib/fmh_gpib.c > index fcafdc02ea2e..af582453fef7 100644 > --- a/drivers/gpib/fmh_gpib/fmh_gpib.c > +++ b/drivers/gpib/fmh_gpib/fmh_gpib.c > @@ -1403,14 +1403,17 @@ static int fmh_gpib_attach_impl(struct gpib_board *board, const struct gpib_boar > res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "gpib_control_status"); > if (!res) { > dev_err(board->dev, "Unable to locate mmio resource\n"); > - return -ENODEV; > + retval = -ENODEV; > + return retval; > } > > if (request_mem_region(res->start, > resource_size(res), > pdev->name) == NULL) { > dev_err(board->dev, "cannot claim registers\n"); > - return -ENXIO; > + retval = -ENXIO; > + return retval; > + > } > e_priv->gpib_iomem_res = res; > > @@ -1418,7 +1421,8 @@ static int fmh_gpib_attach_impl(struct gpib_board *board, const struct gpib_boar > resource_size(e_priv->gpib_iomem_res)); > if (!nec_priv->mmiobase) { > dev_err(board->dev, "Could not map I/O memory\n"); > - return -ENOMEM; > + retval = -ENOMEM; > + goto err_release_gpib_region; > } > dev_dbg(board->dev, "iobase %pr remapped to %p\n", > e_priv->gpib_iomem_res, nec_priv->mmiobase); > @@ -1426,42 +1430,48 @@ static int fmh_gpib_attach_impl(struct gpib_board *board, const struct gpib_boar > res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma_fifos"); > if (!res) { > dev_err(board->dev, "Unable to locate mmio resource for gpib dma port\n"); > - return -ENODEV; > + retval = -ENODEV; > + goto err_iounmap_gpib; > } > if (request_mem_region(res->start, > resource_size(res), > pdev->name) == NULL) { > dev_err(board->dev, "cannot claim registers\n"); > - return -ENXIO; > + retval = -ENXIO; > + goto err_iounmap_gpib; > } > e_priv->dma_port_res = res; > e_priv->fifo_base = ioremap(e_priv->dma_port_res->start, > resource_size(e_priv->dma_port_res)); > if (!e_priv->fifo_base) { > dev_err(board->dev, "Could not map I/O memory for fifos\n"); > - return -ENOMEM; > + retval = -ENOMEM; > + goto err_release_dma_region; > } > dev_dbg(board->dev, "dma fifos 0x%lx remapped to %p, length=%ld\n", > (unsigned long)e_priv->dma_port_res->start, e_priv->fifo_base, > (unsigned long)resource_size(e_priv->dma_port_res)); > > irq = platform_get_irq(pdev, 0); > - if (irq < 0) > - return -EBUSY; > + if (irq < 0) { > + retval = -EBUSY; > + goto err_iounmap_fifo; > + } > + e_priv->irq = irq; > retval = request_irq(irq, fmh_gpib_interrupt, IRQF_SHARED, pdev->name, board); > if (retval) { > dev_err(board->dev, > "cannot register interrupt handler err=%d\n", > retval); > - return retval; > + goto err_iounmap_fifo; > } > - e_priv->irq = irq; > > if (acquire_dma) { > e_priv->dma_channel = dma_request_slave_channel(board->dev, "rxtx"); > if (!e_priv->dma_channel) { > dev_err(board->dev, "failed to acquire dma channel \"rxtx\".\n"); > - return -EIO; > + retval = -EIO; > + goto err_free_irq; > } > } > /* > @@ -1473,6 +1483,20 @@ static int fmh_gpib_attach_impl(struct gpib_board *board, const struct gpib_boar > fifo_max_burst_length_mask; > > return fmh_gpib_init(e_priv, board, handshake_mode); > + > +err_free_irq: > + free_irq(e_priv->irq, board); > +err_iounmap_fifo: > + iounmap(e_priv->fifo_base); > +err_release_dma_region: > + release_mem_region(e_priv->dma_port_res->start, > + resource_size(e_priv->dma_port_res)); > +err_iounmap_gpib: > + iounmap(nec_priv->mmiobase); > +err_release_gpib_region: > + release_mem_region(e_priv->gpib_iomem_res->start, > + resource_size(e_priv->gpib_iomem_res)); > + return retval; > } > > int fmh_gpib_attach_holdoff_all(struct gpib_board *board, const struct gpib_board_config *config) > -- > 2.25.1 > Hi, This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree. You are receiving this message because of the following common error(s) as indicated below: - You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this. If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers. thanks, greg k-h's patch email bot