Hi Greg, Arve, Riley,
This patcheset fixes:
(1) Define the GPL V2 for ion_test driver
(2) Add the remove() platform driver callback to
deregister the misc device
(3) unregister platform device when driver is unloaded
Phong Tran (3):
staging: android: ion_test: Add the MODULE_LICENSE macro
staging: android: ion_test: unregister the misc device
staging: android: ion_test: unregister the platform device
drivers/staging/android/ion/ion_test.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
--
2.1.0
Base on the file comment should define GPL v2 for ion test driver
Signed-off-by: Phong Tran <[email protected]>
---
drivers/staging/android/ion/ion_test.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/staging/android/ion/ion_test.c b/drivers/staging/android/ion/ion_test.c
index 654acb5..3bc461c 100644
--- a/drivers/staging/android/ion/ion_test.c
+++ b/drivers/staging/android/ion/ion_test.c
@@ -280,3 +280,4 @@ static void __exit ion_test_exit(void)
module_init(ion_test_init);
module_exit(ion_test_exit);
+MODULE_LICENSE("GPL v2");
--
2.1.0
Add the remove() method for deregister from misc device
when it's unloaded.
Signed-off-by: Phong Tran <[email protected]>
---
drivers/staging/android/ion/ion_test.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/drivers/staging/android/ion/ion_test.c b/drivers/staging/android/ion/ion_test.c
index 3bc461c..f36a35e 100644
--- a/drivers/staging/android/ion/ion_test.c
+++ b/drivers/staging/android/ion/ion_test.c
@@ -261,7 +261,25 @@ static int __init ion_test_probe(struct platform_device *pdev)
return 0;
}
+static int ion_test_remove(struct platform_device *pdev)
+{
+ int ret = 0;
+ struct ion_test_device *testdev;
+
+ testdev = platform_get_drvdata(pdev);
+
+ if (!testdev) {
+ pr_err("failed to get pdev data.\n");
+ return -ENODATA;
+ }
+
+ ret = misc_deregister(&testdev->misc);
+
+ return ret;
+}
+
static struct platform_driver ion_test_platform_driver = {
+ .remove = ion_test_remove,
.driver = {
.name = "ion-test",
},
--
2.1.0
The driver has to unregister from platform device when it's unloaded
Signed-off-by: Phong Tran <[email protected]>
---
drivers/staging/android/ion/ion_test.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/android/ion/ion_test.c b/drivers/staging/android/ion/ion_test.c
index f36a35e..d2a236e 100644
--- a/drivers/staging/android/ion/ion_test.c
+++ b/drivers/staging/android/ion/ion_test.c
@@ -278,6 +278,7 @@ static int ion_test_remove(struct platform_device *pdev)
return ret;
}
+static struct platform_device *ion_test_platform_device;
static struct platform_driver ion_test_platform_driver = {
.remove = ion_test_remove,
.driver = {
@@ -287,13 +288,21 @@ static struct platform_driver ion_test_platform_driver = {
static int __init ion_test_init(void)
{
- platform_device_register_simple("ion-test", -1, NULL, 0);
+ ion_test_platform_device = platform_device_register_simple("ion-test",
+ -1, NULL, 0);
+
+ if (!ion_test_platform_device) {
+ pr_err("failed to register ion-test platform device\n");
+ return -ENODEV;
+ }
+
return platform_driver_probe(&ion_test_platform_driver, ion_test_probe);
}
static void __exit ion_test_exit(void)
{
platform_driver_unregister(&ion_test_platform_driver);
+ platform_device_unregister(ion_test_platform_device);
}
module_init(ion_test_init);
--
2.1.0
On Thu, Apr 02, 2015 at 12:38:19AM +0700, Phong Tran wrote:
> Add the remove() method for deregister from misc device
> when it's unloaded.
>
> Signed-off-by: Phong Tran <[email protected]>
> ---
> drivers/staging/android/ion/ion_test.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/drivers/staging/android/ion/ion_test.c b/drivers/staging/android/ion/ion_test.c
> index 3bc461c..f36a35e 100644
> --- a/drivers/staging/android/ion/ion_test.c
> +++ b/drivers/staging/android/ion/ion_test.c
> @@ -261,7 +261,25 @@ static int __init ion_test_probe(struct platform_device *pdev)
> return 0;
> }
>
> +static int ion_test_remove(struct platform_device *pdev)
> +{
> + int ret = 0;
Don't initialize variables if you don't need to. Just remove the ret
variable completely.
> + struct ion_test_device *testdev;
> +
> + testdev = platform_get_drvdata(pdev);
> +
> + if (!testdev) {
Remove the blank line between the function and the check. They are part
of the same thing/paragraph.
> + pr_err("failed to get pdev data.\n");
Just leave this error statement out. It will never get printed. It's
just a waste of RAM. If it were printed the -ENODATA error is unique
to this path so it's all the debug out put we need.
> + return -ENODATA;
> + }
> +
> + ret = misc_deregister(&testdev->misc);
> +
> + return ret;
return misc_deregister(&testdev->misc);
regards,
dan carpenter
On Thu, Apr 02, 2015 at 12:38:20AM +0700, Phong Tran wrote:
> The driver has to unregister from platform device when it's unloaded
>
> Signed-off-by: Phong Tran <[email protected]>
> ---
> drivers/staging/android/ion/ion_test.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/android/ion/ion_test.c b/drivers/staging/android/ion/ion_test.c
> index f36a35e..d2a236e 100644
> --- a/drivers/staging/android/ion/ion_test.c
> +++ b/drivers/staging/android/ion/ion_test.c
> @@ -278,6 +278,7 @@ static int ion_test_remove(struct platform_device *pdev)
> return ret;
> }
>
> +static struct platform_device *ion_test_platform_device;
This name is too long. You will run into the 80 character limit.
> static struct platform_driver ion_test_platform_driver = {
> .remove = ion_test_remove,
> .driver = {
> @@ -287,13 +288,21 @@ static struct platform_driver ion_test_platform_driver = {
>
> static int __init ion_test_init(void)
> {
> - platform_device_register_simple("ion-test", -1, NULL, 0);
> + ion_test_platform_device = platform_device_register_simple("ion-test",
> + -1, NULL, 0);
This indenting is off. It should be:
ion_test_dev = platform_device_register_simple("ion-test",
-1, NULL, 0);
or something similar.
> +
> + if (!ion_test_platform_device) {
> + pr_err("failed to register ion-test platform device\n");
People add error messages without thinking about it because they think,
"Obviously, the more error messages the better." Almost all the bad
things that can happen in platform_device_register_simple() generate
their own error message.
Also platform_driver_probe() doesn't have an error message so it's
possible to leave them out if you want. Be bold! Leave out the
message! Or if you want go ahead and leave it in. So long as you have
thought about it is what matters.
regards,
dan carpenter
Hi Greg, Arve, Riley, Dan,
This patcheset fixes:
(1) Define the GPL V2 for ion_test driver
(2) Add the remove() platform driver callback to
deregister the misc device
(3) unregister platform device when driver is unloaded
Thank for Dan's reivew.
Changes from v1:
Imporve the coding style
Phong Tran (3):
staging: android: ion_test: Add the MODULE_LICENSE macro
staging: android: ion_test: unregister the misc device
staging: android: ion_test: unregister the platform device
drivers/staging/android/ion/ion_test.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
--
2.1.0
Base on the file comment should define GPL v2 for ion test driver
Signed-off-by: Phong Tran <[email protected]>
---
drivers/staging/android/ion/ion_test.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/staging/android/ion/ion_test.c b/drivers/staging/android/ion/ion_test.c
index 654acb5..3bc461c 100644
--- a/drivers/staging/android/ion/ion_test.c
+++ b/drivers/staging/android/ion/ion_test.c
@@ -280,3 +280,4 @@ static void __exit ion_test_exit(void)
module_init(ion_test_init);
module_exit(ion_test_exit);
+MODULE_LICENSE("GPL v2");
--
2.1.0
Add the remove() method for deregister from misc device
when it's unloaded.
Signed-off-by: Phong Tran <[email protected]>
---
drivers/staging/android/ion/ion_test.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/staging/android/ion/ion_test.c b/drivers/staging/android/ion/ion_test.c
index 3bc461c..d6a9653 100644
--- a/drivers/staging/android/ion/ion_test.c
+++ b/drivers/staging/android/ion/ion_test.c
@@ -261,7 +261,19 @@ static int __init ion_test_probe(struct platform_device *pdev)
return 0;
}
+static int ion_test_remove(struct platform_device *pdev)
+{
+ struct ion_test_device *testdev;
+
+ testdev = platform_get_drvdata(pdev);
+ if (!testdev)
+ return -ENODATA;
+
+ return misc_deregister(&testdev->misc);
+}
+
static struct platform_driver ion_test_platform_driver = {
+ .remove = ion_test_remove,
.driver = {
.name = "ion-test",
},
--
2.1.0
The driver has to unregister from platform device when it's unloaded
Signed-off-by: Phong Tran <[email protected]>
---
drivers/staging/android/ion/ion_test.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/android/ion/ion_test.c b/drivers/staging/android/ion/ion_test.c
index d6a9653..24fd77d3 100644
--- a/drivers/staging/android/ion/ion_test.c
+++ b/drivers/staging/android/ion/ion_test.c
@@ -272,6 +272,7 @@ static int ion_test_remove(struct platform_device *pdev)
return misc_deregister(&testdev->misc);
}
+static struct platform_device *ion_test_pdev;
static struct platform_driver ion_test_platform_driver = {
.remove = ion_test_remove,
.driver = {
@@ -281,13 +282,18 @@ static struct platform_driver ion_test_platform_driver = {
static int __init ion_test_init(void)
{
- platform_device_register_simple("ion-test", -1, NULL, 0);
+ ion_test_pdev = platform_device_register_simple("ion-test",
+ -1, NULL, 0);
+ if (!ion_test_pdev)
+ return -ENODEV;
+
return platform_driver_probe(&ion_test_platform_driver, ion_test_probe);
}
static void __exit ion_test_exit(void)
{
platform_driver_unregister(&ion_test_platform_driver);
+ platform_device_unregister(ion_test_pdev);
}
module_init(ion_test_init);
--
2.1.0
Thanks!
regards,
dan carpenter
On Thu, Apr 02, 2015 at 09:36:06PM +0700, Phong Tran wrote:
> Add the remove() method for deregister from misc device
> when it's unloaded.
>
> Signed-off-by: Phong Tran <[email protected]>
> ---
> drivers/staging/android/ion/ion_test.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/staging/android/ion/ion_test.c b/drivers/staging/android/ion/ion_test.c
> index 3bc461c..d6a9653 100644
> --- a/drivers/staging/android/ion/ion_test.c
> +++ b/drivers/staging/android/ion/ion_test.c
> @@ -261,7 +261,19 @@ static int __init ion_test_probe(struct platform_device *pdev)
> return 0;
> }
>
> +static int ion_test_remove(struct platform_device *pdev)
> +{
> + struct ion_test_device *testdev;
> +
> + testdev = platform_get_drvdata(pdev);
> + if (!testdev)
> + return -ENODATA;
> +
> + return misc_deregister(&testdev->misc);
Extra space here :(
Hi Greg,
I resend 2 patches
(1) add the remove() platform driver callback to
deregister the misc device
(2) unregister platform device when driver is unloaded
Changes from v2:
Remove the extra space of patch (1)
Changes from v1:
Imporve the coding style
Phong Tran (2):
(1) staging: android: ion_test: unregister the misc device
(2) staging: android: ion_test: unregister the platform device
drivers/staging/android/ion/ion_test.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
--
2.1.0
Add the remove() method for deregister from misc device
when it's unloaded.
Signed-off-by: Phong Tran <[email protected]>
---
drivers/staging/android/ion/ion_test.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/staging/android/ion/ion_test.c b/drivers/staging/android/ion/ion_test.c
index 3bc461c..052d5e2 100644
--- a/drivers/staging/android/ion/ion_test.c
+++ b/drivers/staging/android/ion/ion_test.c
@@ -261,7 +261,19 @@ static int __init ion_test_probe(struct platform_device *pdev)
return 0;
}
+static int ion_test_remove(struct platform_device *pdev)
+{
+ struct ion_test_device *testdev;
+
+ testdev = platform_get_drvdata(pdev);
+ if (!testdev)
+ return -ENODATA;
+
+ return misc_deregister(&testdev->misc);
+}
+
static struct platform_driver ion_test_platform_driver = {
+ .remove = ion_test_remove,
.driver = {
.name = "ion-test",
},
--
2.1.0
The driver has to unregister from platform device when it's unloaded
Signed-off-by: Phong Tran <[email protected]>
---
drivers/staging/android/ion/ion_test.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/android/ion/ion_test.c b/drivers/staging/android/ion/ion_test.c
index 052d5e2..7d6e6b6 100644
--- a/drivers/staging/android/ion/ion_test.c
+++ b/drivers/staging/android/ion/ion_test.c
@@ -272,6 +272,7 @@ static int ion_test_remove(struct platform_device *pdev)
return misc_deregister(&testdev->misc);
}
+static struct platform_device *ion_test_pdev;
static struct platform_driver ion_test_platform_driver = {
.remove = ion_test_remove,
.driver = {
@@ -281,13 +282,18 @@ static struct platform_driver ion_test_platform_driver = {
static int __init ion_test_init(void)
{
- platform_device_register_simple("ion-test", -1, NULL, 0);
+ ion_test_pdev = platform_device_register_simple("ion-test",
+ -1, NULL, 0);
+ if (!ion_test_pdev)
+ return -ENODEV;
+
return platform_driver_probe(&ion_test_platform_driver, ion_test_probe);
}
static void __exit ion_test_exit(void)
{
platform_driver_unregister(&ion_test_platform_driver);
+ platform_device_unregister(ion_test_pdev);
}
module_init(ion_test_init);
--
2.1.0