Fix some issues of staging ion test driver
cover Fix some issues of staging ion test driver
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(-)
Signature · 1 line
2.1.0
PATCH 1/3 staging: android: ion_test: Add the MODULE_LICENSE macro
Base on the file comment should define GPL v2 for ion test driver
--- drivers/staging/android/ion/ion_test.c | 1 + 1 file changed, 1 insertion(+)
drivers/staging/android/ion/ion_test.c +1 -0
@@ -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" );
Signature · 1 line
2.1.0
PATCH 2/3 staging: android: ion_test: unregister the misc device
In reply to Phong TranAdd the remove() method for deregister from misc device when it's unloaded.
--- drivers/staging/android/ion/ion_test.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/staging/android/ion/ion_test.c +18 -0
@@ -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" , },
Signature · 1 line
2.1.0
Re: [PATCH 2/3] staging: android: ion_test: unregister the misc device
Quoted 13 lines · Phong Tran
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(+)drivers/staging/android/ion/ion_test.c +0
-0
drivers/staging/android/ion/ion_test.c static int __init ion_test_probe(struct platform_device *pdev) · line 266
Quoted 6 lines
drivers/staging/android/ion/ion_test.c +3
-0@@ -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.
drivers/staging/android/ion/ion_test.c static int __init ion_test_probe(struct platform_device *pdev) · line 271
Quoted 5 lines
drivers/staging/android/ion/ion_test.c +5
-0+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.
drivers/staging/android/ion/ion_test.c static int __init ion_test_probe(struct platform_device *pdev) · line 272
Quoted 1 line
drivers/staging/android/ion/ion_test.c +1
-0+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.
drivers/staging/android/ion/ion_test.c static int __init ion_test_probe(struct platform_device *pdev) · line 278
Quoted 6 lines
drivers/staging/android/ion/ion_test.c +6
-0+return -ENODATA ; + } + + ret =misc_deregister (&testdev->misc); + +return ret;
return misc_deregister(&testdev->misc);
regards,
dan carpenter
PATCH 3/3 staging: android: ion_test: unregister the platform device
In reply to Phong TranThe driver has to unregister from platform device when it's unloaded
--- drivers/staging/android/ion/ion_test.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/staging/android/ion/ion_test.c +10 -1
@@ -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);
Signature · 1 line
2.1.0
Re: [PATCH 3/3] staging: android: ion_test: unregister the platform device
Quoted 12 lines · Phong Tran
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(-)drivers/staging/android/ion/ion_test.c +0
-0
drivers/staging/android/ion/ion_test.c static int ion_test_remove(struct platform_device *pdev) · line 281
Quoted 4 lines
drivers/staging/android/ion/ion_test.c +1
-0@@ -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.
drivers/staging/android/ion/ion_test.c static struct platform_driver ion_test_platform_driver = { · line 292
Quoted 10 lines
drivers/staging/android/ion/ion_test.c +2
-1static 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.
drivers/staging/android/ion/ion_test.c static struct platform_driver ion_test_platform_driver = { · line 295
Quoted 3 lines
drivers/staging/android/ion/ion_test.c +3
-0+ +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
v2 cover Fix some issues of staging ion test driver
In reply to Phong TranHi 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(-)
Signature · 1 line
2.1.0
PATCH v2 1/3 staging: android: ion_test: Add the MODULE_LICENSE macro
Base on the file comment should define GPL v2 for ion test driver
--- drivers/staging/android/ion/ion_test.c | 1 + 1 file changed, 1 insertion(+)
drivers/staging/android/ion/ion_test.c +1 -0
@@ -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" );
Signature · 1 line
2.1.0
PATCH v2 2/3 staging: android: ion_test: unregister the misc device
In reply to Phong TranAdd the remove() method for deregister from misc device when it's unloaded.
--- drivers/staging/android/ion/ion_test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/staging/android/ion/ion_test.c +12 -0
@@ -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" , },
Signature · 1 line
2.1.0
Greg KH
maintainerRe: [PATCH V2 2/3] staging: android: ion_test: unregister the misc device
Quoted 15 lines · Phong Tran
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(+)drivers/staging/android/ion/ion_test.c +0
-0@@ -261,7 +261,19 @@ static int __init ion_test_probe(struct platform_device *pdev)return 0 ; }
drivers/staging/android/ion/ion_test.c static int __init ion_test_probe(struct platform_device *pdev) · line 272
Quoted 10 lines
drivers/staging/android/ion/ion_test.c +9
-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 :(
v3 cover Fix some issues of staging ion test driver
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(-)
Signature · 1 line
2.1.0
PATCH v3 1/2 staging: android: ion_test: unregister the misc device
Add the remove() method for deregister from misc device when it's unloaded.
--- drivers/staging/android/ion/ion_test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/staging/android/ion/ion_test.c +12 -0
@@ -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" , },
Signature · 1 line
2.1.0
PATCH v3 2/2 staging: android: ion_test: unregister the platform device
In reply to Phong TranThe driver has to unregister from platform device when it's unloaded
--- drivers/staging/android/ion/ion_test.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/staging/android/ion/ion_test.c +7 -1
@@ -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);
Signature · 1 line
2.1.0
PATCH v2 3/3 staging: android: ion_test: unregister the platform device
In reply to Phong TranThe driver has to unregister from platform device when it's unloaded
--- drivers/staging/android/ion/ion_test.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/staging/android/ion/ion_test.c +7 -1
@@ -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);
Signature · 1 line
2.1.0
Thanks!
regards,
dan carpenter