diff mbox series

vfio/platform: Convert to platform remove callback returning void

Message ID 79d3df42fe5b359a05b8061631e72e5ed249b234.1709886922.git.u.kleine-koenig@pengutronix.de (mailing list archive)
State New, archived
Headers show
Series vfio/platform: Convert to platform remove callback returning void | expand

Commit Message

Uwe Kleine-König March 8, 2024, 8:51 a.m. UTC
The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is ignored (apart
from emitting a warning) and this typically results in resource leaks.

To improve here there is a quest to make the remove callback return
void. In the first step of this quest all drivers are converted to
.remove_new(), which already returns void. Eventually after all drivers
are converted, .remove_new() will be renamed to .remove().

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/vfio/platform/vfio_platform.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)


base-commit: 8ffc8b1bbd505e27e2c8439d326b6059c906c9dd

Comments

Jason Gunthorpe March 8, 2024, 5:06 p.m. UTC | #1
On Fri, Mar 08, 2024 at 09:51:19AM +0100, Uwe Kleine-König wrote:
> The .remove() callback for a platform driver returns an int which makes
> many driver authors wrongly assume it's possible to do error handling by
> returning an error code. However the value returned is ignored (apart
> from emitting a warning) and this typically results in resource leaks.
> 
> To improve here there is a quest to make the remove callback return
> void. In the first step of this quest all drivers are converted to
> .remove_new(), which already returns void. Eventually after all drivers
> are converted, .remove_new() will be renamed to .remove().
> 
> Trivially convert this driver from always returning zero in the remove
> callback to the void returning variant.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/vfio/platform/vfio_platform.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

Jason
Eric Auger March 11, 2024, 7:38 a.m. UTC | #2
Hi,

On 3/8/24 09:51, Uwe Kleine-König wrote:
> The .remove() callback for a platform driver returns an int which makes
> many driver authors wrongly assume it's possible to do error handling by
> returning an error code. However the value returned is ignored (apart
> from emitting a warning) and this typically results in resource leaks.
>
> To improve here there is a quest to make the remove callback return
> void. In the first step of this quest all drivers are converted to
> .remove_new(), which already returns void. Eventually after all drivers
> are converted, .remove_new() will be renamed to .remove().
>
> Trivially convert this driver from always returning zero in the remove
> callback to the void returning variant.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Eric
> ---
>  drivers/vfio/platform/vfio_platform.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/vfio/platform/vfio_platform.c b/drivers/vfio/platform/vfio_platform.c
> index 8cf22fa65baa..42d1462c5e19 100644
> --- a/drivers/vfio/platform/vfio_platform.c
> +++ b/drivers/vfio/platform/vfio_platform.c
> @@ -85,14 +85,13 @@ static void vfio_platform_release_dev(struct vfio_device *core_vdev)
>  	vfio_platform_release_common(vdev);
>  }
>  
> -static int vfio_platform_remove(struct platform_device *pdev)
> +static void vfio_platform_remove(struct platform_device *pdev)
>  {
>  	struct vfio_platform_device *vdev = dev_get_drvdata(&pdev->dev);
>  
>  	vfio_unregister_group_dev(&vdev->vdev);
>  	pm_runtime_disable(vdev->device);
>  	vfio_put_device(&vdev->vdev);
> -	return 0;
>  }
>  
>  static const struct vfio_device_ops vfio_platform_ops = {
> @@ -113,7 +112,7 @@ static const struct vfio_device_ops vfio_platform_ops = {
>  
>  static struct platform_driver vfio_platform_driver = {
>  	.probe		= vfio_platform_probe,
> -	.remove		= vfio_platform_remove,
> +	.remove_new	= vfio_platform_remove,
>  	.driver	= {
>  		.name	= "vfio-platform",
>  	},
>
> base-commit: 8ffc8b1bbd505e27e2c8439d326b6059c906c9dd
Alex Williamson March 11, 2024, 8:22 p.m. UTC | #3
On Fri,  8 Mar 2024 09:51:19 +0100
Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:

> The .remove() callback for a platform driver returns an int which makes
> many driver authors wrongly assume it's possible to do error handling by
> returning an error code. However the value returned is ignored (apart
> from emitting a warning) and this typically results in resource leaks.
> 
> To improve here there is a quest to make the remove callback return
> void. In the first step of this quest all drivers are converted to
> .remove_new(), which already returns void. Eventually after all drivers
> are converted, .remove_new() will be renamed to .remove().
> 
> Trivially convert this driver from always returning zero in the remove
> callback to the void returning variant.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/vfio/platform/vfio_platform.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

Applied to vfio next branch for v6.9.  Thanks,

Alex

> 
> diff --git a/drivers/vfio/platform/vfio_platform.c b/drivers/vfio/platform/vfio_platform.c
> index 8cf22fa65baa..42d1462c5e19 100644
> --- a/drivers/vfio/platform/vfio_platform.c
> +++ b/drivers/vfio/platform/vfio_platform.c
> @@ -85,14 +85,13 @@ static void vfio_platform_release_dev(struct vfio_device *core_vdev)
>  	vfio_platform_release_common(vdev);
>  }
>  
> -static int vfio_platform_remove(struct platform_device *pdev)
> +static void vfio_platform_remove(struct platform_device *pdev)
>  {
>  	struct vfio_platform_device *vdev = dev_get_drvdata(&pdev->dev);
>  
>  	vfio_unregister_group_dev(&vdev->vdev);
>  	pm_runtime_disable(vdev->device);
>  	vfio_put_device(&vdev->vdev);
> -	return 0;
>  }
>  
>  static const struct vfio_device_ops vfio_platform_ops = {
> @@ -113,7 +112,7 @@ static const struct vfio_device_ops vfio_platform_ops = {
>  
>  static struct platform_driver vfio_platform_driver = {
>  	.probe		= vfio_platform_probe,
> -	.remove		= vfio_platform_remove,
> +	.remove_new	= vfio_platform_remove,
>  	.driver	= {
>  		.name	= "vfio-platform",
>  	},
> 
> base-commit: 8ffc8b1bbd505e27e2c8439d326b6059c906c9dd
diff mbox series

Patch

diff --git a/drivers/vfio/platform/vfio_platform.c b/drivers/vfio/platform/vfio_platform.c
index 8cf22fa65baa..42d1462c5e19 100644
--- a/drivers/vfio/platform/vfio_platform.c
+++ b/drivers/vfio/platform/vfio_platform.c
@@ -85,14 +85,13 @@  static void vfio_platform_release_dev(struct vfio_device *core_vdev)
 	vfio_platform_release_common(vdev);
 }
 
-static int vfio_platform_remove(struct platform_device *pdev)
+static void vfio_platform_remove(struct platform_device *pdev)
 {
 	struct vfio_platform_device *vdev = dev_get_drvdata(&pdev->dev);
 
 	vfio_unregister_group_dev(&vdev->vdev);
 	pm_runtime_disable(vdev->device);
 	vfio_put_device(&vdev->vdev);
-	return 0;
 }
 
 static const struct vfio_device_ops vfio_platform_ops = {
@@ -113,7 +112,7 @@  static const struct vfio_device_ops vfio_platform_ops = {
 
 static struct platform_driver vfio_platform_driver = {
 	.probe		= vfio_platform_probe,
-	.remove		= vfio_platform_remove,
+	.remove_new	= vfio_platform_remove,
 	.driver	= {
 		.name	= "vfio-platform",
 	},