[PATCH] nvme: apple: tolerate missing power-domain arrays during cleanup

From: Slavin Liu

Date: Sun Sep 13 2026 - 08:53:52 EST


pd_count is set before either backing array is allocated. A failed
array allocation can therefore reach cleanup with a positive count but
a NULL array. Check each array before indexing it.

Detected by static analysis and reviewed with AI-assisted source auditing.

Fixes: eefa72a15ea0 ("apple-nvme: Release power domains when probe fails")
Assisted-by: LLM
Signed-off-by: Slavin Liu <bolin.liu@xxxxxxxxxx>
---
drivers/nvme/host/apple.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c
index c63e28c75766..b7835e736d82 100644
--- a/drivers/nvme/host/apple.c
+++ b/drivers/nvme/host/apple.c
@@ -1398,9 +1398,9 @@ static void apple_nvme_detach_genpd(struct apple_nvme *anv)
return;

for (i = anv->pd_count - 1; i >= 0; i--) {
- if (anv->pd_link[i])
+ if (anv->pd_link && anv->pd_link[i])
device_link_del(anv->pd_link[i]);
- if (!IS_ERR_OR_NULL(anv->pd_dev[i]))
+ if (anv->pd_dev && !IS_ERR_OR_NULL(anv->pd_dev[i]))
dev_pm_domain_detach(anv->pd_dev[i], true);
}
}