linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] virt: Convert to platform remove callback returning void
@ 2023-12-26 13:28 Uwe Kleine-König
  2023-12-26 13:28 ` [PATCH 1/2] virt: efi_secret: " Uwe Kleine-König
  2023-12-26 13:28 ` [PATCH 2/2] virt: sev-guest: " Uwe Kleine-König
  0 siblings, 2 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2023-12-26 13:28 UTC (permalink / raw)
  To: Dov Murik, Ard Biesheuvel, Dan Williams, Borislav Petkov (AMD),
	Tom Lendacky, Dionna Glaze
  Cc: kernel, Gerd Hoffmann, linux-kernel

Hello,

this series converts the two platform drivers below drivers/virt that
make use of .remove() to use .remove_new() instead.

See commit 5c5a7680e67b ("platform: Provide a remove callback that
returns no value") for an extended explanation and the eventual goal.
The TL;DR; is to make it harder for driver authors to leak resources
without noticing. The drivers here get it right though and so can be
converted trivially.

This is merge window material. There doesn't seem to be a maintainer for
all of drivers/virt and I don't know how patch application works there
usally. The two patches are independent of each other so they can be
applied individually if necessary.

Best regards
Uwe

Uwe Kleine-König (2):
  virt: efi_secret: Convert to platform remove callback returning void
  virt: sev-guest: Convert to platform remove callback returning void

 drivers/virt/coco/efi_secret/efi_secret.c | 5 ++---
 drivers/virt/coco/sev-guest/sev-guest.c   | 6 ++----
 2 files changed, 4 insertions(+), 7 deletions(-)

base-commit: b85ea95d086471afb4ad062012a4d73cd328fa86
-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] virt: efi_secret: Convert to platform remove callback returning void
  2023-12-26 13:28 [PATCH 0/2] virt: Convert to platform remove callback returning void Uwe Kleine-König
@ 2023-12-26 13:28 ` Uwe Kleine-König
  2024-01-03 13:18   ` Ard Biesheuvel
  2024-03-06 21:35   ` Uwe Kleine-König
  2023-12-26 13:28 ` [PATCH 2/2] virt: sev-guest: " Uwe Kleine-König
  1 sibling, 2 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2023-12-26 13:28 UTC (permalink / raw)
  To: Dov Murik, Ard Biesheuvel, Dan Williams
  Cc: kernel, Gerd Hoffmann, linux-kernel

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/virt/coco/efi_secret/efi_secret.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/virt/coco/efi_secret/efi_secret.c b/drivers/virt/coco/efi_secret/efi_secret.c
index e700a5ef7043..cd29e66b1543 100644
--- a/drivers/virt/coco/efi_secret/efi_secret.c
+++ b/drivers/virt/coco/efi_secret/efi_secret.c
@@ -326,16 +326,15 @@ static int efi_secret_probe(struct platform_device *dev)
 	return ret;
 }
 
-static int efi_secret_remove(struct platform_device *dev)
+static void efi_secret_remove(struct platform_device *dev)
 {
 	efi_secret_securityfs_teardown(dev);
 	efi_secret_unmap_area();
-	return 0;
 }
 
 static struct platform_driver efi_secret_driver = {
 	.probe = efi_secret_probe,
-	.remove = efi_secret_remove,
+	.remove_new = efi_secret_remove,
 	.driver = {
 		.name = "efi_secret",
 	},
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] virt: sev-guest: Convert to platform remove callback returning void
  2023-12-26 13:28 [PATCH 0/2] virt: Convert to platform remove callback returning void Uwe Kleine-König
  2023-12-26 13:28 ` [PATCH 1/2] virt: efi_secret: " Uwe Kleine-König
@ 2023-12-26 13:28 ` Uwe Kleine-König
  2024-01-02 16:47   ` Tom Lendacky
  1 sibling, 1 reply; 7+ messages in thread
From: Uwe Kleine-König @ 2023-12-26 13:28 UTC (permalink / raw)
  To: Borislav Petkov (AMD), Tom Lendacky, Dan Williams, Dionna Glaze
  Cc: kernel, linux-kernel

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/virt/coco/sev-guest/sev-guest.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c
index bc564adcf499..87f241825bc3 100644
--- a/drivers/virt/coco/sev-guest/sev-guest.c
+++ b/drivers/virt/coco/sev-guest/sev-guest.c
@@ -994,7 +994,7 @@ static int __init sev_guest_probe(struct platform_device *pdev)
 	return ret;
 }
 
-static int __exit sev_guest_remove(struct platform_device *pdev)
+static void __exit sev_guest_remove(struct platform_device *pdev)
 {
 	struct snp_guest_dev *snp_dev = platform_get_drvdata(pdev);
 
@@ -1003,8 +1003,6 @@ static int __exit sev_guest_remove(struct platform_device *pdev)
 	free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg));
 	deinit_crypto(snp_dev->crypto);
 	misc_deregister(&snp_dev->misc);
-
-	return 0;
 }
 
 /*
@@ -1013,7 +1011,7 @@ static int __exit sev_guest_remove(struct platform_device *pdev)
  * with the SEV-SNP support, it is named "sev-guest".
  */
 static struct platform_driver sev_guest_driver = {
-	.remove		= __exit_p(sev_guest_remove),
+	.remove_new	= __exit_p(sev_guest_remove),
 	.driver		= {
 		.name = "sev-guest",
 	},
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] virt: sev-guest: Convert to platform remove callback returning void
  2023-12-26 13:28 ` [PATCH 2/2] virt: sev-guest: " Uwe Kleine-König
@ 2024-01-02 16:47   ` Tom Lendacky
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Lendacky @ 2024-01-02 16:47 UTC (permalink / raw)
  To: Uwe Kleine-König, Borislav Petkov (AMD), Dan Williams, Dionna Glaze
  Cc: kernel, linux-kernel

On 12/26/23 07:28, 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>

Acked-by: Tom Lendacky <thomas.lendacky@amd.com>

> ---
>   drivers/virt/coco/sev-guest/sev-guest.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c
> index bc564adcf499..87f241825bc3 100644
> --- a/drivers/virt/coco/sev-guest/sev-guest.c
> +++ b/drivers/virt/coco/sev-guest/sev-guest.c
> @@ -994,7 +994,7 @@ static int __init sev_guest_probe(struct platform_device *pdev)
>   	return ret;
>   }
>   
> -static int __exit sev_guest_remove(struct platform_device *pdev)
> +static void __exit sev_guest_remove(struct platform_device *pdev)
>   {
>   	struct snp_guest_dev *snp_dev = platform_get_drvdata(pdev);
>   
> @@ -1003,8 +1003,6 @@ static int __exit sev_guest_remove(struct platform_device *pdev)
>   	free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg));
>   	deinit_crypto(snp_dev->crypto);
>   	misc_deregister(&snp_dev->misc);
> -
> -	return 0;
>   }
>   
>   /*
> @@ -1013,7 +1011,7 @@ static int __exit sev_guest_remove(struct platform_device *pdev)
>    * with the SEV-SNP support, it is named "sev-guest".
>    */
>   static struct platform_driver sev_guest_driver = {
> -	.remove		= __exit_p(sev_guest_remove),
> +	.remove_new	= __exit_p(sev_guest_remove),
>   	.driver		= {
>   		.name = "sev-guest",
>   	},

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] virt: efi_secret: Convert to platform remove callback returning void
  2023-12-26 13:28 ` [PATCH 1/2] virt: efi_secret: " Uwe Kleine-König
@ 2024-01-03 13:18   ` Ard Biesheuvel
  2024-03-06 21:35   ` Uwe Kleine-König
  1 sibling, 0 replies; 7+ messages in thread
From: Ard Biesheuvel @ 2024-01-03 13:18 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Dov Murik, Dan Williams, kernel, Gerd Hoffmann, linux-kernel

On Tue, 26 Dec 2023 at 14:28, 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>

Acked-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>  drivers/virt/coco/efi_secret/efi_secret.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/virt/coco/efi_secret/efi_secret.c b/drivers/virt/coco/efi_secret/efi_secret.c
> index e700a5ef7043..cd29e66b1543 100644
> --- a/drivers/virt/coco/efi_secret/efi_secret.c
> +++ b/drivers/virt/coco/efi_secret/efi_secret.c
> @@ -326,16 +326,15 @@ static int efi_secret_probe(struct platform_device *dev)
>         return ret;
>  }
>
> -static int efi_secret_remove(struct platform_device *dev)
> +static void efi_secret_remove(struct platform_device *dev)
>  {
>         efi_secret_securityfs_teardown(dev);
>         efi_secret_unmap_area();
> -       return 0;
>  }
>
>  static struct platform_driver efi_secret_driver = {
>         .probe = efi_secret_probe,
> -       .remove = efi_secret_remove,
> +       .remove_new = efi_secret_remove,
>         .driver = {
>                 .name = "efi_secret",
>         },
> --
> 2.43.0
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] virt: efi_secret: Convert to platform remove callback returning void
  2023-12-26 13:28 ` [PATCH 1/2] virt: efi_secret: " Uwe Kleine-König
  2024-01-03 13:18   ` Ard Biesheuvel
@ 2024-03-06 21:35   ` Uwe Kleine-König
  2024-03-07  0:20     ` Ard Biesheuvel
  1 sibling, 1 reply; 7+ messages in thread
From: Uwe Kleine-König @ 2024-03-06 21:35 UTC (permalink / raw)
  To: Dov Murik, Ard Biesheuvel, Dan Williams
  Cc: Gerd Hoffmann, kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1114 bytes --]

Hello,

On Tue, Dec 26, 2023 at 02:28:02PM +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>

Is this patch still on someone's radar? If a resend would help, please
tell me.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] virt: efi_secret: Convert to platform remove callback returning void
  2024-03-06 21:35   ` Uwe Kleine-König
@ 2024-03-07  0:20     ` Ard Biesheuvel
  0 siblings, 0 replies; 7+ messages in thread
From: Ard Biesheuvel @ 2024-03-07  0:20 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Dov Murik, Dan Williams, Gerd Hoffmann, kernel, linux-kernel

On Wed, 6 Mar 2024 at 22:35, Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
>
> Hello,
>
> On Tue, Dec 26, 2023 at 02:28:02PM +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>
>
> Is this patch still on someone's radar? If a resend would help, please
> tell me.
>

I've queued this up in the EFI tree.

Thanks,

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-07  0:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-26 13:28 [PATCH 0/2] virt: Convert to platform remove callback returning void Uwe Kleine-König
2023-12-26 13:28 ` [PATCH 1/2] virt: efi_secret: " Uwe Kleine-König
2024-01-03 13:18   ` Ard Biesheuvel
2024-03-06 21:35   ` Uwe Kleine-König
2024-03-07  0:20     ` Ard Biesheuvel
2023-12-26 13:28 ` [PATCH 2/2] virt: sev-guest: " Uwe Kleine-König
2024-01-02 16:47   ` Tom Lendacky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).