* [PATCH] PCI: pnv_php: Use common error handling code in pnv_php_alloc_slot()
@ 2026-06-11 9:25 Markus Elfring
2026-06-11 9:33 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Markus Elfring @ 2026-06-11 9:25 UTC (permalink / raw)
To: linux-pci, linuxppc-dev, Bjorn Helgaas, Christophe Leroy,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin
Cc: LKML, kernel-janitors, Ilpo Järvinen, Jonathan Cameron,
Krzysztof Kozlowski
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 11 Jun 2026 11:16:49 +0200
Use an additional label so that a bit of exception handling can be better
reused at the end of an if branch.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/pci/hotplug/pnv_php.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/pci/hotplug/pnv_php.c b/drivers/pci/hotplug/pnv_php.c
index ff92a5c301b8..e448f1802002 100644
--- a/drivers/pci/hotplug/pnv_php.c
+++ b/drivers/pci/hotplug/pnv_php.c
@@ -791,16 +791,15 @@ static struct pnv_php_slot *pnv_php_alloc_slot(struct device_node *dn)
return NULL;
php_slot->name = kstrdup(label, GFP_KERNEL);
- if (!php_slot->name) {
- kfree(php_slot);
- return NULL;
- }
+ if (!php_slot->name)
+ goto free_php_slot;
/* Allocate workqueue for this slot's interrupt handling */
php_slot->wq = alloc_workqueue("pciehp-%s", WQ_PERCPU, 0, php_slot->name);
if (!php_slot->wq) {
SLOT_WARN(php_slot, "Cannot alloc workqueue\n");
kfree(php_slot->name);
+free_php_slot:
kfree(php_slot);
return NULL;
}
--
2.54.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] PCI: pnv_php: Use common error handling code in pnv_php_alloc_slot()
2026-06-11 9:25 [PATCH] PCI: pnv_php: Use common error handling code in pnv_php_alloc_slot() Markus Elfring
@ 2026-06-11 9:33 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-06-11 9:33 UTC (permalink / raw)
To: Markus Elfring; +Cc: linux-pci
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Low] The patch introduces spaghetti code by placing an error cleanup label inside the body of an intermediate 'if' block.
Pre-existing issues:
- [High] Calling SLOT_WARN() when alloc_workqueue() fails causes a NULL pointer dereference because php_slot->bus is uninitialized.
--
commit fc5acb6d5ef23950f12a496bbb0ba6bddebe9f87
Author: Markus Elfring <elfring@users.sourceforge.net>
PCI: pnv_php: Use common error handling code in pnv_php_alloc_slot()
This commit introduces a new goto label to reuse error handling when allocating
a PCI hotplug slot in pnv_php.
> diff --git a/drivers/pci/hotplug/pnv_php.c b/drivers/pci/hotplug/pnv_php.c
> index ff92a5c301b81..e448f18020026 100644
> --- a/drivers/pci/hotplug/pnv_php.c
> +++ b/drivers/pci/hotplug/pnv_php.c
[ ... ]
> @@ -791,16 +791,15 @@ static struct pnv_php_slot *pnv_php_alloc_slot(struct device_node *dn)
[ ... ]
> /* Allocate workqueue for this slot's interrupt handling */
> php_slot->wq = alloc_workqueue("pciehp-%s", WQ_PERCPU, 0, php_slot->name);
> if (!php_slot->wq) {
> SLOT_WARN(php_slot, "Cannot alloc workqueue\n");
[Severity: High]
This is a pre-existing issue, but can this call to SLOT_WARN() cause a NULL
pointer dereference?
Looking at pnv_php_alloc_slot(), php_slot->pdev and php_slot->bus are not
initialized until much later in the function. Since the structure is
kzalloc'd, SLOT_WARN() will evaluate with a NULL php_slot->pdev and fall back
to dev_warn(&(sl)->bus->dev, ...).
Because php_slot->bus is also NULL here, this calculates an offset from a NULL
pointer and passes it to dev_warn(), which will crash when it attempts to read
the device name.
> kfree(php_slot->name);
> +free_php_slot:
[Severity: Low]
Does placing a cleanup label inside an intermediate if block obscure the
control flow?
Standard kernel coding style typically places cleanup labels sequentially at
the end of the function rather than embedding them inside failure paths.
> kfree(php_slot);
> return NULL;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/5cd04727-44c5-4ace-af86-d3c227234d4b@web.de?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-11 9:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-11 9:25 [PATCH] PCI: pnv_php: Use common error handling code in pnv_php_alloc_slot() Markus Elfring
2026-06-11 9:33 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox