Skip to content

Commit a6792a0

Browse files
Yang YingliangJassiBrar
authored andcommitted
mailbox: zynq-ipi: fix error handling while device_register() fails
If device_register() fails, it has two issues: 1. The name allocated by dev_set_name() is leaked. 2. The parent of device is not NULL, device_unregister() is called in zynqmp_ipi_free_mboxes(), it will lead a kernel crash because of removing not added device. Call put_device() to give up the reference, so the name is freed in kobject_cleanup(). Add device registered check in zynqmp_ipi_free_mboxes() to avoid null-ptr-deref. Fixes: 4981b82 ("mailbox: ZynqMP IPI mailbox controller") Signed-off-by: Yang Yingliang <[email protected]> Signed-off-by: Jassi Brar <[email protected]>
1 parent acabe12 commit a6792a0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/mailbox/zynqmp-ipi-mailbox.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ static int zynqmp_ipi_mbox_probe(struct zynqmp_ipi_mbox *ipi_mbox,
493493
ret = device_register(&ipi_mbox->dev);
494494
if (ret) {
495495
dev_err(dev, "Failed to register ipi mbox dev.\n");
496+
put_device(&ipi_mbox->dev);
496497
return ret;
497498
}
498499
mdev = &ipi_mbox->dev;
@@ -619,7 +620,8 @@ static void zynqmp_ipi_free_mboxes(struct zynqmp_ipi_pdata *pdata)
619620
ipi_mbox = &pdata->ipi_mboxes[i];
620621
if (ipi_mbox->dev.parent) {
621622
mbox_controller_unregister(&ipi_mbox->mbox);
622-
device_unregister(&ipi_mbox->dev);
623+
if (device_is_registered(&ipi_mbox->dev))
624+
device_unregister(&ipi_mbox->dev);
623625
}
624626
}
625627
}

0 commit comments

Comments
 (0)