Re: [PATCH 01/20] coresight: Fix memory leak in coresight_register

2018-06-06 Thread Arvind Yadav

Hi Suzuki,


On Wednesday 06 June 2018 03:13 AM, Suzuki K Poulose wrote:

commit 6403587a930c ("coresight: use put_device() instead of kfree()")
introduced a memory leak where, if we fail to register the device
for coresight_device, we don't free the "coresight_device" object,
which was allocated via kzalloc(). Fix this by jumping to the
appropriate error path.

put_device() will decrement the last reference and then
free the memory by calling dev->release.  Internally
put_device() -> kobject_put() -> kobject_cleanup() which is
responsible to call 'dev -> release' and also free other kobject
resources. If you will see the coresight_device_release. There
we are releasing all allocated memory. Still if you call kfree() again
then it'll be redundancy.

~arvind


Fixes: commit 6403587a930c ("coresight: use put_device() instead of kfree()")
Cc: Mathieu Poirier 
Cc: Arvind Yadav 
Signed-off-by: Suzuki K Poulose 
---
  drivers/hwtracing/coresight/coresight.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index 4969b32..2893cfe 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1020,7 +1020,7 @@ struct coresight_device *coresight_register(struct 
coresight_desc *desc)
ret = device_register(>dev);
if (ret) {
put_device(>dev);
-   goto err_kzalloc_csdev;
+   goto err_kzalloc_refcnts;
}
  
  	mutex_lock(_mutex);




Re: [PATCH 01/20] coresight: Fix memory leak in coresight_register

2018-06-06 Thread Arvind Yadav

Hi Suzuki,


On Wednesday 06 June 2018 03:13 AM, Suzuki K Poulose wrote:

commit 6403587a930c ("coresight: use put_device() instead of kfree()")
introduced a memory leak where, if we fail to register the device
for coresight_device, we don't free the "coresight_device" object,
which was allocated via kzalloc(). Fix this by jumping to the
appropriate error path.

put_device() will decrement the last reference and then
free the memory by calling dev->release.  Internally
put_device() -> kobject_put() -> kobject_cleanup() which is
responsible to call 'dev -> release' and also free other kobject
resources. If you will see the coresight_device_release. There
we are releasing all allocated memory. Still if you call kfree() again
then it'll be redundancy.

~arvind


Fixes: commit 6403587a930c ("coresight: use put_device() instead of kfree()")
Cc: Mathieu Poirier 
Cc: Arvind Yadav 
Signed-off-by: Suzuki K Poulose 
---
  drivers/hwtracing/coresight/coresight.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index 4969b32..2893cfe 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1020,7 +1020,7 @@ struct coresight_device *coresight_register(struct 
coresight_desc *desc)
ret = device_register(>dev);
if (ret) {
put_device(>dev);
-   goto err_kzalloc_csdev;
+   goto err_kzalloc_refcnts;
}
  
  	mutex_lock(_mutex);




Re: [PATCH v2] staging: greybus: Use gpio_is_valid()

2018-05-02 Thread Arvind Yadav



On Wednesday 02 May 2018 03:27 PM, Johan Hovold wrote:

On Wed, May 02, 2018 at 03:15:05PM +0530, Arvind Yadav wrote:


On Wednesday 02 May 2018 02:13 PM, Johan Hovold wrote:

On Sat, Apr 28, 2018 at 10:05:39AM +0530, Arvind Yadav wrote:

Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
chnage in v2 :
   Returning invalid gpio as error instead of -ENODEV.

   drivers/staging/greybus/arche-platform.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/greybus/arche-platform.c 
b/drivers/staging/greybus/arche-platform.c
index 83254a7..c3a7da5 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -448,7 +448,7 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_reset_gpio = of_get_named_gpio(np,
"svc,reset-gpio",
0);
-   if (arche_pdata->svc_reset_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_reset_gpio)) {
dev_err(dev, "failed to get reset-gpio\n");
return arche_pdata->svc_reset_gpio;

I'm sorry, but I don't this change is desirable. of_get_named_gpio()
returns a valid gpio number or a negative errno, so there's no need to
use the legacy gpio_is_valid() helper here.

If you grep for of_get_named_gpio() you'll find that some drivers indeed
use that helper this way, but they are in a clear minority.

And ultimately, we want to move to using gpio descriptors anyway.

We need to check gpio validity. If we are using of_get_named_gpio() or
not.  of_get_name_gpio() will read a device node and fetch the value.
But it'll not check that gpio is valid or not valid.

No, I believe you're mistaken here. of_get_named_gpio() does not return
an arbitrary gpio number, unlike what you could possibly find in
legacy board files and for which the gpio_is_valid() helper made sense.

Johan

Yes, You are coorect. It'll read gpio form gpio device node. Which means
it'll read from device tree node. without finding a valid entry. It'll 
return

an error.

~arvind



Re: [PATCH v2] staging: greybus: Use gpio_is_valid()

2018-05-02 Thread Arvind Yadav



On Wednesday 02 May 2018 03:27 PM, Johan Hovold wrote:

On Wed, May 02, 2018 at 03:15:05PM +0530, Arvind Yadav wrote:


On Wednesday 02 May 2018 02:13 PM, Johan Hovold wrote:

On Sat, Apr 28, 2018 at 10:05:39AM +0530, Arvind Yadav wrote:

Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav 
---
chnage in v2 :
   Returning invalid gpio as error instead of -ENODEV.

   drivers/staging/greybus/arche-platform.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/greybus/arche-platform.c 
b/drivers/staging/greybus/arche-platform.c
index 83254a7..c3a7da5 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -448,7 +448,7 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_reset_gpio = of_get_named_gpio(np,
"svc,reset-gpio",
0);
-   if (arche_pdata->svc_reset_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_reset_gpio)) {
dev_err(dev, "failed to get reset-gpio\n");
return arche_pdata->svc_reset_gpio;

I'm sorry, but I don't this change is desirable. of_get_named_gpio()
returns a valid gpio number or a negative errno, so there's no need to
use the legacy gpio_is_valid() helper here.

If you grep for of_get_named_gpio() you'll find that some drivers indeed
use that helper this way, but they are in a clear minority.

And ultimately, we want to move to using gpio descriptors anyway.

We need to check gpio validity. If we are using of_get_named_gpio() or
not.  of_get_name_gpio() will read a device node and fetch the value.
But it'll not check that gpio is valid or not valid.

No, I believe you're mistaken here. of_get_named_gpio() does not return
an arbitrary gpio number, unlike what you could possibly find in
legacy board files and for which the gpio_is_valid() helper made sense.

Johan

Yes, You are coorect. It'll read gpio form gpio device node. Which means
it'll read from device tree node. without finding a valid entry. It'll 
return

an error.

~arvind



Re: [PATCH v2] staging: greybus: Use gpio_is_valid()

2018-05-02 Thread Arvind Yadav



On Wednesday 02 May 2018 02:13 PM, Johan Hovold wrote:

On Sat, Apr 28, 2018 at 10:05:39AM +0530, Arvind Yadav wrote:

Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
chnage in v2 :
  Returning invalid gpio as error instead of -ENODEV.

  drivers/staging/greybus/arche-platform.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/greybus/arche-platform.c 
b/drivers/staging/greybus/arche-platform.c
index 83254a7..c3a7da5 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -448,7 +448,7 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_reset_gpio = of_get_named_gpio(np,
"svc,reset-gpio",
0);
-   if (arche_pdata->svc_reset_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_reset_gpio)) {
dev_err(dev, "failed to get reset-gpio\n");
return arche_pdata->svc_reset_gpio;

I'm sorry, but I don't this change is desirable. of_get_named_gpio()
returns a valid gpio number or a negative errno, so there's no need to
use the legacy gpio_is_valid() helper here.

If you grep for of_get_named_gpio() you'll find that some drivers indeed
use that helper this way, but they are in a clear minority.

And ultimately, we want to move to using gpio descriptors anyway.


We need to check gpio validity. If we are using of_get_named_gpio() or not.
of_get_name_gpio() will read a device node and fetch the value. But 
it'll not

check that gpio is valid or not valid.



}
@@ -468,7 +468,7 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_sysboot_gpio = of_get_named_gpio(np,
  "svc,sysboot-gpio",
  0);
-   if (arche_pdata->svc_sysboot_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_sysboot_gpio)) {
dev_err(dev, "failed to get sysboot gpio\n");
return arche_pdata->svc_sysboot_gpio;
}
@@ -487,7 +487,7 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_refclk_req = of_get_named_gpio(np,
"svc,refclk-req-gpio",
0);
-   if (arche_pdata->svc_refclk_req < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_refclk_req)) {
dev_err(dev, "failed to get svc clock-req gpio\n");
return arche_pdata->svc_refclk_req;
}

But if this were to be changed, you'd need to update also the fourth
call to of_get_named_gpio() in this function.


Sorry, I missed it. Thanks for point out. I will add check for this.

~arvind


Thanks,
Johan




Re: [PATCH v2] staging: greybus: Use gpio_is_valid()

2018-05-02 Thread Arvind Yadav



On Wednesday 02 May 2018 02:13 PM, Johan Hovold wrote:

On Sat, Apr 28, 2018 at 10:05:39AM +0530, Arvind Yadav wrote:

Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav 
---
chnage in v2 :
  Returning invalid gpio as error instead of -ENODEV.

  drivers/staging/greybus/arche-platform.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/greybus/arche-platform.c 
b/drivers/staging/greybus/arche-platform.c
index 83254a7..c3a7da5 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -448,7 +448,7 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_reset_gpio = of_get_named_gpio(np,
"svc,reset-gpio",
0);
-   if (arche_pdata->svc_reset_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_reset_gpio)) {
dev_err(dev, "failed to get reset-gpio\n");
return arche_pdata->svc_reset_gpio;

I'm sorry, but I don't this change is desirable. of_get_named_gpio()
returns a valid gpio number or a negative errno, so there's no need to
use the legacy gpio_is_valid() helper here.

If you grep for of_get_named_gpio() you'll find that some drivers indeed
use that helper this way, but they are in a clear minority.

And ultimately, we want to move to using gpio descriptors anyway.


We need to check gpio validity. If we are using of_get_named_gpio() or not.
of_get_name_gpio() will read a device node and fetch the value. But 
it'll not

check that gpio is valid or not valid.



}
@@ -468,7 +468,7 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_sysboot_gpio = of_get_named_gpio(np,
  "svc,sysboot-gpio",
  0);
-   if (arche_pdata->svc_sysboot_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_sysboot_gpio)) {
dev_err(dev, "failed to get sysboot gpio\n");
return arche_pdata->svc_sysboot_gpio;
}
@@ -487,7 +487,7 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_refclk_req = of_get_named_gpio(np,
"svc,refclk-req-gpio",
0);
-   if (arche_pdata->svc_refclk_req < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_refclk_req)) {
dev_err(dev, "failed to get svc clock-req gpio\n");
return arche_pdata->svc_refclk_req;
}

But if this were to be changed, you'd need to update also the fourth
call to of_get_named_gpio() in this function.


Sorry, I missed it. Thanks for point out. I will add check for this.

~arvind


Thanks,
Johan




[PATCH v2] staging: greybus: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
chnage in v2 :
 Returning invalid gpio as error instead of -ENODEV.

 drivers/staging/greybus/arche-platform.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/greybus/arche-platform.c 
b/drivers/staging/greybus/arche-platform.c
index 83254a7..c3a7da5 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -448,7 +448,7 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_reset_gpio = of_get_named_gpio(np,
"svc,reset-gpio",
0);
-   if (arche_pdata->svc_reset_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_reset_gpio)) {
dev_err(dev, "failed to get reset-gpio\n");
return arche_pdata->svc_reset_gpio;
}
@@ -468,7 +468,7 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_sysboot_gpio = of_get_named_gpio(np,
  "svc,sysboot-gpio",
  0);
-   if (arche_pdata->svc_sysboot_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_sysboot_gpio)) {
dev_err(dev, "failed to get sysboot gpio\n");
return arche_pdata->svc_sysboot_gpio;
}
@@ -487,7 +487,7 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_refclk_req = of_get_named_gpio(np,
"svc,refclk-req-gpio",
0);
-   if (arche_pdata->svc_refclk_req < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_refclk_req)) {
dev_err(dev, "failed to get svc clock-req gpio\n");
return arche_pdata->svc_refclk_req;
}
-- 
2.7.4



[PATCH v2] staging: greybus: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav 
---
chnage in v2 :
 Returning invalid gpio as error instead of -ENODEV.

 drivers/staging/greybus/arche-platform.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/greybus/arche-platform.c 
b/drivers/staging/greybus/arche-platform.c
index 83254a7..c3a7da5 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -448,7 +448,7 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_reset_gpio = of_get_named_gpio(np,
"svc,reset-gpio",
0);
-   if (arche_pdata->svc_reset_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_reset_gpio)) {
dev_err(dev, "failed to get reset-gpio\n");
return arche_pdata->svc_reset_gpio;
}
@@ -468,7 +468,7 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_sysboot_gpio = of_get_named_gpio(np,
  "svc,sysboot-gpio",
  0);
-   if (arche_pdata->svc_sysboot_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_sysboot_gpio)) {
dev_err(dev, "failed to get sysboot gpio\n");
return arche_pdata->svc_sysboot_gpio;
}
@@ -487,7 +487,7 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_refclk_req = of_get_named_gpio(np,
"svc,refclk-req-gpio",
0);
-   if (arche_pdata->svc_refclk_req < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_refclk_req)) {
dev_err(dev, "failed to get svc clock-req gpio\n");
return arche_pdata->svc_refclk_req;
}
-- 
2.7.4



Re: [greybus-dev] [PATCH] staging: greybus: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav



On Friday 27 April 2018 05:47 PM, Alex Elder wrote:

On 04/27/2018 05:52 AM, Arvind Yadav wrote:

Replace the manual validity checks for the GPIO with the
gpio_is_valid().

I haven't looked through the code paths very closely, but I
think that get_named_gpio() might return -EPROBE_DEFER, which
would be something we want to pass to the caller.

Yes of_get_name_gpio() can return other error value apart from
-EPROBE_DEFER.

So rather than returning -ENODEV and hiding the reason the
call to of_get_named_gpio() failed, you should continue
returning the errno it supplies (if not a valid gpio number).

-Alex

I have return -ENODEV because invalid gpio pin can be positive.
static inline bool gpio_is_valid(int number)
{
return number >= 0 && number < ARCH_NR_GPIOS;
}
Here if number > ARCH_NR_GPIOS then it's invalid but return value
will be positive.

We can return like this
" return (gpio > 0) ? -ENODEV: gpio;"

But not sure this is worth to handle this.

~arvind



Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
  drivers/staging/greybus/arche-platform.c | 12 ++--
  1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/greybus/arche-platform.c 
b/drivers/staging/greybus/arche-platform.c
index 83254a7..fc6bf60 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -448,9 +448,9 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_reset_gpio = of_get_named_gpio(np,
"svc,reset-gpio",
0);
-   if (arche_pdata->svc_reset_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_reset_gpio)) {
dev_err(dev, "failed to get reset-gpio\n");
-   return arche_pdata->svc_reset_gpio;
+   return -ENODEV;
}
ret = devm_gpio_request(dev, arche_pdata->svc_reset_gpio, "svc-reset");
if (ret) {
@@ -468,9 +468,9 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_sysboot_gpio = of_get_named_gpio(np,
  "svc,sysboot-gpio",
  0);
-   if (arche_pdata->svc_sysboot_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_sysboot_gpio)) {
dev_err(dev, "failed to get sysboot gpio\n");
-   return arche_pdata->svc_sysboot_gpio;
+   return -ENODEV;
}
ret = devm_gpio_request(dev, arche_pdata->svc_sysboot_gpio, "sysboot0");
if (ret) {
@@ -487,9 +487,9 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_refclk_req = of_get_named_gpio(np,
"svc,refclk-req-gpio",
0);
-   if (arche_pdata->svc_refclk_req < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_refclk_req)) {
dev_err(dev, "failed to get svc clock-req gpio\n");
-   return arche_pdata->svc_refclk_req;
+   return -ENODEV;
}
ret = devm_gpio_request(dev, arche_pdata->svc_refclk_req,
"svc-clk-req");





Re: [greybus-dev] [PATCH] staging: greybus: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav



On Friday 27 April 2018 05:47 PM, Alex Elder wrote:

On 04/27/2018 05:52 AM, Arvind Yadav wrote:

Replace the manual validity checks for the GPIO with the
gpio_is_valid().

I haven't looked through the code paths very closely, but I
think that get_named_gpio() might return -EPROBE_DEFER, which
would be something we want to pass to the caller.

Yes of_get_name_gpio() can return other error value apart from
-EPROBE_DEFER.

So rather than returning -ENODEV and hiding the reason the
call to of_get_named_gpio() failed, you should continue
returning the errno it supplies (if not a valid gpio number).

-Alex

I have return -ENODEV because invalid gpio pin can be positive.
static inline bool gpio_is_valid(int number)
{
return number >= 0 && number < ARCH_NR_GPIOS;
}
Here if number > ARCH_NR_GPIOS then it's invalid but return value
will be positive.

We can return like this
" return (gpio > 0) ? -ENODEV: gpio;"

But not sure this is worth to handle this.

~arvind



Signed-off-by: Arvind Yadav 
---
  drivers/staging/greybus/arche-platform.c | 12 ++--
  1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/greybus/arche-platform.c 
b/drivers/staging/greybus/arche-platform.c
index 83254a7..fc6bf60 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -448,9 +448,9 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_reset_gpio = of_get_named_gpio(np,
"svc,reset-gpio",
0);
-   if (arche_pdata->svc_reset_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_reset_gpio)) {
dev_err(dev, "failed to get reset-gpio\n");
-   return arche_pdata->svc_reset_gpio;
+   return -ENODEV;
}
ret = devm_gpio_request(dev, arche_pdata->svc_reset_gpio, "svc-reset");
if (ret) {
@@ -468,9 +468,9 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_sysboot_gpio = of_get_named_gpio(np,
  "svc,sysboot-gpio",
  0);
-   if (arche_pdata->svc_sysboot_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_sysboot_gpio)) {
dev_err(dev, "failed to get sysboot gpio\n");
-   return arche_pdata->svc_sysboot_gpio;
+   return -ENODEV;
}
ret = devm_gpio_request(dev, arche_pdata->svc_sysboot_gpio, "sysboot0");
if (ret) {
@@ -487,9 +487,9 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_refclk_req = of_get_named_gpio(np,
"svc,refclk-req-gpio",
0);
-   if (arche_pdata->svc_refclk_req < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_refclk_req)) {
dev_err(dev, "failed to get svc clock-req gpio\n");
-   return arche_pdata->svc_refclk_req;
+   return -ENODEV;
}
ret = devm_gpio_request(dev, arche_pdata->svc_refclk_req,
"svc-clk-req");





[PATCH 0/2] Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Arvind Yadav (2):
  [PATCH 1/2] [media] platform: Use gpio_is_valid()
  [PATCH 2/2] [media] sta2x11: Use gpio_is_valid() and remove unnecessary check

 drivers/media/pci/sta2x11/sta2x11_vip.c | 31 +++
 drivers/media/platform/via-camera.c |  2 +-
 2 files changed, 16 insertions(+), 17 deletions(-)

-- 
1.9.1



[PATCH 0/2] Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Arvind Yadav (2):
  [PATCH 1/2] [media] platform: Use gpio_is_valid()
  [PATCH 2/2] [media] sta2x11: Use gpio_is_valid() and remove unnecessary check

 drivers/media/pci/sta2x11/sta2x11_vip.c | 31 +++
 drivers/media/platform/via-camera.c |  2 +-
 2 files changed, 16 insertions(+), 17 deletions(-)

-- 
1.9.1



[PATCH 1/2] [media] platform: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/media/platform/via-camera.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/via-camera.c 
b/drivers/media/platform/via-camera.c
index e9a0263..f01c3e8 100644
--- a/drivers/media/platform/via-camera.c
+++ b/drivers/media/platform/via-camera.c
@@ -178,7 +178,7 @@ static int via_sensor_power_setup(struct via_camera *cam)
 
cam->power_gpio = viafb_gpio_lookup("VGPIO3");
cam->reset_gpio = viafb_gpio_lookup("VGPIO2");
-   if (cam->power_gpio < 0 || cam->reset_gpio < 0) {
+   if (!gpio_is_valid(cam->power_gpio) || !gpio_is_valid(cam->reset_gpio)) 
{
dev_err(>platdev->dev, "Unable to find GPIO lines\n");
return -EINVAL;
}
-- 
1.9.1



[PATCH 1/2] [media] platform: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav 
---
 drivers/media/platform/via-camera.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/via-camera.c 
b/drivers/media/platform/via-camera.c
index e9a0263..f01c3e8 100644
--- a/drivers/media/platform/via-camera.c
+++ b/drivers/media/platform/via-camera.c
@@ -178,7 +178,7 @@ static int via_sensor_power_setup(struct via_camera *cam)
 
cam->power_gpio = viafb_gpio_lookup("VGPIO3");
cam->reset_gpio = viafb_gpio_lookup("VGPIO2");
-   if (cam->power_gpio < 0 || cam->reset_gpio < 0) {
+   if (!gpio_is_valid(cam->power_gpio) || !gpio_is_valid(cam->reset_gpio)) 
{
dev_err(>platdev->dev, "Unable to find GPIO lines\n");
return -EINVAL;
}
-- 
1.9.1



[PATCH 2/2] [media] sta2x11: Use gpio_is_valid() and remove unnecessary check

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

In vip_gpio_reserve(), Error checking for gpio pin is not correct.
If pwr_pin = -1, It will return 0. This should be return an error.

In sta2x11_vip_init_one(), Error checking for gpio 'reset_pin'
is unnecessary. Because vip_gpio_reserve() is also checking for
valid gpio pin. So removed extra error checking for gpio 'reset_pin'.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/media/pci/sta2x11/sta2x11_vip.c | 31 +++
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c 
b/drivers/media/pci/sta2x11/sta2x11_vip.c
index dd199bf..069c4a8 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -908,10 +908,10 @@ static int sta2x11_vip_init_controls(struct sta2x11_vip 
*vip)
 static int vip_gpio_reserve(struct device *dev, int pin, int dir,
const char *name)
 {
-   int ret;
+   int ret = -ENODEV;
 
-   if (pin == -1)
-   return 0;
+   if (!gpio_is_valid(pin))
+   return ret;
 
ret = gpio_request(pin, name);
if (ret) {
@@ -946,7 +946,7 @@ static int vip_gpio_reserve(struct device *dev, int pin, 
int dir,
  */
 static void vip_gpio_release(struct device *dev, int pin, const char *name)
 {
-   if (pin != -1) {
+   if (gpio_is_valid(pin)) {
dev_dbg(dev, "releasing pin %d (%s)\n", pin, name);
gpio_unexport(pin);
gpio_free(pin);
@@ -1003,25 +1003,24 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
if (ret)
goto disable;
 
-   if (config->reset_pin >= 0) {
-   ret = vip_gpio_reserve(>dev, config->reset_pin, 0,
-  config->reset_name);
-   if (ret) {
-   vip_gpio_release(>dev, config->pwr_pin,
-config->pwr_name);
-   goto disable;
-   }
+   ret = vip_gpio_reserve(>dev, config->reset_pin, 0,
+  config->reset_name);
+   if (ret) {
+   vip_gpio_release(>dev, config->pwr_pin,
+config->pwr_name);
+   goto disable;
}
-   if (config->pwr_pin != -1) {
+
+   if (gpio_is_valid(config->pwr_pin)) {
/* Datasheet says 5ms between PWR and RST */
usleep_range(5000, 25000);
-   ret = gpio_direction_output(config->pwr_pin, 1);
+   gpio_direction_output(config->pwr_pin, 1);
}
 
-   if (config->reset_pin != -1) {
+   if (gpio_is_valid(config->reset_pin)) {
/* Datasheet says 5ms between PWR and RST */
usleep_range(5000, 25000);
-   ret = gpio_direction_output(config->reset_pin, 1);
+   gpio_direction_output(config->reset_pin, 1);
}
usleep_range(5000, 25000);
 
-- 
1.9.1



[PATCH 2/2] [media] sta2x11: Use gpio_is_valid() and remove unnecessary check

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

In vip_gpio_reserve(), Error checking for gpio pin is not correct.
If pwr_pin = -1, It will return 0. This should be return an error.

In sta2x11_vip_init_one(), Error checking for gpio 'reset_pin'
is unnecessary. Because vip_gpio_reserve() is also checking for
valid gpio pin. So removed extra error checking for gpio 'reset_pin'.

Signed-off-by: Arvind Yadav 
---
 drivers/media/pci/sta2x11/sta2x11_vip.c | 31 +++
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c 
b/drivers/media/pci/sta2x11/sta2x11_vip.c
index dd199bf..069c4a8 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -908,10 +908,10 @@ static int sta2x11_vip_init_controls(struct sta2x11_vip 
*vip)
 static int vip_gpio_reserve(struct device *dev, int pin, int dir,
const char *name)
 {
-   int ret;
+   int ret = -ENODEV;
 
-   if (pin == -1)
-   return 0;
+   if (!gpio_is_valid(pin))
+   return ret;
 
ret = gpio_request(pin, name);
if (ret) {
@@ -946,7 +946,7 @@ static int vip_gpio_reserve(struct device *dev, int pin, 
int dir,
  */
 static void vip_gpio_release(struct device *dev, int pin, const char *name)
 {
-   if (pin != -1) {
+   if (gpio_is_valid(pin)) {
dev_dbg(dev, "releasing pin %d (%s)\n", pin, name);
gpio_unexport(pin);
gpio_free(pin);
@@ -1003,25 +1003,24 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
if (ret)
goto disable;
 
-   if (config->reset_pin >= 0) {
-   ret = vip_gpio_reserve(>dev, config->reset_pin, 0,
-  config->reset_name);
-   if (ret) {
-   vip_gpio_release(>dev, config->pwr_pin,
-config->pwr_name);
-   goto disable;
-   }
+   ret = vip_gpio_reserve(>dev, config->reset_pin, 0,
+  config->reset_name);
+   if (ret) {
+   vip_gpio_release(>dev, config->pwr_pin,
+config->pwr_name);
+   goto disable;
}
-   if (config->pwr_pin != -1) {
+
+   if (gpio_is_valid(config->pwr_pin)) {
/* Datasheet says 5ms between PWR and RST */
usleep_range(5000, 25000);
-   ret = gpio_direction_output(config->pwr_pin, 1);
+   gpio_direction_output(config->pwr_pin, 1);
}
 
-   if (config->reset_pin != -1) {
+   if (gpio_is_valid(config->reset_pin)) {
/* Datasheet says 5ms between PWR and RST */
usleep_range(5000, 25000);
-   ret = gpio_direction_output(config->reset_pin, 1);
+   gpio_direction_output(config->reset_pin, 1);
}
usleep_range(5000, 25000);
 
-- 
1.9.1



[PATCH] spi: mpc52xx: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/spi/spi-mpc52xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-mpc52xx.c b/drivers/spi/spi-mpc52xx.c
index e8b59ce..0e55784 100644
--- a/drivers/spi/spi-mpc52xx.c
+++ b/drivers/spi/spi-mpc52xx.c
@@ -447,7 +447,7 @@ static int mpc52xx_spi_probe(struct platform_device *op)
 
for (i = 0; i < ms->gpio_cs_count; i++) {
gpio_cs = of_get_gpio(op->dev.of_node, i);
-   if (gpio_cs < 0) {
+   if (!gpio_is_valid(gpio_cs)) {
dev_err(>dev,
"could not parse the gpio field in 
oftree\n");
rc = -ENODEV;
-- 
1.9.1



[PATCH] spi: mpc52xx: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav 
---
 drivers/spi/spi-mpc52xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-mpc52xx.c b/drivers/spi/spi-mpc52xx.c
index e8b59ce..0e55784 100644
--- a/drivers/spi/spi-mpc52xx.c
+++ b/drivers/spi/spi-mpc52xx.c
@@ -447,7 +447,7 @@ static int mpc52xx_spi_probe(struct platform_device *op)
 
for (i = 0; i < ms->gpio_cs_count; i++) {
gpio_cs = of_get_gpio(op->dev.of_node, i);
-   if (gpio_cs < 0) {
+   if (!gpio_is_valid(gpio_cs)) {
dev_err(>dev,
"could not parse the gpio field in 
oftree\n");
rc = -ENODEV;
-- 
1.9.1



[PATCH] staging: greybus: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/staging/greybus/arche-platform.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/greybus/arche-platform.c 
b/drivers/staging/greybus/arche-platform.c
index 83254a7..fc6bf60 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -448,9 +448,9 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_reset_gpio = of_get_named_gpio(np,
"svc,reset-gpio",
0);
-   if (arche_pdata->svc_reset_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_reset_gpio)) {
dev_err(dev, "failed to get reset-gpio\n");
-   return arche_pdata->svc_reset_gpio;
+   return -ENODEV;
}
ret = devm_gpio_request(dev, arche_pdata->svc_reset_gpio, "svc-reset");
if (ret) {
@@ -468,9 +468,9 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_sysboot_gpio = of_get_named_gpio(np,
  "svc,sysboot-gpio",
  0);
-   if (arche_pdata->svc_sysboot_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_sysboot_gpio)) {
dev_err(dev, "failed to get sysboot gpio\n");
-   return arche_pdata->svc_sysboot_gpio;
+   return -ENODEV;
}
ret = devm_gpio_request(dev, arche_pdata->svc_sysboot_gpio, "sysboot0");
if (ret) {
@@ -487,9 +487,9 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_refclk_req = of_get_named_gpio(np,
"svc,refclk-req-gpio",
0);
-   if (arche_pdata->svc_refclk_req < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_refclk_req)) {
dev_err(dev, "failed to get svc clock-req gpio\n");
-   return arche_pdata->svc_refclk_req;
+   return -ENODEV;
}
ret = devm_gpio_request(dev, arche_pdata->svc_refclk_req,
"svc-clk-req");
-- 
1.9.1



[PATCH] staging: greybus: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav 
---
 drivers/staging/greybus/arche-platform.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/greybus/arche-platform.c 
b/drivers/staging/greybus/arche-platform.c
index 83254a7..fc6bf60 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -448,9 +448,9 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_reset_gpio = of_get_named_gpio(np,
"svc,reset-gpio",
0);
-   if (arche_pdata->svc_reset_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_reset_gpio)) {
dev_err(dev, "failed to get reset-gpio\n");
-   return arche_pdata->svc_reset_gpio;
+   return -ENODEV;
}
ret = devm_gpio_request(dev, arche_pdata->svc_reset_gpio, "svc-reset");
if (ret) {
@@ -468,9 +468,9 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_sysboot_gpio = of_get_named_gpio(np,
  "svc,sysboot-gpio",
  0);
-   if (arche_pdata->svc_sysboot_gpio < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_sysboot_gpio)) {
dev_err(dev, "failed to get sysboot gpio\n");
-   return arche_pdata->svc_sysboot_gpio;
+   return -ENODEV;
}
ret = devm_gpio_request(dev, arche_pdata->svc_sysboot_gpio, "sysboot0");
if (ret) {
@@ -487,9 +487,9 @@ static int arche_platform_probe(struct platform_device 
*pdev)
arche_pdata->svc_refclk_req = of_get_named_gpio(np,
"svc,refclk-req-gpio",
0);
-   if (arche_pdata->svc_refclk_req < 0) {
+   if (!gpio_is_valid(arche_pdata->svc_refclk_req)) {
dev_err(dev, "failed to get svc clock-req gpio\n");
-   return arche_pdata->svc_refclk_req;
+   return -ENODEV;
}
ret = devm_gpio_request(dev, arche_pdata->svc_refclk_req,
"svc-clk-req");
-- 
1.9.1



[PATCH 2/3] ASoC: tpa6130a2: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 sound/soc/codecs/tpa6130a2.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c
index 616cd4b..18f32b9 100644
--- a/sound/soc/codecs/tpa6130a2.c
+++ b/sound/soc/codecs/tpa6130a2.c
@@ -62,7 +62,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool 
enable)
return ret;
}
/* Power on */
-   if (data->power_gpio >= 0)
+   if (gpio_is_valid(data->power_gpio))
gpio_set_value(data->power_gpio, 1);
 
/* Sync registers */
@@ -72,7 +72,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool 
enable)
dev_err(data->dev,
"Failed to sync registers: %d\n", ret);
regcache_cache_only(data->regmap, true);
-   if (data->power_gpio >= 0)
+   if (gpio_is_valid(data->power_gpio))
gpio_set_value(data->power_gpio, 0);
ret2 = regulator_disable(data->supply);
if (ret2 != 0)
@@ -89,7 +89,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool 
enable)
regcache_cache_only(data->regmap, true);
 
/* Power off */
-   if (data->power_gpio >= 0)
+   if (gpio_is_valid(data->power_gpio))
gpio_set_value(data->power_gpio, 0);
 
ret = regulator_disable(data->supply);
@@ -259,7 +259,7 @@ static int tpa6130a2_probe(struct i2c_client *client,
 
data->id = id->driver_data;
 
-   if (data->power_gpio >= 0) {
+   if (gpio_is_valid(data->power_gpio)) {
ret = devm_gpio_request(dev, data->power_gpio,
"tpa6130a2 enable");
if (ret < 0) {
-- 
1.9.1



[PATCH 2/3] ASoC: tpa6130a2: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav 
---
 sound/soc/codecs/tpa6130a2.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c
index 616cd4b..18f32b9 100644
--- a/sound/soc/codecs/tpa6130a2.c
+++ b/sound/soc/codecs/tpa6130a2.c
@@ -62,7 +62,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool 
enable)
return ret;
}
/* Power on */
-   if (data->power_gpio >= 0)
+   if (gpio_is_valid(data->power_gpio))
gpio_set_value(data->power_gpio, 1);
 
/* Sync registers */
@@ -72,7 +72,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool 
enable)
dev_err(data->dev,
"Failed to sync registers: %d\n", ret);
regcache_cache_only(data->regmap, true);
-   if (data->power_gpio >= 0)
+   if (gpio_is_valid(data->power_gpio))
gpio_set_value(data->power_gpio, 0);
ret2 = regulator_disable(data->supply);
if (ret2 != 0)
@@ -89,7 +89,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool 
enable)
regcache_cache_only(data->regmap, true);
 
/* Power off */
-   if (data->power_gpio >= 0)
+   if (gpio_is_valid(data->power_gpio))
gpio_set_value(data->power_gpio, 0);
 
ret = regulator_disable(data->supply);
@@ -259,7 +259,7 @@ static int tpa6130a2_probe(struct i2c_client *client,
 
data->id = id->driver_data;
 
-   if (data->power_gpio >= 0) {
+   if (gpio_is_valid(data->power_gpio)) {
ret = devm_gpio_request(dev, data->power_gpio,
"tpa6130a2 enable");
if (ret < 0) {
-- 
1.9.1



[PATCH 1/3] ASoC: tlv320dac33: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 sound/soc/codecs/tlv320dac33.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index a957eae..c23b9db 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -397,13 +397,13 @@ static int dac33_hard_power(struct snd_soc_component 
*component, int power)
goto exit;
}
 
-   if (dac33->power_gpio >= 0)
+   if (gpio_is_valid(dac33->power_gpio))
gpio_set_value(dac33->power_gpio, 1);
 
dac33->chip_power = 1;
} else {
dac33_soft_power(component, 0);
-   if (dac33->power_gpio >= 0)
+   if (gpio_is_valid(dac33->power_gpio))
gpio_set_value(dac33->power_gpio, 0);
 
ret = regulator_bulk_disable(ARRAY_SIZE(dac33->supplies),
@@ -1519,7 +1519,7 @@ static int dac33_i2c_probe(struct i2c_client *client,
dac33->fifo_mode = DAC33_FIFO_BYPASS;
 
/* Check if the reset GPIO number is valid and request it */
-   if (dac33->power_gpio >= 0) {
+   if (gpio_is_valid(dac33->power_gpio)) {
ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset");
if (ret < 0) {
dev_err(>dev,
@@ -1548,7 +1548,7 @@ static int dac33_i2c_probe(struct i2c_client *client,
 
return ret;
 err_get:
-   if (dac33->power_gpio >= 0)
+   if (gpio_is_valid(dac33->power_gpio))
gpio_free(dac33->power_gpio);
 err_gpio:
return ret;
@@ -1561,7 +1561,7 @@ static int dac33_i2c_remove(struct i2c_client *client)
if (unlikely(dac33->chip_power))
dac33_hard_power(dac33->component, 0);
 
-   if (dac33->power_gpio >= 0)
+   if (gpio_is_valid(dac33->power_gpio))
gpio_free(dac33->power_gpio);
 
return 0;
-- 
1.9.1



[PATCH 1/3] ASoC: tlv320dac33: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav 
---
 sound/soc/codecs/tlv320dac33.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index a957eae..c23b9db 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -397,13 +397,13 @@ static int dac33_hard_power(struct snd_soc_component 
*component, int power)
goto exit;
}
 
-   if (dac33->power_gpio >= 0)
+   if (gpio_is_valid(dac33->power_gpio))
gpio_set_value(dac33->power_gpio, 1);
 
dac33->chip_power = 1;
} else {
dac33_soft_power(component, 0);
-   if (dac33->power_gpio >= 0)
+   if (gpio_is_valid(dac33->power_gpio))
gpio_set_value(dac33->power_gpio, 0);
 
ret = regulator_bulk_disable(ARRAY_SIZE(dac33->supplies),
@@ -1519,7 +1519,7 @@ static int dac33_i2c_probe(struct i2c_client *client,
dac33->fifo_mode = DAC33_FIFO_BYPASS;
 
/* Check if the reset GPIO number is valid and request it */
-   if (dac33->power_gpio >= 0) {
+   if (gpio_is_valid(dac33->power_gpio)) {
ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset");
if (ret < 0) {
dev_err(>dev,
@@ -1548,7 +1548,7 @@ static int dac33_i2c_probe(struct i2c_client *client,
 
return ret;
 err_get:
-   if (dac33->power_gpio >= 0)
+   if (gpio_is_valid(dac33->power_gpio))
gpio_free(dac33->power_gpio);
 err_gpio:
return ret;
@@ -1561,7 +1561,7 @@ static int dac33_i2c_remove(struct i2c_client *client)
if (unlikely(dac33->chip_power))
dac33_hard_power(dac33->component, 0);
 
-   if (dac33->power_gpio >= 0)
+   if (gpio_is_valid(dac33->power_gpio))
gpio_free(dac33->power_gpio);
 
return 0;
-- 
1.9.1



[PATCH 3/3] ASoC: samsung: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 sound/soc/samsung/s3c24xx_simtec.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sound/soc/samsung/s3c24xx_simtec.c 
b/sound/soc/samsung/s3c24xx_simtec.c
index 6de63f3..23e8ef9d 100644
--- a/sound/soc/samsung/s3c24xx_simtec.c
+++ b/sound/soc/samsung/s3c24xx_simtec.c
@@ -229,7 +229,7 @@ static int attach_gpio_amp(struct device *dev,
int ret;
 
/* attach gpio amp gain (if any) */
-   if (pdata->amp_gain[0] > 0) {
+   if (gpio_is_valid(pdata->amp_gain[0])) {
ret = gpio_request(pd->amp_gain[0], "gpio-amp-gain0");
if (ret) {
dev_err(dev, "cannot get amp gpio gain0\n");
@@ -248,7 +248,7 @@ static int attach_gpio_amp(struct device *dev,
}
 
/* note, currently we assume GPA0 isn't valid amp */
-   if (pdata->amp_gpio > 0) {
+   if (gpio_is_valid(pdata->amp_gpio)) {
ret = gpio_request(pd->amp_gpio, "gpio-amp");
if (ret) {
dev_err(dev, "cannot get amp gpio %d (%d)\n",
@@ -263,7 +263,7 @@ static int attach_gpio_amp(struct device *dev,
return 0;
 
 err_amp:
-   if (pd->amp_gain[0] > 0) {
+   if (gpio_is_valid(pd->amp_gain[0])) {
gpio_free(pd->amp_gain[0]);
gpio_free(pd->amp_gain[1]);
}
@@ -273,12 +273,12 @@ static int attach_gpio_amp(struct device *dev,
 
 static void detach_gpio_amp(struct s3c24xx_audio_simtec_pdata *pd)
 {
-   if (pd->amp_gain[0] > 0) {
+   if (gpio_is_valid(pd->amp_gain[0])) {
gpio_free(pd->amp_gain[0]);
gpio_free(pd->amp_gain[1]);
}
 
-   if (pd->amp_gpio > 0)
+   if (gpio_is_valid(pd->amp_gpio))
gpio_free(pd->amp_gpio);
 }
 
-- 
1.9.1



[PATCH 3/3] ASoC: samsung: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav 
---
 sound/soc/samsung/s3c24xx_simtec.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sound/soc/samsung/s3c24xx_simtec.c 
b/sound/soc/samsung/s3c24xx_simtec.c
index 6de63f3..23e8ef9d 100644
--- a/sound/soc/samsung/s3c24xx_simtec.c
+++ b/sound/soc/samsung/s3c24xx_simtec.c
@@ -229,7 +229,7 @@ static int attach_gpio_amp(struct device *dev,
int ret;
 
/* attach gpio amp gain (if any) */
-   if (pdata->amp_gain[0] > 0) {
+   if (gpio_is_valid(pdata->amp_gain[0])) {
ret = gpio_request(pd->amp_gain[0], "gpio-amp-gain0");
if (ret) {
dev_err(dev, "cannot get amp gpio gain0\n");
@@ -248,7 +248,7 @@ static int attach_gpio_amp(struct device *dev,
}
 
/* note, currently we assume GPA0 isn't valid amp */
-   if (pdata->amp_gpio > 0) {
+   if (gpio_is_valid(pdata->amp_gpio)) {
ret = gpio_request(pd->amp_gpio, "gpio-amp");
if (ret) {
dev_err(dev, "cannot get amp gpio %d (%d)\n",
@@ -263,7 +263,7 @@ static int attach_gpio_amp(struct device *dev,
return 0;
 
 err_amp:
-   if (pd->amp_gain[0] > 0) {
+   if (gpio_is_valid(pd->amp_gain[0])) {
gpio_free(pd->amp_gain[0]);
gpio_free(pd->amp_gain[1]);
}
@@ -273,12 +273,12 @@ static int attach_gpio_amp(struct device *dev,
 
 static void detach_gpio_amp(struct s3c24xx_audio_simtec_pdata *pd)
 {
-   if (pd->amp_gain[0] > 0) {
+   if (gpio_is_valid(pd->amp_gain[0])) {
gpio_free(pd->amp_gain[0]);
gpio_free(pd->amp_gain[1]);
}
 
-   if (pd->amp_gpio > 0)
+   if (gpio_is_valid(pd->amp_gpio))
gpio_free(pd->amp_gpio);
 }
 
-- 
1.9.1



[PATCH 0/3] ASoC: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Arvind Yadav (3):
  [PATCH 1/3] ASoC: tlv320dac33: Use gpio_is_valid()
  [PATCH 2/3] ASoC: tpa6130a2: Use gpio_is_valid()
  [PATCH 3/3] ASoC: samsung: Use gpio_is_valid()

 sound/soc/codecs/tlv320dac33.c | 10 +-
 sound/soc/codecs/tpa6130a2.c   |  8 
 sound/soc/samsung/s3c24xx_simtec.c | 10 +-
 3 files changed, 14 insertions(+), 14 deletions(-)

-- 
1.9.1



[PATCH 0/3] ASoC: Use gpio_is_valid()

2018-04-27 Thread Arvind Yadav
Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Arvind Yadav (3):
  [PATCH 1/3] ASoC: tlv320dac33: Use gpio_is_valid()
  [PATCH 2/3] ASoC: tpa6130a2: Use gpio_is_valid()
  [PATCH 3/3] ASoC: samsung: Use gpio_is_valid()

 sound/soc/codecs/tlv320dac33.c | 10 +-
 sound/soc/codecs/tpa6130a2.c   |  8 
 sound/soc/samsung/s3c24xx_simtec.c | 10 +-
 3 files changed, 14 insertions(+), 14 deletions(-)

-- 
1.9.1



[PATCH] mm: memory_hotplug: use put_device() if device_register fail

2018-04-26 Thread Arvind Yadav
if device_register() returned an error. Always use put_device()
to give up the initialized reference and release allocated memory.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/base/memory.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index bffe861..f5e5601 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -649,13 +649,19 @@ static const struct attribute_group 
*memory_memblk_attr_groups[] = {
 static
 int register_memory(struct memory_block *memory)
 {
+   int ret;
+
memory->dev.bus = _subsys;
memory->dev.id = memory->start_section_nr / sections_per_block;
memory->dev.release = memory_block_release;
memory->dev.groups = memory_memblk_attr_groups;
memory->dev.offline = memory->state == MEM_OFFLINE;
 
-   return device_register(>dev);
+   ret = device_register(>dev);
+   if (ret)
+   put_device(>dev);
+
+   return ret;
 }
 
 static int init_memory_block(struct memory_block **memory,
-- 
2.7.4



[PATCH] mm: memory_hotplug: use put_device() if device_register fail

2018-04-26 Thread Arvind Yadav
if device_register() returned an error. Always use put_device()
to give up the initialized reference and release allocated memory.

Signed-off-by: Arvind Yadav 
---
 drivers/base/memory.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index bffe861..f5e5601 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -649,13 +649,19 @@ static const struct attribute_group 
*memory_memblk_attr_groups[] = {
 static
 int register_memory(struct memory_block *memory)
 {
+   int ret;
+
memory->dev.bus = _subsys;
memory->dev.id = memory->start_section_nr / sections_per_block;
memory->dev.release = memory_block_release;
memory->dev.groups = memory_memblk_attr_groups;
memory->dev.offline = memory->state == MEM_OFFLINE;
 
-   return device_register(>dev);
+   ret = device_register(>dev);
+   if (ret)
+   put_device(>dev);
+
+   return ret;
 }
 
 static int init_memory_block(struct memory_block **memory,
-- 
2.7.4



[PATCH] sparc: vio: use put_device() instead of kfree()

2018-04-25 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error. Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 arch/sparc/kernel/vio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sparc/kernel/vio.c b/arch/sparc/kernel/vio.c
index 1a0fa10..32bae68 100644
--- a/arch/sparc/kernel/vio.c
+++ b/arch/sparc/kernel/vio.c
@@ -403,7 +403,7 @@ static struct vio_dev *vio_create_one(struct mdesc_handle 
*hp, u64 mp,
if (err) {
printk(KERN_ERR "VIO: Could not register device %s, err=%d\n",
   dev_name(>dev), err);
-   kfree(vdev);
+   put_device(>dev);
return NULL;
}
if (vdev->dp)
-- 
2.7.4



[PATCH] sparc: vio: use put_device() instead of kfree()

2018-04-25 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error. Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav 
---
 arch/sparc/kernel/vio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sparc/kernel/vio.c b/arch/sparc/kernel/vio.c
index 1a0fa10..32bae68 100644
--- a/arch/sparc/kernel/vio.c
+++ b/arch/sparc/kernel/vio.c
@@ -403,7 +403,7 @@ static struct vio_dev *vio_create_one(struct mdesc_handle 
*hp, u64 mp,
if (err) {
printk(KERN_ERR "VIO: Could not register device %s, err=%d\n",
   dev_name(>dev), err);
-   kfree(vdev);
+   put_device(>dev);
return NULL;
}
if (vdev->dp)
-- 
2.7.4



[PATCH] IA64: tiocx: use put_device() instead of kfree()

2018-04-25 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error. Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 arch/ia64/sn/kernel/tiocx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/ia64/sn/kernel/tiocx.c b/arch/ia64/sn/kernel/tiocx.c
index 32d0380..fd515bc 100644
--- a/arch/ia64/sn/kernel/tiocx.c
+++ b/arch/ia64/sn/kernel/tiocx.c
@@ -209,7 +209,7 @@ cx_device_register(nasid_t nasid, int part_num, int mfg_num,
dev_set_name(_dev->dev, "%d", cx_dev->cx_id.nasid);
r = device_register(_dev->dev);
if (r) {
-   kfree(cx_dev);
+   put_device(_dev->dev);
return r;
}
get_device(_dev->dev);
-- 
2.7.4



[PATCH] IA64: tiocx: use put_device() instead of kfree()

2018-04-25 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error. Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav 
---
 arch/ia64/sn/kernel/tiocx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/ia64/sn/kernel/tiocx.c b/arch/ia64/sn/kernel/tiocx.c
index 32d0380..fd515bc 100644
--- a/arch/ia64/sn/kernel/tiocx.c
+++ b/arch/ia64/sn/kernel/tiocx.c
@@ -209,7 +209,7 @@ cx_device_register(nasid_t nasid, int part_num, int mfg_num,
dev_set_name(_dev->dev, "%d", cx_dev->cx_id.nasid);
r = device_register(_dev->dev);
if (r) {
-   kfree(cx_dev);
+   put_device(_dev->dev);
return r;
}
get_device(_dev->dev);
-- 
2.7.4



[PATCH] ARM: locomo: use put_device() instead of kfree()

2018-04-25 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error. Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 arch/arm/common/locomo.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/arm/common/locomo.c b/arch/arm/common/locomo.c
index 51936bd..23a5079 100644
--- a/arch/arm/common/locomo.c
+++ b/arch/arm/common/locomo.c
@@ -226,8 +226,7 @@ locomo_init_one_child(struct locomo *lchip, struct 
locomo_dev_info *info)
 
dev = kzalloc(sizeof(struct locomo_dev), GFP_KERNEL);
if (!dev) {
-   ret = -ENOMEM;
-   goto out;
+   return -ENOMEM;
}
 
/*
@@ -256,10 +255,9 @@ locomo_init_one_child(struct locomo *lchip, struct 
locomo_dev_info *info)
NO_IRQ : lchip->irq_base + info->irq[0];
 
ret = device_register(>dev);
-   if (ret) {
- out:
-   kfree(dev);
-   }
+   if (ret)
+   put_device(>dev);
+
return ret;
 }
 
-- 
2.7.4



[PATCH] ARM: locomo: use put_device() instead of kfree()

2018-04-25 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error. Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav 
---
 arch/arm/common/locomo.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/arm/common/locomo.c b/arch/arm/common/locomo.c
index 51936bd..23a5079 100644
--- a/arch/arm/common/locomo.c
+++ b/arch/arm/common/locomo.c
@@ -226,8 +226,7 @@ locomo_init_one_child(struct locomo *lchip, struct 
locomo_dev_info *info)
 
dev = kzalloc(sizeof(struct locomo_dev), GFP_KERNEL);
if (!dev) {
-   ret = -ENOMEM;
-   goto out;
+   return -ENOMEM;
}
 
/*
@@ -256,10 +255,9 @@ locomo_init_one_child(struct locomo *lchip, struct 
locomo_dev_info *info)
NO_IRQ : lchip->irq_base + info->irq[0];
 
ret = device_register(>dev);
-   if (ret) {
- out:
-   kfree(dev);
-   }
+   if (ret)
+   put_device(>dev);
+
return ret;
 }
 
-- 
2.7.4



[PATCH] HID: wacom: Release device resource data obtained by devres_alloc()

2018-04-24 Thread Arvind Yadav
Free device resource data, if __wacom_devm_sysfs_create_group
is not successful.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/hid/wacom_sys.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index b54ef1f..ee7a37e 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -1213,8 +1213,10 @@ static int __wacom_devm_sysfs_create_group(struct wacom 
*wacom,
devres->root = root;
 
error = sysfs_create_group(devres->root, group);
-   if (error)
+   if (error) {
+   devres_free(devres);
return error;
+   }
 
devres_add(>hdev->dev, devres);
 
-- 
1.9.1



[PATCH] HID: wacom: Release device resource data obtained by devres_alloc()

2018-04-24 Thread Arvind Yadav
Free device resource data, if __wacom_devm_sysfs_create_group
is not successful.

Signed-off-by: Arvind Yadav 
---
 drivers/hid/wacom_sys.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index b54ef1f..ee7a37e 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -1213,8 +1213,10 @@ static int __wacom_devm_sysfs_create_group(struct wacom 
*wacom,
devres->root = root;
 
error = sysfs_create_group(devres->root, group);
-   if (error)
+   if (error) {
+   devres_free(devres);
return error;
+   }
 
devres_add(>hdev->dev, devres);
 
-- 
1.9.1



[PATCH] PM / devfreq: use put_device() instead of kfree()

2018-03-30 Thread Arvind Yadav
Never directly free @dev after calling device_register() or
device_unregister(), even if device_register() returned an error.
Always use put_device() to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/devfreq/devfreq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index fe2af6a..a225b94 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -625,7 +625,8 @@ struct devfreq *devfreq_add_device(struct device *dev,
err = device_register(>dev);
if (err) {
mutex_unlock(>lock);
-   goto err_dev;
+   put_device(>dev);
+   goto err_out;
}
 
devfreq->trans_table =  devm_kzalloc(>dev,
@@ -671,6 +672,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
mutex_unlock(_list_lock);
 
device_unregister(>dev);
+   devfreq = NULL;
 err_dev:
if (devfreq)
kfree(devfreq);
-- 
2.7.4



[PATCH] PM / devfreq: use put_device() instead of kfree()

2018-03-30 Thread Arvind Yadav
Never directly free @dev after calling device_register() or
device_unregister(), even if device_register() returned an error.
Always use put_device() to give up the reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/devfreq/devfreq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index fe2af6a..a225b94 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -625,7 +625,8 @@ struct devfreq *devfreq_add_device(struct device *dev,
err = device_register(>dev);
if (err) {
mutex_unlock(>lock);
-   goto err_dev;
+   put_device(>dev);
+   goto err_out;
}
 
devfreq->trans_table =  devm_kzalloc(>dev,
@@ -671,6 +672,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
mutex_unlock(_list_lock);
 
device_unregister(>dev);
+   devfreq = NULL;
 err_dev:
if (devfreq)
kfree(devfreq);
-- 
2.7.4



[PATCH] hid: intel-ish-hid: use put_device() instead of kfree()

2018-03-30 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error. Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/hid/intel-ish-hid/ishtp/bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c 
b/drivers/hid/intel-ish-hid/ishtp/bus.c
index f272cdd..2623a56 100644
--- a/drivers/hid/intel-ish-hid/ishtp/bus.c
+++ b/drivers/hid/intel-ish-hid/ishtp/bus.c
@@ -418,7 +418,7 @@ static struct ishtp_cl_device *ishtp_bus_add_device(struct 
ishtp_device *dev,
list_del(>device_link);
spin_unlock_irqrestore(>device_list_lock, flags);
dev_err(dev->devc, "Failed to register ISHTP client device\n");
-   kfree(device);
+   put_device(>dev);
return NULL;
}
 
-- 
2.7.4



[PATCH] hid: intel-ish-hid: use put_device() instead of kfree()

2018-03-30 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error. Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/hid/intel-ish-hid/ishtp/bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c 
b/drivers/hid/intel-ish-hid/ishtp/bus.c
index f272cdd..2623a56 100644
--- a/drivers/hid/intel-ish-hid/ishtp/bus.c
+++ b/drivers/hid/intel-ish-hid/ishtp/bus.c
@@ -418,7 +418,7 @@ static struct ishtp_cl_device *ishtp_bus_add_device(struct 
ishtp_device *dev,
list_del(>device_link);
spin_unlock_irqrestore(>device_list_lock, flags);
dev_err(dev->devc, "Failed to register ISHTP client device\n");
-   kfree(device);
+   put_device(>dev);
return NULL;
}
 
-- 
2.7.4



[RFT] media: hdpvr: Fix Double kfree() error

2018-03-20 Thread Arvind Yadav
Here, double-free is happening on error path of hdpvr_probe.

error_v4l2_unregister:
  v4l2_device_unregister(>v4l2_dev);
   =>
v4l2_device_disconnect
=>
 put_device
 =>
  kobject_put
  =>
   kref_put
   =>
v4l2_device_release
=>
 hdpvr_device_release (CALLBACK)
 =>
 kfree(dev)

error_free_dev:
   kfree(dev)

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
reported by:
   Dan Carpenter<dan.carpen...@oracle.com>

 drivers/media/usb/hdpvr/hdpvr-core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c 
b/drivers/media/usb/hdpvr/hdpvr-core.c
index 29ac7fc..cab100a0 100644
--- a/drivers/media/usb/hdpvr/hdpvr-core.c
+++ b/drivers/media/usb/hdpvr/hdpvr-core.c
@@ -395,6 +395,7 @@ static int hdpvr_probe(struct usb_interface *interface,
kfree(dev->usbc_buf);
 error_v4l2_unregister:
v4l2_device_unregister(>v4l2_dev);
+   dev = NULL;
 error_free_dev:
kfree(dev);
 error:
-- 
1.9.1



[RFT] media: hdpvr: Fix Double kfree() error

2018-03-20 Thread Arvind Yadav
Here, double-free is happening on error path of hdpvr_probe.

error_v4l2_unregister:
  v4l2_device_unregister(>v4l2_dev);
   =>
v4l2_device_disconnect
=>
 put_device
 =>
  kobject_put
  =>
   kref_put
   =>
v4l2_device_release
=>
 hdpvr_device_release (CALLBACK)
 =>
 kfree(dev)

error_free_dev:
   kfree(dev)

Signed-off-by: Arvind Yadav 
---
reported by:
   Dan Carpenter

 drivers/media/usb/hdpvr/hdpvr-core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c 
b/drivers/media/usb/hdpvr/hdpvr-core.c
index 29ac7fc..cab100a0 100644
--- a/drivers/media/usb/hdpvr/hdpvr-core.c
+++ b/drivers/media/usb/hdpvr/hdpvr-core.c
@@ -395,6 +395,7 @@ static int hdpvr_probe(struct usb_interface *interface,
kfree(dev->usbc_buf);
 error_v4l2_unregister:
v4l2_device_unregister(>v4l2_dev);
+   dev = NULL;
 error_free_dev:
kfree(dev);
 error:
-- 
1.9.1



[PATCH] coresight: use put_device() instead of kfree()

2018-03-18 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error. Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/hwtracing/coresight/coresight.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index 389c4ba..132dfbc 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1026,8 +1026,10 @@ struct coresight_device *coresight_register(struct 
coresight_desc *desc)
dev_set_name(>dev, "%s", desc->pdata->name);
 
ret = device_register(>dev);
-   if (ret)
-   goto err_device_register;
+   if (ret) {
+   put_device(>dev);
+   goto err_kzalloc_csdev;
+   }
 
mutex_lock(_mutex);
 
@@ -1038,8 +1040,6 @@ struct coresight_device *coresight_register(struct 
coresight_desc *desc)
 
return csdev;
 
-err_device_register:
-   kfree(conns);
 err_kzalloc_conns:
kfree(refcnts);
 err_kzalloc_refcnts:
-- 
2.7.4



[PATCH] coresight: use put_device() instead of kfree()

2018-03-18 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error. Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/hwtracing/coresight/coresight.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index 389c4ba..132dfbc 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1026,8 +1026,10 @@ struct coresight_device *coresight_register(struct 
coresight_desc *desc)
dev_set_name(>dev, "%s", desc->pdata->name);
 
ret = device_register(>dev);
-   if (ret)
-   goto err_device_register;
+   if (ret) {
+   put_device(>dev);
+   goto err_kzalloc_csdev;
+   }
 
mutex_lock(_mutex);
 
@@ -1038,8 +1040,6 @@ struct coresight_device *coresight_register(struct 
coresight_desc *desc)
 
return csdev;
 
-err_device_register:
-   kfree(conns);
 err_kzalloc_conns:
kfree(refcnts);
 err_kzalloc_refcnts:
-- 
2.7.4



[PATCH] vmbus: use put_device() if device_register fail

2018-03-18 Thread Arvind Yadav
if device_register() returned an error. Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/hv/vmbus_drv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index bc65c4d..25da2f3 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1358,6 +1358,7 @@ int vmbus_device_register(struct hv_device 
*child_device_obj)
ret = device_register(_device_obj->device);
if (ret) {
pr_err("Unable to register child device\n");
+   put_device(_device_obj->device);
return ret;
}
 
-- 
2.7.4



[PATCH] vmbus: use put_device() if device_register fail

2018-03-18 Thread Arvind Yadav
if device_register() returned an error. Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/hv/vmbus_drv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index bc65c4d..25da2f3 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1358,6 +1358,7 @@ int vmbus_device_register(struct hv_device 
*child_device_obj)
ret = device_register(_device_obj->device);
if (ret) {
pr_err("Unable to register child device\n");
+   put_device(_device_obj->device);
return ret;
}
 
-- 
2.7.4



Re: [PATCH 2/2 v2] mtd: ubi: use put_device() if device_register fail

2018-03-15 Thread Arvind Yadav



On Thursday 15 March 2018 01:25 PM, Richard Weinberger wrote:

Am Donnerstag, 15. März 2018, 08:20:31 CET schrieb Arvind Yadav:

if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Like DaveM said, there is no need to shout and use "!".


I will fix this and send you update patch.
  

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
change in v2:
 Fix use-after-free bug. move put_device() after cdev_del().

  drivers/mtd/ubi/vmt.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 3fd8d7f..93c6163 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -610,6 +610,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct
ubi_volume *vol)

  out_cdev:
cdev_del(>cdev);
+   put_device(>dev);
return err;

The more I dig into device code, the more questions I have.
Why is cdev_del() not part of the release function?

Thanks,
//richard


Yes, It's should be a part release function.

~arvind


Re: [PATCH 2/2 v2] mtd: ubi: use put_device() if device_register fail

2018-03-15 Thread Arvind Yadav



On Thursday 15 March 2018 01:25 PM, Richard Weinberger wrote:

Am Donnerstag, 15. März 2018, 08:20:31 CET schrieb Arvind Yadav:

if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Like DaveM said, there is no need to shout and use "!".


I will fix this and send you update patch.
  

Signed-off-by: Arvind Yadav 
---
change in v2:
 Fix use-after-free bug. move put_device() after cdev_del().

  drivers/mtd/ubi/vmt.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 3fd8d7f..93c6163 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -610,6 +610,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct
ubi_volume *vol)

  out_cdev:
cdev_del(>cdev);
+   put_device(>dev);
return err;

The more I dig into device code, the more questions I have.
Why is cdev_del() not part of the release function?

Thanks,
//richard


Yes, It's should be a part release function.

~arvind


[PATCH 2/2 v2] mtd: ubi: use put_device() if device_register fail

2018-03-15 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
change in v2:
Fix use-after-free bug. move put_device() after cdev_del().

 drivers/mtd/ubi/vmt.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 3fd8d7f..93c6163 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -610,6 +610,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct 
ubi_volume *vol)
 
 out_cdev:
cdev_del(>cdev);
+   put_device(>dev);
return err;
 }
 
-- 
1.9.1



[PATCH 2/2 v2] mtd: ubi: use put_device() if device_register fail

2018-03-15 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav 
---
change in v2:
Fix use-after-free bug. move put_device() after cdev_del().

 drivers/mtd/ubi/vmt.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 3fd8d7f..93c6163 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -610,6 +610,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct 
ubi_volume *vol)
 
 out_cdev:
cdev_del(>cdev);
+   put_device(>dev);
return err;
 }
 
-- 
1.9.1



Re: [PATCH 2/2] mtd: ubi: use put_device() if device_register fail

2018-03-15 Thread Arvind Yadav



On Thursday 15 March 2018 12:55 AM, Richard Weinberger wrote:

Am Mittwoch, 14. März 2018, 19:56:52 CET schrieb Boris Brezillon:

On Fri,  9 Mar 2018 16:20:49 +0530

Arvind Yadav <arvind.yadav...@gmail.com> wrote:

if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---

  drivers/mtd/ubi/vmt.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 3fd8d7f..db85b68 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -609,6 +609,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct
ubi_volume *vol)>
return err;
  
  out_cdev:

+   put_device(>dev);

cdev_del(>cdev);

use-after-free bug here: put_device() has freed the vol obj, and you're
dereferencing the pointer just after that.

Thanks Boris, to point out this error.

eeek, thanks for looking at more context.
Arvind, while you are right that put_device() is missing, please double check
that freeing the devices is also correct.

Thanks,
//richard

Sorry for that. I will take care of this.

~arvind


Re: [PATCH 2/2] mtd: ubi: use put_device() if device_register fail

2018-03-15 Thread Arvind Yadav



On Thursday 15 March 2018 12:55 AM, Richard Weinberger wrote:

Am Mittwoch, 14. März 2018, 19:56:52 CET schrieb Boris Brezillon:

On Fri,  9 Mar 2018 16:20:49 +0530

Arvind Yadav  wrote:

if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav 
---

  drivers/mtd/ubi/vmt.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 3fd8d7f..db85b68 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -609,6 +609,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct
ubi_volume *vol)>
return err;
  
  out_cdev:

+   put_device(>dev);

cdev_del(>cdev);

use-after-free bug here: put_device() has freed the vol obj, and you're
dereferencing the pointer just after that.

Thanks Boris, to point out this error.

eeek, thanks for looking at more context.
Arvind, while you are right that put_device() is missing, please double check
that freeing the devices is also correct.

Thanks,
//richard

Sorry for that. I will take care of this.

~arvind


[PATCH 1/2] misc: mic: Release reference count and memory for VOP device

2018-03-12 Thread Arvind Yadav
Never directly free @dev after calling device_register(),
even if it returned an error! Always use put_device() to
give up the reference initialized.
Release allocated memory for vop device in vop_release_dev().

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/misc/mic/bus/vop_bus.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/mic/bus/vop_bus.c b/drivers/misc/mic/bus/vop_bus.c
index fd7f2a6..e5bb9c7 100644
--- a/drivers/misc/mic/bus/vop_bus.c
+++ b/drivers/misc/mic/bus/vop_bus.c
@@ -135,7 +135,9 @@ void vop_unregister_driver(struct vop_driver *driver)
 
 static void vop_release_dev(struct device *d)
 {
-   put_device(d);
+   struct vop_device *dev = dev_to_vop(d);
+
+   kfree(dev);
 }
 
 struct vop_device *
@@ -174,7 +176,7 @@ struct vop_device *
goto free_vdev;
return vdev;
 free_vdev:
-   kfree(vdev);
+   put_device(>dev);
return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(vop_register_device);
-- 
1.9.1



[PATCH 1/2] misc: mic: Release reference count and memory for VOP device

2018-03-12 Thread Arvind Yadav
Never directly free @dev after calling device_register(),
even if it returned an error! Always use put_device() to
give up the reference initialized.
Release allocated memory for vop device in vop_release_dev().

Signed-off-by: Arvind Yadav 
---
 drivers/misc/mic/bus/vop_bus.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/mic/bus/vop_bus.c b/drivers/misc/mic/bus/vop_bus.c
index fd7f2a6..e5bb9c7 100644
--- a/drivers/misc/mic/bus/vop_bus.c
+++ b/drivers/misc/mic/bus/vop_bus.c
@@ -135,7 +135,9 @@ void vop_unregister_driver(struct vop_driver *driver)
 
 static void vop_release_dev(struct device *d)
 {
-   put_device(d);
+   struct vop_device *dev = dev_to_vop(d);
+
+   kfree(dev);
 }
 
 struct vop_device *
@@ -174,7 +176,7 @@ struct vop_device *
goto free_vdev;
return vdev;
 free_vdev:
-   kfree(vdev);
+   put_device(>dev);
return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(vop_register_device);
-- 
1.9.1



[PATCH 2/2] misc: ocxl: use put_device() instead of device_unregister()

2018-03-12 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/misc/ocxl/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/ocxl/pci.c b/drivers/misc/ocxl/pci.c
index 0051d9e..21f4254 100644
--- a/drivers/misc/ocxl/pci.c
+++ b/drivers/misc/ocxl/pci.c
@@ -519,7 +519,7 @@ static struct ocxl_fn *init_function(struct pci_dev *dev)
rc = device_register(>dev);
if (rc) {
deconfigure_function(fn);
-   device_unregister(>dev);
+   put_device(>dev);
return ERR_PTR(rc);
}
return fn;
-- 
1.9.1



[PATCH 2/2] misc: ocxl: use put_device() instead of device_unregister()

2018-03-12 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/misc/ocxl/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/ocxl/pci.c b/drivers/misc/ocxl/pci.c
index 0051d9e..21f4254 100644
--- a/drivers/misc/ocxl/pci.c
+++ b/drivers/misc/ocxl/pci.c
@@ -519,7 +519,7 @@ static struct ocxl_fn *init_function(struct pci_dev *dev)
rc = device_register(>dev);
if (rc) {
deconfigure_function(fn);
-   device_unregister(>dev);
+   put_device(>dev);
return ERR_PTR(rc);
}
return fn;
-- 
1.9.1



[PATCH 0/2] misc: use put_device() instead of kfree()

2018-03-12 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Arvind Yadav (2):
  [PATCH 1/2] misc: mic: Release reference count and memory for VOP device
  [PATCH 2/2] misc: ocxl: use put_device() instead of device_unregister()

 drivers/misc/mic/bus/vop_bus.c | 6 --
 drivers/misc/ocxl/pci.c| 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

-- 
1.9.1



[PATCH 0/2] misc: use put_device() instead of kfree()

2018-03-12 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Arvind Yadav (2):
  [PATCH 1/2] misc: mic: Release reference count and memory for VOP device
  [PATCH 2/2] misc: ocxl: use put_device() instead of device_unregister()

 drivers/misc/mic/bus/vop_bus.c | 6 --
 drivers/misc/ocxl/pci.c| 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

-- 
1.9.1



Re: [PATCH 0/2] mtd: use put_device() if device_register fail

2018-03-11 Thread Arvind Yadav



On Monday 12 March 2018 01:05 AM, Richard Weinberger wrote:

Am Freitag, 9. März 2018, 11:50:47 CET schrieb Arvind Yadav:

if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Arvind Yadav (2):
   [PATCH 1/2] mtd: use put_device() if device_register fail
   [PATCH 2/2] mtd: ubi: use put_device() if device_register fail

Uhh, this is not obvious. Does device_register() really always return with a
reference held in all (error) cases?

Thanks,
//richard

if device_register() returned an error! Always use put_device()
to give up the reference initialized.(-- Please see the comment
for device_register() ). put_device() is able to handle those case
where it'll not return a reference.

~arvind


Re: [PATCH 0/2] mtd: use put_device() if device_register fail

2018-03-11 Thread Arvind Yadav



On Monday 12 March 2018 01:05 AM, Richard Weinberger wrote:

Am Freitag, 9. März 2018, 11:50:47 CET schrieb Arvind Yadav:

if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Arvind Yadav (2):
   [PATCH 1/2] mtd: use put_device() if device_register fail
   [PATCH 2/2] mtd: ubi: use put_device() if device_register fail

Uhh, this is not obvious. Does device_register() really always return with a
reference held in all (error) cases?

Thanks,
//richard

if device_register() returned an error! Always use put_device()
to give up the reference initialized.(-- Please see the comment
for device_register() ). put_device() is able to handle those case
where it'll not return a reference.

~arvind


[PATCH 0/4] driver core: use put_device() instead of kfree()

2018-03-10 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Arvind Yadav (4):
  [PATCH 1/4] base: soc: use put_device() instead of kfree()
  [PATCH 2/4] driver core: platform: use put_device() if device_register fail
  [PATCH 3/4] driver core: node: use put_device() if device_register fail
  [PATCH 4/4] driver core: cpu: use put_device() if device_register fail

 drivers/base/cpu.c  | 4 +++-
 drivers/base/node.c | 4 +++-
 drivers/base/platform.c | 4 +++-
 drivers/base/soc.c  | 2 ++
 4 files changed, 11 insertions(+), 3 deletions(-)

-- 
2.7.4



[PATCH 0/4] driver core: use put_device() instead of kfree()

2018-03-10 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Arvind Yadav (4):
  [PATCH 1/4] base: soc: use put_device() instead of kfree()
  [PATCH 2/4] driver core: platform: use put_device() if device_register fail
  [PATCH 3/4] driver core: node: use put_device() if device_register fail
  [PATCH 4/4] driver core: cpu: use put_device() if device_register fail

 drivers/base/cpu.c  | 4 +++-
 drivers/base/node.c | 4 +++-
 drivers/base/platform.c | 4 +++-
 drivers/base/soc.c  | 2 ++
 4 files changed, 11 insertions(+), 3 deletions(-)

-- 
2.7.4



[PATCH 1/4] base: soc: use put_device() instead of kfree()

2018-03-10 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/base/soc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 4e80f48..10b280f 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -150,6 +150,8 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
 
 out3:
ida_simple_remove(_ida, soc_dev->soc_dev_num);
+   put_device(_dev->dev);
+   soc_dev = NULL;
 out2:
kfree(soc_dev);
 out1:
-- 
2.7.4



[PATCH 4/4] driver core: cpu: use put_device() if device_register fail

2018-03-10 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/base/cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index d21a2d9..2da998b 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -382,8 +382,10 @@ int register_cpu(struct cpu *cpu, int num)
if (cpu->hotpluggable)
cpu->dev.groups = hotplugable_cpu_attr_groups;
error = device_register(>dev);
-   if (error)
+   if (error) {
+   put_device(>dev);
return error;
+   }
 
per_cpu(cpu_sys_devices, num) = >dev;
register_cpu_under_node(num, cpu_to_node(num));
-- 
2.7.4



[PATCH 3/4] driver core: node: use put_device() if device_register fail

2018-03-10 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/base/node.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/base/node.c b/drivers/base/node.c
index ee090ab..c5f81fc 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -315,7 +315,9 @@ static int register_node(struct node *node, int num)
node->dev.groups = node_dev_groups;
error = device_register(>dev);
 
-   if (!error){
+   if (error)
+   put_device(>dev);
+   else {
hugetlb_register_node(node);
 
compaction_register_node(node);
-- 
2.7.4



[PATCH 2/4] driver core: platform: use put_device() if device_register fail

2018-03-10 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/base/platform.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index f1bf7b3..8075ddc 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -1153,8 +1153,10 @@ int __init platform_bus_init(void)
early_platform_cleanup();
 
error = device_register(_bus);
-   if (error)
+   if (error) {
+   put_device(_bus);
return error;
+   }
error =  bus_register(_bus_type);
if (error)
device_unregister(_bus);
-- 
2.7.4



[PATCH 1/4] base: soc: use put_device() instead of kfree()

2018-03-10 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/base/soc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 4e80f48..10b280f 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -150,6 +150,8 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
 
 out3:
ida_simple_remove(_ida, soc_dev->soc_dev_num);
+   put_device(_dev->dev);
+   soc_dev = NULL;
 out2:
kfree(soc_dev);
 out1:
-- 
2.7.4



[PATCH 4/4] driver core: cpu: use put_device() if device_register fail

2018-03-10 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/base/cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index d21a2d9..2da998b 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -382,8 +382,10 @@ int register_cpu(struct cpu *cpu, int num)
if (cpu->hotpluggable)
cpu->dev.groups = hotplugable_cpu_attr_groups;
error = device_register(>dev);
-   if (error)
+   if (error) {
+   put_device(>dev);
return error;
+   }
 
per_cpu(cpu_sys_devices, num) = >dev;
register_cpu_under_node(num, cpu_to_node(num));
-- 
2.7.4



[PATCH 3/4] driver core: node: use put_device() if device_register fail

2018-03-10 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/base/node.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/base/node.c b/drivers/base/node.c
index ee090ab..c5f81fc 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -315,7 +315,9 @@ static int register_node(struct node *node, int num)
node->dev.groups = node_dev_groups;
error = device_register(>dev);
 
-   if (!error){
+   if (error)
+   put_device(>dev);
+   else {
hugetlb_register_node(node);
 
compaction_register_node(node);
-- 
2.7.4



[PATCH 2/4] driver core: platform: use put_device() if device_register fail

2018-03-10 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/base/platform.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index f1bf7b3..8075ddc 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -1153,8 +1153,10 @@ int __init platform_bus_init(void)
early_platform_cleanup();
 
error = device_register(_bus);
-   if (error)
+   if (error) {
+   put_device(_bus);
return error;
+   }
error =  bus_register(_bus_type);
if (error)
device_unregister(_bus);
-- 
2.7.4



[PATCH 2/2] mtd: ubi: use put_device() if device_register fail

2018-03-09 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/mtd/ubi/vmt.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 3fd8d7f..db85b68 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -609,6 +609,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct 
ubi_volume *vol)
return err;
 
 out_cdev:
+   put_device(>dev);
cdev_del(>cdev);
return err;
 }
-- 
1.9.1



[PATCH 2/2] mtd: ubi: use put_device() if device_register fail

2018-03-09 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/mtd/ubi/vmt.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 3fd8d7f..db85b68 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -609,6 +609,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct 
ubi_volume *vol)
return err;
 
 out_cdev:
+   put_device(>dev);
cdev_del(>cdev);
return err;
 }
-- 
1.9.1



[PATCH 1/2] mtd: use put_device() if device_register fail

2018-03-09 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/mtd/mtdcore.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 28553c8..4d77ca2 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -586,6 +586,7 @@ int add_mtd_device(struct mtd_info *mtd)
return 0;
 
 fail_added:
+   put_device(>dev);
of_node_put(mtd_get_of_node(mtd));
idr_remove(_idr, i);
 fail_locked:
-- 
1.9.1



[PATCH 1/2] mtd: use put_device() if device_register fail

2018-03-09 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/mtd/mtdcore.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 28553c8..4d77ca2 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -586,6 +586,7 @@ int add_mtd_device(struct mtd_info *mtd)
return 0;
 
 fail_added:
+   put_device(>dev);
of_node_put(mtd_get_of_node(mtd));
idr_remove(_idr, i);
 fail_locked:
-- 
1.9.1



[PATCH 0/2] mtd: use put_device() if device_register fail

2018-03-09 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Arvind Yadav (2):
  [PATCH 1/2] mtd: use put_device() if device_register fail
  [PATCH 2/2] mtd: ubi: use put_device() if device_register fail

 drivers/mtd/mtdcore.c | 1 +
 drivers/mtd/ubi/vmt.c | 1 +
 2 files changed, 2 insertions(+)

-- 
1.9.1



[PATCH 0/2] mtd: use put_device() if device_register fail

2018-03-09 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Arvind Yadav (2):
  [PATCH 1/2] mtd: use put_device() if device_register fail
  [PATCH 2/2] mtd: ubi: use put_device() if device_register fail

 drivers/mtd/mtdcore.c | 1 +
 drivers/mtd/ubi/vmt.c | 1 +
 2 files changed, 2 insertions(+)

-- 
1.9.1



[PATCH] net: hns: use put_device() if device_register fail

2018-03-09 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/net/ethernet/hisilicon/hns/hnae.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.c 
b/drivers/net/ethernet/hisilicon/hns/hnae.c
index a051e58..0cf5ceb 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.c
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.c
@@ -422,8 +422,10 @@ int hnae_ae_register(struct hnae_ae_dev *hdev, struct 
module *owner)
hdev->cls_dev.release = hnae_release;
(void)dev_set_name(>cls_dev, "hnae%d", hdev->id);
ret = device_register(>cls_dev);
-   if (ret)
+   if (ret) {
+   put_device(>cls_dev);
return ret;
+   }
 
__module_get(THIS_MODULE);
 
-- 
1.9.1



[PATCH] net: hns: use put_device() if device_register fail

2018-03-09 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/net/ethernet/hisilicon/hns/hnae.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.c 
b/drivers/net/ethernet/hisilicon/hns/hnae.c
index a051e58..0cf5ceb 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.c
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.c
@@ -422,8 +422,10 @@ int hnae_ae_register(struct hnae_ae_dev *hdev, struct 
module *owner)
hdev->cls_dev.release = hnae_release;
(void)dev_set_name(>cls_dev, "hnae%d", hdev->id);
ret = device_register(>cls_dev);
-   if (ret)
+   if (ret) {
+   put_device(>cls_dev);
return ret;
+   }
 
__module_get(THIS_MODULE);
 
-- 
1.9.1



[PATCH] ntb_transport: use put_device() instead of kfree()

2018-03-09 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/ntb/ntb_transport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 9878c48..8182a3a 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -393,7 +393,7 @@ int ntb_transport_register_client_dev(char *device_name)
 
rc = device_register(dev);
if (rc) {
-   kfree(client_dev);
+   put_device(dev);
goto err;
}
 
-- 
1.9.1



[PATCH] ntb_transport: use put_device() instead of kfree()

2018-03-09 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/ntb/ntb_transport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 9878c48..8182a3a 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -393,7 +393,7 @@ int ntb_transport_register_client_dev(char *device_name)
 
rc = device_register(dev);
if (rc) {
-   kfree(client_dev);
+   put_device(dev);
goto err;
}
 
-- 
1.9.1



[PATCH] pwm: sysfs: use put_device() instead of kfree()

2018-03-08 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/pwm/sysfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c
index 83f2b0b..7c71cdb 100644
--- a/drivers/pwm/sysfs.c
+++ b/drivers/pwm/sysfs.c
@@ -273,7 +273,8 @@ static int pwm_export_child(struct device *parent, struct 
pwm_device *pwm)
ret = device_register(>child);
if (ret) {
clear_bit(PWMF_EXPORTED, >flags);
-   kfree(export);
+   put_device(>child);
+   export = NULL;
return ret;
}
 
-- 
1.9.1



[PATCH] pwm: sysfs: use put_device() instead of kfree()

2018-03-08 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/pwm/sysfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c
index 83f2b0b..7c71cdb 100644
--- a/drivers/pwm/sysfs.c
+++ b/drivers/pwm/sysfs.c
@@ -273,7 +273,8 @@ static int pwm_export_child(struct device *parent, struct 
pwm_device *pwm)
ret = device_register(>child);
if (ret) {
clear_bit(PWMF_EXPORTED, >flags);
-   kfree(export);
+   put_device(>child);
+   export = NULL;
return ret;
}
 
-- 
1.9.1



[PATCH 0/2] rpmsg: use put_device() if device_register fail

2018-03-08 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized. unregister device for
other return error.


Arvind Yadav (2):
  [PATCH 1/2] rpmsg: glink: use put_device() if device_register fail
  [PATCH 2/2] rpmsg: smd: use put_device() if device_register fail

 drivers/rpmsg/qcom_glink_smem.c | 3 ++-
 drivers/rpmsg/qcom_smd.c| 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

-- 
1.9.1



[PATCH 0/2] rpmsg: use put_device() if device_register fail

2018-03-08 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized. unregister device for
other return error.


Arvind Yadav (2):
  [PATCH 1/2] rpmsg: glink: use put_device() if device_register fail
  [PATCH 2/2] rpmsg: smd: use put_device() if device_register fail

 drivers/rpmsg/qcom_glink_smem.c | 3 ++-
 drivers/rpmsg/qcom_smd.c| 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

-- 
1.9.1



[PATCH 1/2] rpmsg: glink: use put_device() if device_register fail

2018-03-08 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized. And unregister device for
other return error.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/rpmsg/qcom_glink_smem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/rpmsg/qcom_glink_smem.c b/drivers/rpmsg/qcom_glink_smem.c
index 892f2b9..3fa9d43 100644
--- a/drivers/rpmsg/qcom_glink_smem.c
+++ b/drivers/rpmsg/qcom_glink_smem.c
@@ -217,6 +217,7 @@ struct qcom_glink *qcom_glink_smem_register(struct device 
*parent,
ret = device_register(dev);
if (ret) {
pr_err("failed to register glink edge\n");
+   put_device(dev);
return ERR_PTR(ret);
}
 
@@ -299,7 +300,7 @@ struct qcom_glink *qcom_glink_smem_register(struct device 
*parent,
return glink;
 
 err_put_dev:
-   put_device(dev);
+   device_unregister(dev);
 
return ERR_PTR(ret);
 }
-- 
1.9.1



[PATCH 1/2] rpmsg: glink: use put_device() if device_register fail

2018-03-08 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized. And unregister device for
other return error.

Signed-off-by: Arvind Yadav 
---
 drivers/rpmsg/qcom_glink_smem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/rpmsg/qcom_glink_smem.c b/drivers/rpmsg/qcom_glink_smem.c
index 892f2b9..3fa9d43 100644
--- a/drivers/rpmsg/qcom_glink_smem.c
+++ b/drivers/rpmsg/qcom_glink_smem.c
@@ -217,6 +217,7 @@ struct qcom_glink *qcom_glink_smem_register(struct device 
*parent,
ret = device_register(dev);
if (ret) {
pr_err("failed to register glink edge\n");
+   put_device(dev);
return ERR_PTR(ret);
}
 
@@ -299,7 +300,7 @@ struct qcom_glink *qcom_glink_smem_register(struct device 
*parent,
return glink;
 
 err_put_dev:
-   put_device(dev);
+   device_unregister(dev);
 
return ERR_PTR(ret);
 }
-- 
1.9.1



[PATCH 2/2] rpmsg: smd: use put_device() if device_register fail

2018-03-08 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized. unregister device for
other return error.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/rpmsg/qcom_smd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/rpmsg/qcom_smd.c b/drivers/rpmsg/qcom_smd.c
index 92d0c6a..ff8101a 100644
--- a/drivers/rpmsg/qcom_smd.c
+++ b/drivers/rpmsg/qcom_smd.c
@@ -1408,6 +1408,7 @@ struct qcom_smd_edge *qcom_smd_register_edge(struct 
device *parent,
ret = device_register(>dev);
if (ret) {
pr_err("failed to register smd edge\n");
+   put_device(>dev);
return ERR_PTR(ret);
}
 
@@ -1428,7 +1429,7 @@ struct qcom_smd_edge *qcom_smd_register_edge(struct 
device *parent,
return edge;
 
 unregister_dev:
-   put_device(>dev);
+   device_unregister(>dev);
return ERR_PTR(ret);
 }
 EXPORT_SYMBOL(qcom_smd_register_edge);
-- 
1.9.1



[PATCH 2/2] rpmsg: smd: use put_device() if device_register fail

2018-03-08 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized. unregister device for
other return error.

Signed-off-by: Arvind Yadav 
---
 drivers/rpmsg/qcom_smd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/rpmsg/qcom_smd.c b/drivers/rpmsg/qcom_smd.c
index 92d0c6a..ff8101a 100644
--- a/drivers/rpmsg/qcom_smd.c
+++ b/drivers/rpmsg/qcom_smd.c
@@ -1408,6 +1408,7 @@ struct qcom_smd_edge *qcom_smd_register_edge(struct 
device *parent,
ret = device_register(>dev);
if (ret) {
pr_err("failed to register smd edge\n");
+   put_device(>dev);
return ERR_PTR(ret);
}
 
@@ -1428,7 +1429,7 @@ struct qcom_smd_edge *qcom_smd_register_edge(struct 
device *parent,
return edge;
 
 unregister_dev:
-   put_device(>dev);
+   device_unregister(>dev);
return ERR_PTR(ret);
 }
 EXPORT_SYMBOL(qcom_smd_register_edge);
-- 
1.9.1



[PATCH v3] ssb: use put_device() if device_register fail

2018-03-07 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
changes in v2:
 Removed kfree() call for @dev.
changes in v3:
 Add put_device() in place of kfree().

 drivers/ssb/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
index 65420a9..e732fd3 100644
--- a/drivers/ssb/main.c
+++ b/drivers/ssb/main.c
@@ -522,7 +522,7 @@ static int ssb_devices_register(struct ssb_bus *bus)
/* Set dev to NULL to not unregister
 * dev on error unwinding. */
sdev->dev = NULL;
-   kfree(devwrap);
+   put_device(dev);
goto error;
}
dev_idx++;
-- 
1.9.1



[PATCH v3] ssb: use put_device() if device_register fail

2018-03-07 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav 
---
changes in v2:
 Removed kfree() call for @dev.
changes in v3:
 Add put_device() in place of kfree().

 drivers/ssb/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
index 65420a9..e732fd3 100644
--- a/drivers/ssb/main.c
+++ b/drivers/ssb/main.c
@@ -522,7 +522,7 @@ static int ssb_devices_register(struct ssb_bus *bus)
/* Set dev to NULL to not unregister
 * dev on error unwinding. */
sdev->dev = NULL;
-   kfree(devwrap);
+   put_device(dev);
goto error;
}
dev_idx++;
-- 
1.9.1



[PATCH v2] ssb: use put_device() if device_register fail

2018-03-07 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
changes in v2:
 Removed kfree() call for @dev.

 drivers/ssb/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
index 65420a9..a7a062b 100644
--- a/drivers/ssb/main.c
+++ b/drivers/ssb/main.c
@@ -521,8 +521,8 @@ static int ssb_devices_register(struct ssb_bus *bus)
ssb_err("Could not register %s\n", dev_name(dev));
/* Set dev to NULL to not unregister
 * dev on error unwinding. */
+   put_device(dev);
sdev->dev = NULL;
-   kfree(devwrap);
goto error;
}
dev_idx++;
-- 
1.9.1



[PATCH v2] ssb: use put_device() if device_register fail

2018-03-07 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav 
---
changes in v2:
 Removed kfree() call for @dev.

 drivers/ssb/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
index 65420a9..a7a062b 100644
--- a/drivers/ssb/main.c
+++ b/drivers/ssb/main.c
@@ -521,8 +521,8 @@ static int ssb_devices_register(struct ssb_bus *bus)
ssb_err("Could not register %s\n", dev_name(dev));
/* Set dev to NULL to not unregister
 * dev on error unwinding. */
+   put_device(dev);
sdev->dev = NULL;
-   kfree(devwrap);
goto error;
}
dev_idx++;
-- 
1.9.1



[PATCH] scsi: scsi_transport_iscsi: use put_device() instead of kfree()

2018-03-07 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/scsi/scsi_transport_iscsi.c | 27 +--
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/scsi/scsi_transport_iscsi.c 
b/drivers/scsi/scsi_transport_iscsi.c
index f4b52b4..aacb7ab 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -221,8 +221,10 @@ struct iscsi_endpoint *
ep->dev.class = _endpoint_class;
dev_set_name(>dev, "ep-%llu", (unsigned long long) id);
err = device_register(>dev);
-if (err)
-goto free_ep;
+   if (err) {
+   put_device(>dev);
+   return NULL;
+   }
 
err = sysfs_create_group(>dev.kobj, _endpoint_group);
if (err)
@@ -235,10 +237,6 @@ struct iscsi_endpoint *
 unregister_dev:
device_unregister(>dev);
return NULL;
-
-free_ep:
-   kfree(ep);
-   return NULL;
 }
 EXPORT_SYMBOL_GPL(iscsi_create_endpoint);
 
@@ -783,7 +781,7 @@ struct iscsi_iface *
 
 free_iface:
put_device(iface->dev.parent);
-   kfree(iface);
+   put_device(>dev);
return NULL;
 }
 EXPORT_SYMBOL_GPL(iscsi_create_iface);
@@ -1260,7 +1258,7 @@ struct iscsi_bus_flash_session *
return fnode_sess;
 
 free_fnode_sess:
-   kfree(fnode_sess);
+   put_device(_sess->dev);
return NULL;
 }
 EXPORT_SYMBOL_GPL(iscsi_create_flashnode_sess);
@@ -1308,7 +1306,7 @@ struct iscsi_bus_flash_conn *
return fnode_conn;
 
 free_fnode_conn:
-   kfree(fnode_conn);
+   put_device(_conn->dev);
return NULL;
 }
 EXPORT_SYMBOL_GPL(iscsi_create_flashnode_conn);
@@ -2268,6 +2266,8 @@ struct iscsi_cls_conn *
 
 release_parent_ref:
put_device(>dev);
+   put_device(>dev);
+   conn = NULL;
 free_conn:
kfree(conn);
return NULL;
@@ -4420,8 +4420,10 @@ struct scsi_transport_template *
priv->dev.class = _transport_class;
dev_set_name(>dev, "%s", tt->name);
err = device_register(>dev);
-   if (err)
-   goto free_priv;
+   if (err) {
+   put_device(>dev);
+   return NULL;
+   }
 
err = sysfs_create_group(>dev.kobj, _transport_group);
if (err)
@@ -4456,9 +4458,6 @@ struct scsi_transport_template *
 unregister_dev:
device_unregister(>dev);
return NULL;
-free_priv:
-   kfree(priv);
-   return NULL;
 }
 EXPORT_SYMBOL_GPL(iscsi_register_transport);
 
-- 
1.9.1



[PATCH] scsi: scsi_transport_iscsi: use put_device() instead of kfree()

2018-03-07 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/scsi/scsi_transport_iscsi.c | 27 +--
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/scsi/scsi_transport_iscsi.c 
b/drivers/scsi/scsi_transport_iscsi.c
index f4b52b4..aacb7ab 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -221,8 +221,10 @@ struct iscsi_endpoint *
ep->dev.class = _endpoint_class;
dev_set_name(>dev, "ep-%llu", (unsigned long long) id);
err = device_register(>dev);
-if (err)
-goto free_ep;
+   if (err) {
+   put_device(>dev);
+   return NULL;
+   }
 
err = sysfs_create_group(>dev.kobj, _endpoint_group);
if (err)
@@ -235,10 +237,6 @@ struct iscsi_endpoint *
 unregister_dev:
device_unregister(>dev);
return NULL;
-
-free_ep:
-   kfree(ep);
-   return NULL;
 }
 EXPORT_SYMBOL_GPL(iscsi_create_endpoint);
 
@@ -783,7 +781,7 @@ struct iscsi_iface *
 
 free_iface:
put_device(iface->dev.parent);
-   kfree(iface);
+   put_device(>dev);
return NULL;
 }
 EXPORT_SYMBOL_GPL(iscsi_create_iface);
@@ -1260,7 +1258,7 @@ struct iscsi_bus_flash_session *
return fnode_sess;
 
 free_fnode_sess:
-   kfree(fnode_sess);
+   put_device(_sess->dev);
return NULL;
 }
 EXPORT_SYMBOL_GPL(iscsi_create_flashnode_sess);
@@ -1308,7 +1306,7 @@ struct iscsi_bus_flash_conn *
return fnode_conn;
 
 free_fnode_conn:
-   kfree(fnode_conn);
+   put_device(_conn->dev);
return NULL;
 }
 EXPORT_SYMBOL_GPL(iscsi_create_flashnode_conn);
@@ -2268,6 +2266,8 @@ struct iscsi_cls_conn *
 
 release_parent_ref:
put_device(>dev);
+   put_device(>dev);
+   conn = NULL;
 free_conn:
kfree(conn);
return NULL;
@@ -4420,8 +4420,10 @@ struct scsi_transport_template *
priv->dev.class = _transport_class;
dev_set_name(>dev, "%s", tt->name);
err = device_register(>dev);
-   if (err)
-   goto free_priv;
+   if (err) {
+   put_device(>dev);
+   return NULL;
+   }
 
err = sysfs_create_group(>dev.kobj, _transport_group);
if (err)
@@ -4456,9 +4458,6 @@ struct scsi_transport_template *
 unregister_dev:
device_unregister(>dev);
return NULL;
-free_priv:
-   kfree(priv);
-   return NULL;
 }
 EXPORT_SYMBOL_GPL(iscsi_register_transport);
 
-- 
1.9.1



[PATCH 2/2] sh: superhyway: use put_device() if device_register fail

2018-03-07 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/sh/superhyway/superhyway.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/sh/superhyway/superhyway.c 
b/drivers/sh/superhyway/superhyway.c
index 348836b..98922e7 100644
--- a/drivers/sh/superhyway/superhyway.c
+++ b/drivers/sh/superhyway/superhyway.c
@@ -54,6 +54,7 @@ int superhyway_add_device(unsigned long base, struct 
superhyway_device *sdev,
  struct superhyway_bus *bus)
 {
struct superhyway_device *dev = sdev;
+   int ret;
 
if (!dev) {
dev = kzalloc(sizeof(struct superhyway_device), GFP_KERNEL);
@@ -87,7 +88,11 @@ int superhyway_add_device(unsigned long base, struct 
superhyway_device *sdev,
 
superhyway_devices++;
 
-   return device_register(>dev);
+   ret = device_register(>dev);
+   if (ret)
+   put_device(>dev);
+
+   return ret;
 }
 
 int superhyway_add_devices(struct superhyway_bus *bus,
@@ -110,8 +115,10 @@ static int __init superhyway_init(void)
int ret;
 
ret = device_register(_bus_device);
-   if (unlikely(ret))
+   if (unlikely(ret)) {
+   put_device(_bus_device);
return ret;
+   }
 
for (bus = superhyway_channels; bus->ops; bus++)
ret |= superhyway_scan_bus(bus);
-- 
1.9.1



[PATCH 1/2] sh: maple: use put_device() instead of kfree()

2018-03-07 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
 drivers/sh/maple/maple.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/sh/maple/maple.c b/drivers/sh/maple/maple.c
index 7525039..28674fe 100644
--- a/drivers/sh/maple/maple.c
+++ b/drivers/sh/maple/maple.c
@@ -393,7 +393,7 @@ static void maple_attach_driver(struct maple_device *mdev)
dev_warn(>dev, "could not register device at"
" (%d, %d), with error 0x%X\n", mdev->unit,
mdev->port, error);
-   maple_free_dev(mdev);
+   put_device(>dev);
mdev = NULL;
return;
}
@@ -886,6 +886,7 @@ static int __init maple_bus_init(void)
 
 cleanup:
printk(KERN_ERR "Maple bus registration failed\n");
+   put_device(_bus);
return retval;
 }
 /* Push init to later to ensure hardware gets detected */
-- 
1.9.1



[PATCH 1/2] sh: maple: use put_device() instead of kfree()

2018-03-07 Thread Arvind Yadav
Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/sh/maple/maple.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/sh/maple/maple.c b/drivers/sh/maple/maple.c
index 7525039..28674fe 100644
--- a/drivers/sh/maple/maple.c
+++ b/drivers/sh/maple/maple.c
@@ -393,7 +393,7 @@ static void maple_attach_driver(struct maple_device *mdev)
dev_warn(>dev, "could not register device at"
" (%d, %d), with error 0x%X\n", mdev->unit,
mdev->port, error);
-   maple_free_dev(mdev);
+   put_device(>dev);
mdev = NULL;
return;
}
@@ -886,6 +886,7 @@ static int __init maple_bus_init(void)
 
 cleanup:
printk(KERN_ERR "Maple bus registration failed\n");
+   put_device(_bus);
return retval;
 }
 /* Push init to later to ensure hardware gets detected */
-- 
1.9.1



[PATCH 2/2] sh: superhyway: use put_device() if device_register fail

2018-03-07 Thread Arvind Yadav
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav 
---
 drivers/sh/superhyway/superhyway.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/sh/superhyway/superhyway.c 
b/drivers/sh/superhyway/superhyway.c
index 348836b..98922e7 100644
--- a/drivers/sh/superhyway/superhyway.c
+++ b/drivers/sh/superhyway/superhyway.c
@@ -54,6 +54,7 @@ int superhyway_add_device(unsigned long base, struct 
superhyway_device *sdev,
  struct superhyway_bus *bus)
 {
struct superhyway_device *dev = sdev;
+   int ret;
 
if (!dev) {
dev = kzalloc(sizeof(struct superhyway_device), GFP_KERNEL);
@@ -87,7 +88,11 @@ int superhyway_add_device(unsigned long base, struct 
superhyway_device *sdev,
 
superhyway_devices++;
 
-   return device_register(>dev);
+   ret = device_register(>dev);
+   if (ret)
+   put_device(>dev);
+
+   return ret;
 }
 
 int superhyway_add_devices(struct superhyway_bus *bus,
@@ -110,8 +115,10 @@ static int __init superhyway_init(void)
int ret;
 
ret = device_register(_bus_device);
-   if (unlikely(ret))
+   if (unlikely(ret)) {
+   put_device(_bus_device);
return ret;
+   }
 
for (bus = superhyway_channels; bus->ops; bus++)
ret |= superhyway_scan_bus(bus);
-- 
1.9.1



  1   2   3   4   5   6   7   8   9   10   >