ANDROID: trusty: Get rid of 'remove_new' relic from platform driver struct

Following on from Linus's change in Mainline, we have to convert all
.remove_new operation back to .remove. To support back to 5.10, we need
to handle the int return value for kernels less than v6.12.

Fixes: e70140ba0d2b ("Get rid of 'remove_new' relic from platform driver struct")
Change-Id: I130fb574b11207a4518f0dfdc5fe6cd3c12ae6ce
Signed-off-by: Lee Jones <[email protected]>
Signed-off-by: Will McVicker <[email protected]>
diff --git a/drivers/trusty/trusty-ffa-transport.c b/drivers/trusty/trusty-ffa-transport.c
index f3fbe67..58ba98b 100644
--- a/drivers/trusty/trusty-ffa-transport.c
+++ b/drivers/trusty/trusty-ffa-transport.c
@@ -12,6 +12,7 @@
 #include <linux/trusty/smcall.h>
 #include <linux/arm_ffa.h>
 #include <linux/trusty/trusty.h>
+#include <linux/version.h>
 
 #include <linux/scatterlist.h>
 #include <linux/dma-mapping.h>
@@ -299,7 +300,13 @@
 	return ret;
 }
 
-static void trusty_ffa_remove(struct ffa_device *ffa_dev)
+static
+#if (KERNEL_VERSION(6, 12, 0) > LINUX_VERSION_CODE)
+int
+#else
+void
+#endif
+trusty_ffa_remove(struct ffa_device *ffa_dev)
 {
 	struct trusty_ffa_state *s = ffa_dev_get_drvdata(ffa_dev);
 
@@ -309,6 +316,9 @@
 	 */
 	memzero_explicit(s, sizeof(struct trusty_ffa_state));
 	kfree(s);
+#if (KERNEL_VERSION(6, 12, 0) > LINUX_VERSION_CODE)
+	return 0;
+#endif
 }
 
 static const struct ffa_device_id trusty_ffa_device_id[] = {
@@ -478,7 +488,7 @@
 
 static struct platform_driver trusty_ffa_platform_driver = {
 	.probe = trusty_ffa_platform_probe,
-	.remove_new = trusty_ffa_platform_remove,
+	.remove = trusty_ffa_platform_remove,
 	.driver	= {
 		.name = "trusty-ffa",
 		.of_match_table = trusty_ffa_of_match,
diff --git a/drivers/trusty/trusty-irq.c b/drivers/trusty/trusty-irq.c
index 6bee431..b568d44 100644
--- a/drivers/trusty/trusty-irq.c
+++ b/drivers/trusty/trusty-irq.c
@@ -16,6 +16,7 @@
 #include <linux/trusty/smcall.h>
 #include <linux/trusty/sm_err.h>
 #include <linux/trusty/trusty.h>
+#include <linux/version.h>
 
 #include "trusty-irq.h"
 #include "trusty-irq-trace.h"
@@ -566,7 +567,13 @@
 	return ret;
 }
 
-static void trusty_irq_remove(struct platform_device *pdev)
+static
+#if (KERNEL_VERSION(6, 12, 0) > LINUX_VERSION_CODE)
+int
+#else
+void
+#endif
+trusty_irq_remove(struct platform_device *pdev)
 {
 	int ret;
 	unsigned long irq_flags;
@@ -587,6 +594,9 @@
 					&is->trusty_call_notifier);
 	free_percpu(is->percpu_irqs);
 	kfree(is);
+#if (KERNEL_VERSION(6, 12, 0) > LINUX_VERSION_CODE)
+	return 0;
+#endif
 }
 
 static const struct of_device_id trusty_test_of_match[] = {
@@ -598,7 +608,7 @@
 
 static struct platform_driver trusty_irq_driver = {
 	.probe = trusty_irq_probe,
-	.remove_new = trusty_irq_remove,
+	.remove = trusty_irq_remove,
 	.driver	= {
 		.name = "trusty-irq",
 		.of_match_table = trusty_test_of_match,
diff --git a/drivers/trusty/trusty-log.c b/drivers/trusty/trusty-log.c
index 0e1f92f..b68a5de 100644
--- a/drivers/trusty/trusty-log.c
+++ b/drivers/trusty/trusty-log.c
@@ -921,12 +921,21 @@
 	return rc;
 }
 
-static void trusty_log_remove(struct platform_device *pdev)
+static
+#if (KERNEL_VERSION(6, 12, 0) > LINUX_VERSION_CODE)
+int
+#else
+void
+#endif
+trusty_log_remove(struct platform_device *pdev)
 {
 	struct trusty_log_state *s = platform_get_drvdata(pdev);
 
 	trusty_log_sfile_unregister(s);
 	kref_put(&s->refcount, trusty_log_cleanup);
+#if (KERNEL_VERSION(6, 12, 0) > LINUX_VERSION_CODE)
+	return 0;
+#endif
 }
 
 static void trusty_log_cleanup(struct kref *ref)
@@ -975,7 +984,7 @@
 
 static struct platform_driver trusty_log_driver = {
 	.probe = trusty_log_probe,
-	.remove_new = trusty_log_remove,
+	.remove = trusty_log_remove,
 	.driver = {
 		.name = "trusty-log",
 		.of_match_table = trusty_test_of_match,
diff --git a/drivers/trusty/trusty-smc-transport.c b/drivers/trusty/trusty-smc-transport.c
index c5011b2..0e9c75f 100644
--- a/drivers/trusty/trusty-smc-transport.c
+++ b/drivers/trusty/trusty-smc-transport.c
@@ -11,6 +11,7 @@
 #include <linux/trusty/arm_ffa.h>
 #include <linux/trusty/smcall.h>
 #include <linux/trusty/trusty.h>
+#include <linux/version.h>
 
 #include <linux/scatterlist.h>
 #include <linux/dma-mapping.h>
@@ -491,7 +492,13 @@
 	return ret;
 }
 
-static void trusty_smc_remove(struct platform_device *pdev)
+static
+#if (KERNEL_VERSION(6, 12, 0) > LINUX_VERSION_CODE)
+int
+#else
+void
+#endif
+trusty_smc_remove(struct platform_device *pdev)
 {
 	struct trusty_smc_state *s = trusty_smc_get_state(platform_get_drvdata(pdev));
 	struct platform_device *core_pdev = to_platform_device(s->core_dev);
@@ -500,6 +507,9 @@
 	trusty_free_msg_buf(s);
 	mutex_destroy(&s->share_memory_msg_lock);
 	kfree(s);
+#if (KERNEL_VERSION(6, 12, 0) > LINUX_VERSION_CODE)
+	return 0;
+#endif
 }
 
 static const struct of_device_id trusty_smc_of_match[] = {
@@ -511,7 +521,7 @@
 
 static struct platform_driver trusty_smc_driver = {
 	.probe = trusty_smc_probe,
-	.remove_new = trusty_smc_remove,
+	.remove = trusty_smc_remove,
 	.driver	= {
 		.name = "trusty-smc",
 		.of_match_table = trusty_smc_of_match,
diff --git a/drivers/trusty/trusty-test-main.c b/drivers/trusty/trusty-test-main.c
index 0ea4cc3..e705f2f 100644
--- a/drivers/trusty/trusty-test-main.c
+++ b/drivers/trusty/trusty-test-main.c
@@ -13,6 +13,7 @@
 #include <linux/mm.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
+#include <linux/version.h>
 #include <linux/vmalloc.h>
 
 #include "trusty-test.h"
@@ -554,11 +555,20 @@
 	return 0;
 }
 
-static void trusty_test_remove(struct platform_device *pdev)
+static
+#if (KERNEL_VERSION(6, 12, 0) > LINUX_VERSION_CODE)
+int
+#else
+void
+#endif
+trusty_test_remove(struct platform_device *pdev)
 {
 	struct trusty_log_state *s = platform_get_drvdata(pdev);
 
 	kfree(s);
+#if (KERNEL_VERSION(6, 12, 0) > LINUX_VERSION_CODE)
+	return 0;
+#endif
 }
 
 static const struct of_device_id trusty_test_of_match[] = {
@@ -570,7 +580,7 @@
 
 static struct platform_driver trusty_test_driver = {
 	.probe = trusty_test_probe,
-	.remove_new = trusty_test_remove,
+	.remove = trusty_test_remove,
 	.driver = {
 		.name = "trusty-test",
 		.of_match_table = trusty_test_of_match,
diff --git a/drivers/trusty/trusty-virtio.c b/drivers/trusty/trusty-virtio.c
index 3f0aa05..1411736 100644
--- a/drivers/trusty/trusty-virtio.c
+++ b/drivers/trusty/trusty-virtio.c
@@ -936,7 +936,13 @@
 	return ret;
 }
 
-static void trusty_virtio_remove(struct platform_device *pdev)
+static
+#if (KERNEL_VERSION(6, 12, 0) > LINUX_VERSION_CODE)
+int
+#else
+void
+#endif
+trusty_virtio_remove(struct platform_device *pdev)
 {
 	struct trusty_ctx *tctx = platform_get_drvdata(pdev);
 	int ret;
@@ -976,6 +982,9 @@
 
 	/* free context */
 	kfree(tctx);
+#if (KERNEL_VERSION(6, 12, 0) > LINUX_VERSION_CODE)
+	return 0;
+#endif
 }
 
 static const struct of_device_id trusty_of_match[] = {
@@ -989,7 +998,7 @@
 
 static struct platform_driver trusty_virtio_driver = {
 	.probe = trusty_virtio_probe,
-	.remove_new = trusty_virtio_remove,
+	.remove = trusty_virtio_remove,
 	.driver = {
 		.name = "trusty-virtio",
 		.of_match_table = trusty_of_match,
diff --git a/drivers/trusty/trusty.c b/drivers/trusty/trusty.c
index f774ca0..109a20e 100644
--- a/drivers/trusty/trusty.c
+++ b/drivers/trusty/trusty.c
@@ -15,6 +15,7 @@
 #include <linux/trusty/smcall.h>
 #include <linux/trusty/sm_err.h>
 #include <linux/trusty/trusty.h>
+#include <linux/version.h>
 
 #include <linux/scatterlist.h>
 #include <linux/dma-mapping.h>
@@ -1078,7 +1079,14 @@
 	return ret;
 }
 
-static void trusty_remove(struct platform_device *pdev)
+
+static
+#if (KERNEL_VERSION(6, 12, 0) > LINUX_VERSION_CODE)
+int
+#else
+void
+#endif
+trusty_remove(struct platform_device *pdev)
 {
 	unsigned int cpu;
 	struct trusty_state *s = trusty_get_state(&pdev->dev);
@@ -1105,6 +1113,9 @@
 	s->dev->dma_parms = NULL;
 	kfree(s->version_str);
 	kfree(s);
+#if (KERNEL_VERSION(6, 12, 0) > LINUX_VERSION_CODE)
+	return 0;
+#endif
 }
 
 static const struct of_device_id trusty_of_match[] = {
@@ -1116,7 +1127,7 @@
 
 static struct platform_driver trusty_driver = {
 	.probe = trusty_probe,
-	.remove_new = trusty_remove,
+	.remove = trusty_remove,
 	.driver	= {
 		.name = "trusty-core",
 		.of_match_table = trusty_of_match,