Skip to contentSkip to conversation

virt: Convert to platform remove callback returning void

PATCH In review Uwe Kleine-König 3 participants 7 messages Dec 26, 2023 – Mar 7, 2024

lore
Share & tools
lore
#0 lore raw

cover virt: Convert to platform remove callback returning void

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

Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 virt: efi_secret: Convert to platform remove callback returning void

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.

---
 drivers/virt/coco/efi_secret/efi_secret.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/virt/coco/efi_secret/efi_secret.c +2 -3
index e700a5ef7043..cd29e66b1543 100644
@@ -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",
 	},
Signature · 1 line
2.43.0
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] virt: efi_secret: Convert to platform remove callback returning void

Quoted 11 lines · Uwe Kleine-König

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().

Quoted 4 lines

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

Quoted 30 lines
---
 drivers/virt/coco/efi_secret/efi_secret.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/virt/coco/efi_secret/efi_secret.c +2 -4
index e700a5ef7043..cd29e66b1543 100644
@@ -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

#3 lore raw

Re: [PATCH 1/2] virt: efi_secret: Convert to platform remove callback returning void

In reply to Uwe Kleine-König

Hello,

Quoted 10 lines · Uwe Kleine-König

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().

Quoted 4 lines

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

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

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
#4 lore raw

Re: [PATCH 1/2] virt: efi_secret: Convert to platform remove callback returning void

Quoted 14 lines · Uwe Kleine-König

Hello,

Quoted 10 lines · Uwe Kleine-König

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().

Quoted 8 lines
Quoted 4 lines

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

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,

#5 lore raw

PATCH 2/2 virt: sev-guest: Convert to platform remove callback returning void

In reply to Uwe Kleine-König

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.

---
 drivers/virt/coco/sev-guest/sev-guest.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/virt/coco/sev-guest/sev-guest.c +2 -4
index bc564adcf499..87f241825bc3 100644
@@ -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",
 	},
Signature · 1 line
2.43.0
Acked-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] virt: sev-guest: Convert to platform remove callback returning void

Quoted 10 lines · Uwe Kleine-König

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().

Quoted 4 lines

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

Quoted 35 lines
---
  drivers/virt/coco/sev-guest/sev-guest.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/virt/coco/sev-guest/sev-guest.c +2 -4
index bc564adcf499..87f241825bc3 100644
@@ -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",
  	},