Skip to content

Commit b9ecbfa

Browse files
committed
nvme: apple: fix device reference counting
Drivers must call nvme_uninit_ctrl after a successful nvme_init_ctrl. Split the allocation side out to make the error handling boundary easier to navigate. The apple driver had been doing this wrong, leaking the controller device memory on a tagset failure. Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 4434887 commit b9ecbfa

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

drivers/nvme/host/apple.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,15 +1388,15 @@ static void devm_apple_nvme_mempool_destroy(void *data)
13881388
mempool_destroy(data);
13891389
}
13901390

1391-
static int apple_nvme_probe(struct platform_device *pdev)
1391+
static struct apple_nvme *apple_nvme_alloc(struct platform_device *pdev)
13921392
{
13931393
struct device *dev = &pdev->dev;
13941394
struct apple_nvme *anv;
13951395
int ret;
13961396

13971397
anv = devm_kzalloc(dev, sizeof(*anv), GFP_KERNEL);
13981398
if (!anv)
1399-
return -ENOMEM;
1399+
return ERR_PTR(-ENOMEM);
14001400

14011401
anv->dev = get_device(dev);
14021402
anv->adminq.is_adminq = true;
@@ -1516,19 +1516,36 @@ static int apple_nvme_probe(struct platform_device *pdev)
15161516
goto put_dev;
15171517
}
15181518

1519+
return anv;
1520+
put_dev:
1521+
put_device(anv->dev);
1522+
return ERR_PTR(ret);
1523+
}
1524+
1525+
static int apple_nvme_probe(struct platform_device *pdev)
1526+
{
1527+
struct apple_nvme *anv;
1528+
int ret;
1529+
1530+
anv = apple_nvme_alloc(pdev);
1531+
if (IS_ERR(anv))
1532+
return PTR_ERR(anv);
1533+
15191534
anv->ctrl.admin_q = blk_mq_alloc_queue(&anv->admin_tagset, NULL, NULL);
15201535
if (IS_ERR(anv->ctrl.admin_q)) {
15211536
ret = -ENOMEM;
1522-
goto put_dev;
1537+
anv->ctrl.admin_q = NULL;
1538+
goto out_uninit_ctrl;
15231539
}
15241540

15251541
nvme_reset_ctrl(&anv->ctrl);
15261542
async_schedule(apple_nvme_async_probe, anv);
15271543

15281544
return 0;
15291545

1530-
put_dev:
1531-
put_device(anv->dev);
1546+
out_uninit_ctrl:
1547+
nvme_uninit_ctrl(&anv->ctrl);
1548+
nvme_put_ctrl(&anv->ctrl);
15321549
return ret;
15331550
}
15341551

0 commit comments

Comments
 (0)