Commit ce389573 authored by Alex Williamson's avatar Alex Williamson

vfio/ap/ccw/samples: Fix device_register() unwind path

We always need to call put_device() if device_register() fails.
All vfio drivers calling device_register() include a similar unwind
stack via gotos, therefore split device_unregister() into its
device_del() and put_device() components in the unwind path, and
add a goto target to handle only the put_device() requirement.
Reported-by: default avatarRuan Jinjie <ruanjinjie@huawei.com>
Link: https://lore.kernel.org/all/20221118032827.3725190-1-ruanjinjie@huawei.com
Fixes: d61fc96f ("sample: vfio mdev display - host device")
Fixes: 9d1a546c ("docs: Sample driver to demonstrate how to use Mediated device framework.")
Fixes: a5e6e650 ("sample: vfio bochs vbe display (host device for bochs-drm)")
Fixes: 9e6f07cd ("vfio/ccw: create a parent struct")
Fixes: 36360658 ("s390: vfio_ap: link the vfio_ap devices to the vfio_ap bus subsystem")
Cc: Tony Krowiak <akrowiak@linux.ibm.com>
Cc: Halil Pasic <pasic@linux.ibm.com>
Cc: Jason Herne <jjherne@linux.ibm.com>
Cc: Kirti Wankhede <kwankhede@nvidia.com>
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Reviewed-by: default avatarEric Farman <farman@linux.ibm.com>
Reviewed-by: default avatarTony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: default avatarJason J. Herne <jjherne@linux.ibm.com>
Link: https://lore.kernel.org/r/166999942139.645727.12439756512449846442.stgit@omenSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent e2d55709
...@@ -199,8 +199,9 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) ...@@ -199,8 +199,9 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
return 0; return 0;
out_unreg: out_unreg:
device_unregister(&parent->dev); device_del(&parent->dev);
out_free: out_free:
put_device(&parent->dev);
dev_set_drvdata(&sch->dev, NULL); dev_set_drvdata(&sch->dev, NULL);
return ret; return ret;
} }
......
...@@ -122,7 +122,7 @@ static int vfio_ap_matrix_dev_create(void) ...@@ -122,7 +122,7 @@ static int vfio_ap_matrix_dev_create(void)
return 0; return 0;
matrix_drv_err: matrix_drv_err:
device_unregister(&matrix_dev->device); device_del(&matrix_dev->device);
matrix_reg_err: matrix_reg_err:
put_device(&matrix_dev->device); put_device(&matrix_dev->device);
matrix_alloc_err: matrix_alloc_err:
......
...@@ -1430,7 +1430,7 @@ static int __init mbochs_dev_init(void) ...@@ -1430,7 +1430,7 @@ static int __init mbochs_dev_init(void)
ret = device_register(&mbochs_dev); ret = device_register(&mbochs_dev);
if (ret) if (ret)
goto err_class; goto err_put;
ret = mdev_register_parent(&mbochs_parent, &mbochs_dev, &mbochs_driver, ret = mdev_register_parent(&mbochs_parent, &mbochs_dev, &mbochs_driver,
mbochs_mdev_types, mbochs_mdev_types,
...@@ -1441,8 +1441,9 @@ static int __init mbochs_dev_init(void) ...@@ -1441,8 +1441,9 @@ static int __init mbochs_dev_init(void)
return 0; return 0;
err_device: err_device:
device_unregister(&mbochs_dev); device_del(&mbochs_dev);
err_class: err_put:
put_device(&mbochs_dev);
class_destroy(mbochs_class); class_destroy(mbochs_class);
err_driver: err_driver:
mdev_unregister_driver(&mbochs_driver); mdev_unregister_driver(&mbochs_driver);
......
...@@ -717,7 +717,7 @@ static int __init mdpy_dev_init(void) ...@@ -717,7 +717,7 @@ static int __init mdpy_dev_init(void)
ret = device_register(&mdpy_dev); ret = device_register(&mdpy_dev);
if (ret) if (ret)
goto err_class; goto err_put;
ret = mdev_register_parent(&mdpy_parent, &mdpy_dev, &mdpy_driver, ret = mdev_register_parent(&mdpy_parent, &mdpy_dev, &mdpy_driver,
mdpy_mdev_types, mdpy_mdev_types,
...@@ -728,8 +728,9 @@ static int __init mdpy_dev_init(void) ...@@ -728,8 +728,9 @@ static int __init mdpy_dev_init(void)
return 0; return 0;
err_device: err_device:
device_unregister(&mdpy_dev); device_del(&mdpy_dev);
err_class: err_put:
put_device(&mdpy_dev);
class_destroy(mdpy_class); class_destroy(mdpy_class);
err_driver: err_driver:
mdev_unregister_driver(&mdpy_driver); mdev_unregister_driver(&mdpy_driver);
......
...@@ -1330,7 +1330,7 @@ static int __init mtty_dev_init(void) ...@@ -1330,7 +1330,7 @@ static int __init mtty_dev_init(void)
ret = device_register(&mtty_dev.dev); ret = device_register(&mtty_dev.dev);
if (ret) if (ret)
goto err_class; goto err_put;
ret = mdev_register_parent(&mtty_dev.parent, &mtty_dev.dev, ret = mdev_register_parent(&mtty_dev.parent, &mtty_dev.dev,
&mtty_driver, mtty_mdev_types, &mtty_driver, mtty_mdev_types,
...@@ -1340,8 +1340,9 @@ static int __init mtty_dev_init(void) ...@@ -1340,8 +1340,9 @@ static int __init mtty_dev_init(void)
return 0; return 0;
err_device: err_device:
device_unregister(&mtty_dev.dev); device_del(&mtty_dev.dev);
err_class: err_put:
put_device(&mtty_dev.dev);
class_destroy(mtty_dev.vd_class); class_destroy(mtty_dev.vd_class);
err_driver: err_driver:
mdev_unregister_driver(&mtty_driver); mdev_unregister_driver(&mtty_driver);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment