From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj2-f7.google.com (mail-pj2-f7.google.com [74.125.227.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91AF743801D for ; Thu, 23 Jul 2026 14:28:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.135 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784816926; cv=none; b=B55765FRXxoTx9bTKgOPEswluXGcWhcporc0PgVnu2yprIi92LszYfx62k4Bpo95c+NGqq22/89fQP26Kl1Mo60QA9C4mfssXgdM8dtZyfwv4UZ4R1gxGEg3Ecc0GSQQA6bCMmnUuCIgtAA0j64zYM3AGi7xGPPt4UV+LsXmMhQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784816926; c=relaxed/simple; bh=PKDwq+x+NOmYN7QbKKAajaz0VL8NafGdsM2UBpgp1e4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=CF3/FE9Xcg2bvAmuC0jM2lF++udUKFWrdOw9pAqMrIoidMMaCA4ND0yR7PMMh/19kytf250ZI7icsl7cUUn7B5OFNWFbjsdUby5K220371zIZ83SvkRoak+Yfmi2YKy7fOJbRqoGb/0YPgHgoNSsZKpEDpPeooZcCIObJgTTzdg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kTJIVpIv; arc=none smtp.client-ip=74.125.227.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kTJIVpIv" Received: by mail-pj2-f7.google.com with SMTP id 98e67ed59e1d1-38dcd98e5easo364896a91.0 for ; Thu, 23 Jul 2026 07:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784816921; x=1785421721; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=E0Yy60Buxa1oln1foYGDC/ST2/TxbKXJmmCBtwLn+QU=; b=kTJIVpIv866zsA4I3x5WsvdGFv7IlGsb7zzeCT+9TTOP4PrsCnOL+ITwJor53qXv20 C5rX656QB99HuqttNDLTJqTcCn0gGeqITjxdQYPoQatFQ0q7RTe5AGh65CLESb7SjUfF Dpq2qvheLhVQDrQHg7gekJ41OeT/JAstb0fSXpjbj7qLjmw2BkmPCv5D94Bh0S0Y+phJ MaeEXBdTaqUlj9rLT0dVUwpJShQBEdbvQlcViFWF2V50ZysyGWAirXPrE9Jk5Yk/AZho FblyzW7DTEJYTEf1SCTMsn9BlAwK1VgF6N+YaqlnS4maqH1Lvr8F63TlcQKY3XVBBkvN xoAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784816921; x=1785421721; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=E0Yy60Buxa1oln1foYGDC/ST2/TxbKXJmmCBtwLn+QU=; b=eXuwBq+ngp+aLPd+joFZKc+maFhQFa/c/QBbK7nwvjvmZY6MVFPCUL8jvnlsDyPxxa vsoa3X0H2nBNPlLL8i3C585OBXYjvensrNw5XQ+vzME3FZz3XbFlT3NCrw8/afOCdvcY Qb12VIG4Ai7pFyC+k45TCZMDBxc8otBc6tmyctQu+z4wQXFB5z2211eplwW1ICH+nYWb YtIaV64X+cwtXuCOjaOagYFIcE9/1pJcYZpEOz8UxX+xN6ajf3MjTZekYNPZjHJxQx/j JrqvsVFGwfBKI6aRSEZIPF0+gLXm7YUu2v5MujSMo6TQi3Gori4Yevp3QQGBiiV5j/jc F5Qw== X-Forwarded-Encrypted: i=1; AHgh+RqKV6lCbQQCSKxTJuWWVJLX4sGAYlGIQx4RQezsRZC/vsnu6Qgxr3eqs9qCzJPqqyasVLch/jWrtVJ/qEM=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9uj7TpGXLfWs1nOLHUsmgHH97uCCaOI4vH/t239QsaZR6FLxe fqekYtY7AmsGPNeiElZs18L+L4f8ZVfaFh1VH+xG8rxafsG6QkpcBJyXr0FSSW+C X-Gm-Gg: AR+sD13QdFUpSc0fzP/UO3f8o8jc3NHDNLYd/7YN/EmQ1b4vtJkPIEOl4zFS3quPrXG c+hZOzqVgOtKg87Vx6Qy62ZNhjoNElzHvIe+vazTneVNBbNNu3cHmiaYd60K7L44DL9r/M71vb6 NQ2Rt/mZh1UMe/OkpjzXz8g/7OpXHyWKrciqJ0HQQ9xg9Auoi1pVBnP2p1NlGLRrJI3Sa3AgVVH FrA2s4SMO1jYM0gZbs2+BUCKQMzSFmoj4LNf/vKTYv1DHPl67MaPGmcfeXyQ9Jq5qcxrYpspD71 BVYnEOitX1x05QvlokwrfUeIcKD2uGb1tlrVjBtgfhKgtMmlA2WxPGtlFOvyQ/Lr+duLIaHdEqR aj4fe12r5Rk9UiPnn+uKo9HX2YRJ9FZ06H3spxGXLICbBaGP9vWzAtLdsGXGB7SYf5eLYfha+uz SWYXuHFJyl X-Received: by 2002:a05:6a21:a394:b0:3b2:8685:118b with SMTP id adf61e73a8af0-3c44aff1d71mr3653312637.20.1784816921359; Thu, 23 Jul 2026 07:28:41 -0700 (PDT) Received: from workstation.. ([182.180.105.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147dc9f2f0sm21575371eec.13.2026.07.23.07.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 07:28:41 -0700 (PDT) From: Ali Tariq To: daire.mcnamara@microchip.com Cc: lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, minda.chen@starfivetech.com, conor.dooley@microchip.com, mason.huo@starfivetech.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, alitariq45892@gmail.com Subject: [PATCH v3 2/2] PCI: plda: Fix resource leaks on error paths in plda_init_interrupts() Date: Thu, 23 Jul 2026 19:28:24 +0500 Message-Id: <20260723142824.726655-1-alitariq45892@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit plda_init_interrupts() initializes IRQ domains and creates IRQ mapping but does not unwind them when later step fails. If platform_get_irq() or either irq_create_mapping() fails in plda_init_interrupts(), the domains are never deinitialized. If irq_create_mapping() fails, port->intx_irq stays initialized. plda_pcie_irq_domain_deinit() now disposes of the intx_irq and msi_irq mappings itself before removing their domains, so the msi_irq mapping failure path can go directly to err_irq_domain_deinit instead of disposing of port->intx_irq separately first. This removes the need for the err_dispose_irq_mapping label used in earlier versions of this patch. This issue was found by automated review of sashiko-bot Fixes: 4602c370bdf6 ("PCI: microchip: Move IRQ functions to pcie-plda-host.c") Fixes: 76c911396807 ("PCI: plda: Add host init/deinit and map bus functions") Link: https://lore.kernel.org/linux-pci/20260718120701.DF4111F000E9@smtp.kernel.org/ Signed-off-by: Ali Tariq Cc: stable@vger.kernel.org --- Changes in v3: - plda_pcie_irq_domain_deinit() now disposes of intx_irq/msi_irq mappings itself (see patch 1/2 of this series), so drop the separate err_dispose_irq_mapping label and go straight to err_irq_domain_deinit on msi_irq mapping failure. Changes in v2: - Added PCI subsystem prefix to the subject line, no functional change. Link to v2: https://lore.kernel.org/linux-pci/20260721131522.594267-1-alitariq45892@gmail.com/ Link to v1: https://lore.kernel.org/linux-pci/20260721130034.560632-1-alitariq45892@gmail.com/ --- drivers/pci/controller/plda/pcie-plda-host.c | 28 +++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/pci/controller/plda/pcie-plda-host.c b/drivers/pci/controller/plda/pcie-plda-host.c index 791f5c1cce06..fd1a11b4c8eb 100644 --- a/drivers/pci/controller/plda/pcie-plda-host.c +++ b/drivers/pci/controller/plda/pcie-plda-host.c @@ -419,6 +419,8 @@ static int plda_pcie_init_irq_domains(struct plda_pcie_rp *port) return plda_allocate_msi_domains(port); } +static void plda_pcie_irq_domain_deinit(struct plda_pcie_rp *pcie); + int plda_init_interrupts(struct platform_device *pdev, struct plda_pcie_rp *port, const struct plda_event *event) @@ -440,14 +442,17 @@ int plda_init_interrupts(struct platform_device *pdev, } port->irq = platform_get_irq(pdev, 0); - if (port->irq < 0) - return -ENODEV; + if (port->irq < 0) { + ret = -ENODEV; + goto err_irq_domain_deinit; + } for_each_set_bit(i, &port->events_bitmap, port->num_events) { event_irq = irq_create_mapping(port->event_domain, i); if (!event_irq) { dev_err(dev, "failed to map hwirq %d\n", i); - return -ENXIO; + ret = -ENXIO; + goto err_irq_domain_deinit; } if (event->request_event_irq) @@ -459,7 +464,7 @@ int plda_init_interrupts(struct platform_device *pdev, if (ret) { dev_err(dev, "failed to request IRQ %d\n", event_irq); - return ret; + goto err_irq_domain_deinit; } } @@ -467,7 +472,8 @@ int plda_init_interrupts(struct platform_device *pdev, event->intx_event); if (!port->intx_irq) { dev_err(dev, "failed to map INTx interrupt\n"); - return -ENXIO; + ret = -ENXIO; + goto err_irq_domain_deinit; } /* Plug the INTx chained handler */ @@ -475,8 +481,11 @@ int plda_init_interrupts(struct platform_device *pdev, port->msi_irq = irq_create_mapping(port->event_domain, event->msi_event); - if (!port->msi_irq) - return -ENXIO; + if (!port->msi_irq) { + dev_err(dev, "failed to map MSI interrupt\n"); + ret = -ENXIO; + goto err_irq_domain_deinit; + } /* Plug the MSI chained handler */ irq_set_chained_handler_and_data(port->msi_irq, plda_handle_msi, port); @@ -485,6 +494,11 @@ int plda_init_interrupts(struct platform_device *pdev, irq_set_chained_handler_and_data(port->irq, plda_handle_event, port); return 0; + +err_irq_domain_deinit: + plda_pcie_irq_domain_deinit(port); + + return ret; } EXPORT_SYMBOL_GPL(plda_init_interrupts); -- 2.34.1