2015-04-01 17:38:40

by Phong Tran

[permalink] [raw]
Subject: [PATCH 0/3] 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(-)

--
2.1.0


2015-04-01 17:38:48

by Phong Tran

[permalink] [raw]
Subject: [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

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

2015-04-01 17:39:13

by Phong Tran

[permalink] [raw]
Subject: [PATCH 2/3] staging: android: ion_test: unregister the misc device

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

2015-04-01 17:38:59

by Phong Tran

[permalink] [raw]
Subject: [PATCH 3/3] staging: android: ion_test: unregister the platform device

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

2015-04-01 22:22:07

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 2/3] staging: android: ion_test: unregister the misc device

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

2015-04-01 22:33:42

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 3/3] staging: android: ion_test: unregister the platform device

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

2015-04-02 14:40:00

by Phong Tran

[permalink] [raw]
Subject: [PATCH V2 0/3] Fix some issues of staging ion test driver

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

2015-04-02 14:36:44

by Phong Tran

[permalink] [raw]
Subject: [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

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

2015-04-02 14:36:49

by Phong Tran

[permalink] [raw]
Subject: [PATCH V2 2/3] staging: android: ion_test: unregister the misc device

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

2015-04-02 14:39:33

by Phong Tran

[permalink] [raw]
Subject: [PATCH V2 3/3] staging: android: ion_test: unregister the platform device

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

2015-04-02 15:23:13

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH V2 0/3] Fix some issues of staging ion test driver

Thanks!

regards,
dan carpenter

2015-04-03 13:13:29

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH V2 2/3] staging: android: ion_test: unregister the misc device

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 :(

2015-04-03 14:07:25

by Phong Tran

[permalink] [raw]
Subject: [PATCH V3 0/2] 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(-)

--
2.1.0

2015-04-03 14:07:32

by Phong Tran

[permalink] [raw]
Subject: [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.

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

2015-04-03 14:07:35

by Phong Tran

[permalink] [raw]
Subject: [PATCH V3 2/2] staging: android: ion_test: unregister the platform device

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