From nobody Mon Jun 8 18:59:09 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 42C0E3BD657 for ; Wed, 27 May 2026 09:55:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779875703; cv=none; b=KEJHKvfMwyfVg79i3FdR+xrrpr5KSBlBe8IQHjyj8GT7+kgFP986hNnBIwwRU/0nPdFu0WQpsY58TaqlvOU7LiI/h1um/sdSDWaRGaipQYnxNTS1g0P7zVA5oEaCRsckngAe1JtD/K6OMNM2cOjbh5BCoL4eZQ7C7Y/F5Izpcac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779875703; c=relaxed/simple; bh=m79esSZXs4H1Rx2qc+nZD+/AvvP7RQHjYASnoJ/gSNc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=uRQkx7KGqvERaQ+Ci9zFy9ASIqMHm4cjYDlVpK60KRp+Is5oNC6RRqbe1uRMoce8vbhkeZ5nF/8QyqFA69SBKLIIEjlMX6/229IZUF0eO/vb4pC4q4G9u33yhWcXAza3zCfSd6Csnse/tJ9KOefy5pfLAlSy5fmvYvDs6mNqTlI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 1d7bfd2e59b211f1aa26b74ffac11d73-20260527 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:e58a5978-7e2b-4bbb-9e01-eee2a5a31802,IP:0,U RL:0,TC:0,Content:-5,EDM:-20,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:-25 X-CID-META: VersionHash:e7bac3a,CLOUDID:4cf102501411b1bbca4a48b910d26818,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:102|850|865|898,TC:nil,Content:0|15|50,E DM:1,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA: 0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 1d7bfd2e59b211f1aa26b74ffac11d73-20260527 X-User: zenghongling@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1841508147; Wed, 27 May 2026 17:54:55 +0800 From: Hongling Zeng To: dpenkler@gmail.com, gregkh@linuxfoundation.org, dominik.karol.piatkowski@protonmail.com, kees@kernel.org, dan.carpenter@linaro.org, lukeyang.dev@gmail.com Cc: linux-kernel@vger.kernel.org, zhongling0719@126.com, Hongling Zeng Subject: [PATCH] gpib: fmh_gpib: Fix resource leaks in fmh_gpib_attach_impl Date: Wed, 27 May 2026 17:54:50 +0800 Message-Id: <20260527095450.647869-1-zenghongling@kylinos.cn> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 dri= ver") 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_g= pib.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 =3D 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 =3D -ENODEV; + return retval; } =20 if (request_mem_region(res->start, resource_size(res), pdev->name) =3D=3D NULL) { dev_err(board->dev, "cannot claim registers\n"); - return -ENXIO; + retval =3D -ENXIO; + return retval; + } e_priv->gpib_iomem_res =3D res; =20 @@ -1418,7 +1421,8 @@ static int fmh_gpib_attach_impl(struct gpib_board *bo= ard, 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 =3D -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 =3D 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 =3D -ENODEV; + goto err_iounmap_gpib; } if (request_mem_region(res->start, resource_size(res), pdev->name) =3D=3D NULL) { dev_err(board->dev, "cannot claim registers\n"); - return -ENXIO; + retval =3D -ENXIO; + goto err_iounmap_gpib; } e_priv->dma_port_res =3D res; e_priv->fifo_base =3D 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 =3D -ENOMEM; + goto err_release_dma_region; } dev_dbg(board->dev, "dma fifos 0x%lx remapped to %p, length=3D%ld\n", (unsigned long)e_priv->dma_port_res->start, e_priv->fifo_base, (unsigned long)resource_size(e_priv->dma_port_res)); =20 irq =3D platform_get_irq(pdev, 0); - if (irq < 0) - return -EBUSY; + if (irq < 0) { + retval =3D -EBUSY; + goto err_iounmap_fifo; + } + e_priv->irq =3D irq; retval =3D request_irq(irq, fmh_gpib_interrupt, IRQF_SHARED, pdev->name, = board); if (retval) { dev_err(board->dev, "cannot register interrupt handler err=3D%d\n", retval); - return retval; + goto err_iounmap_fifo; } - e_priv->irq =3D irq; =20 if (acquire_dma) { e_priv->dma_channel =3D 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 =3D -EIO; + goto err_free_irq; } } /* @@ -1473,6 +1483,20 @@ static int fmh_gpib_attach_impl(struct gpib_board *b= oard, const struct gpib_boar fifo_max_burst_length_mask; =20 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; } =20 int fmh_gpib_attach_holdoff_all(struct gpib_board *board, const struct gpi= b_board_config *config) --=20 2.25.1