Re: [PATCH] iio: (max1363) Fix probe error path

2012-12-27 Thread Jonathan Cameron
On 12/24/2012 06:24 AM, Guenter Roeck wrote:
> Instantiating the driver with no available regulator results in:
> 
> [39711.686393] i2c i2c-7: new_device: Instantiated device max1139 at 0x35
> [39711.688687] BUG: unable to handle kernel paging request at fe13
> [39711.688734] IP: [] regulator_disable+0x1b/0x80
> [39711.688788] PGD 1c0e067 PUD 1c0f067 PMD 0
> [39711.688835] Oops:  [#1] SMP
> 
> Caused by bad probe error path. Fix it.
Oops.
> 
> Driver should also not attempt to free the interrupt in its error path if
> none was allocated. Fix that problem as well.
> 
> Finally, testing if the regulator was allocated is not necessary in the
> remove function, since the probe function bails out if this is the case.
> Remove that check.
> 
Thanks Guenter. Added to the fixes-togreg branch of
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git

Might be the new year before I send Greg the pull request.

Jonathan

> Signed-off-by: Guenter Roeck 
> ---
>  drivers/iio/adc/max1363.c |   13 ++---
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
> index 1e84b5b..31f3485 100644
> --- a/drivers/iio/adc/max1363.c
> +++ b/drivers/iio/adc/max1363.c
> @@ -1605,19 +1605,20 @@ static int __devinit max1363_probe(struct i2c_client 
> *client,
>  
>   return 0;
>  error_free_irq:
> - free_irq(st->client->irq, indio_dev);
> + if (client->irq)
> + free_irq(st->client->irq, indio_dev);
>  error_uninit_buffer:
>   iio_buffer_unregister(indio_dev);
>  error_cleanup_buffer:
>   max1363_buffer_cleanup(indio_dev);
>  error_free_available_scan_masks:
>   kfree(indio_dev->available_scan_masks);
> -error_unregister_map:
> - iio_map_array_unregister(indio_dev, client->dev.platform_data);
>  error_disable_reg:
>   regulator_disable(st->reg);
>  error_put_reg:
>   regulator_put(st->reg);
> +error_unregister_map:
> + iio_map_array_unregister(indio_dev, client->dev.platform_data);
>  error_free_device:
>   iio_device_free(indio_dev);
>  error_out:
> @@ -1635,10 +1636,8 @@ static int __devexit max1363_remove(struct i2c_client 
> *client)
>   iio_buffer_unregister(indio_dev);
>   max1363_buffer_cleanup(indio_dev);
>   kfree(indio_dev->available_scan_masks);
> - if (!IS_ERR(st->reg)) {
> - regulator_disable(st->reg);
> - regulator_put(st->reg);
> - }
> + regulator_disable(st->reg);
> + regulator_put(st->reg);
>   iio_map_array_unregister(indio_dev, client->dev.platform_data);
>   iio_device_free(indio_dev);
>  
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] iio: (max1363) Fix probe error path

2012-12-27 Thread Jonathan Cameron
On 12/24/2012 06:24 AM, Guenter Roeck wrote:
 Instantiating the driver with no available regulator results in:
 
 [39711.686393] i2c i2c-7: new_device: Instantiated device max1139 at 0x35
 [39711.688687] BUG: unable to handle kernel paging request at fe13
 [39711.688734] IP: [813e835b] regulator_disable+0x1b/0x80
 [39711.688788] PGD 1c0e067 PUD 1c0f067 PMD 0
 [39711.688835] Oops:  [#1] SMP
 
 Caused by bad probe error path. Fix it.
Oops.
 
 Driver should also not attempt to free the interrupt in its error path if
 none was allocated. Fix that problem as well.
 
 Finally, testing if the regulator was allocated is not necessary in the
 remove function, since the probe function bails out if this is the case.
 Remove that check.
 
Thanks Guenter. Added to the fixes-togreg branch of
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git

Might be the new year before I send Greg the pull request.

Jonathan

 Signed-off-by: Guenter Roeck li...@roeck-us.net
 ---
  drivers/iio/adc/max1363.c |   13 ++---
  1 file changed, 6 insertions(+), 7 deletions(-)
 
 diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
 index 1e84b5b..31f3485 100644
 --- a/drivers/iio/adc/max1363.c
 +++ b/drivers/iio/adc/max1363.c
 @@ -1605,19 +1605,20 @@ static int __devinit max1363_probe(struct i2c_client 
 *client,
  
   return 0;
  error_free_irq:
 - free_irq(st-client-irq, indio_dev);
 + if (client-irq)
 + free_irq(st-client-irq, indio_dev);
  error_uninit_buffer:
   iio_buffer_unregister(indio_dev);
  error_cleanup_buffer:
   max1363_buffer_cleanup(indio_dev);
  error_free_available_scan_masks:
   kfree(indio_dev-available_scan_masks);
 -error_unregister_map:
 - iio_map_array_unregister(indio_dev, client-dev.platform_data);
  error_disable_reg:
   regulator_disable(st-reg);
  error_put_reg:
   regulator_put(st-reg);
 +error_unregister_map:
 + iio_map_array_unregister(indio_dev, client-dev.platform_data);
  error_free_device:
   iio_device_free(indio_dev);
  error_out:
 @@ -1635,10 +1636,8 @@ static int __devexit max1363_remove(struct i2c_client 
 *client)
   iio_buffer_unregister(indio_dev);
   max1363_buffer_cleanup(indio_dev);
   kfree(indio_dev-available_scan_masks);
 - if (!IS_ERR(st-reg)) {
 - regulator_disable(st-reg);
 - regulator_put(st-reg);
 - }
 + regulator_disable(st-reg);
 + regulator_put(st-reg);
   iio_map_array_unregister(indio_dev, client-dev.platform_data);
   iio_device_free(indio_dev);
  
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] iio: (max1363) Fix probe error path

2012-12-23 Thread Guenter Roeck
Instantiating the driver with no available regulator results in:

[39711.686393] i2c i2c-7: new_device: Instantiated device max1139 at 0x35
[39711.688687] BUG: unable to handle kernel paging request at fe13
[39711.688734] IP: [] regulator_disable+0x1b/0x80
[39711.688788] PGD 1c0e067 PUD 1c0f067 PMD 0
[39711.688835] Oops:  [#1] SMP

Caused by bad probe error path. Fix it.

Driver should also not attempt to free the interrupt in its error path if
none was allocated. Fix that problem as well.

Finally, testing if the regulator was allocated is not necessary in the
remove function, since the probe function bails out if this is the case.
Remove that check.

Signed-off-by: Guenter Roeck 
---
 drivers/iio/adc/max1363.c |   13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
index 1e84b5b..31f3485 100644
--- a/drivers/iio/adc/max1363.c
+++ b/drivers/iio/adc/max1363.c
@@ -1605,19 +1605,20 @@ static int __devinit max1363_probe(struct i2c_client 
*client,
 
return 0;
 error_free_irq:
-   free_irq(st->client->irq, indio_dev);
+   if (client->irq)
+   free_irq(st->client->irq, indio_dev);
 error_uninit_buffer:
iio_buffer_unregister(indio_dev);
 error_cleanup_buffer:
max1363_buffer_cleanup(indio_dev);
 error_free_available_scan_masks:
kfree(indio_dev->available_scan_masks);
-error_unregister_map:
-   iio_map_array_unregister(indio_dev, client->dev.platform_data);
 error_disable_reg:
regulator_disable(st->reg);
 error_put_reg:
regulator_put(st->reg);
+error_unregister_map:
+   iio_map_array_unregister(indio_dev, client->dev.platform_data);
 error_free_device:
iio_device_free(indio_dev);
 error_out:
@@ -1635,10 +1636,8 @@ static int __devexit max1363_remove(struct i2c_client 
*client)
iio_buffer_unregister(indio_dev);
max1363_buffer_cleanup(indio_dev);
kfree(indio_dev->available_scan_masks);
-   if (!IS_ERR(st->reg)) {
-   regulator_disable(st->reg);
-   regulator_put(st->reg);
-   }
+   regulator_disable(st->reg);
+   regulator_put(st->reg);
iio_map_array_unregister(indio_dev, client->dev.platform_data);
iio_device_free(indio_dev);
 
-- 
1.7.9.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] iio: (max1363) Fix probe error path

2012-12-23 Thread Guenter Roeck
Instantiating the driver with no available regulator results in:

[39711.686393] i2c i2c-7: new_device: Instantiated device max1139 at 0x35
[39711.688687] BUG: unable to handle kernel paging request at fe13
[39711.688734] IP: [813e835b] regulator_disable+0x1b/0x80
[39711.688788] PGD 1c0e067 PUD 1c0f067 PMD 0
[39711.688835] Oops:  [#1] SMP

Caused by bad probe error path. Fix it.

Driver should also not attempt to free the interrupt in its error path if
none was allocated. Fix that problem as well.

Finally, testing if the regulator was allocated is not necessary in the
remove function, since the probe function bails out if this is the case.
Remove that check.

Signed-off-by: Guenter Roeck li...@roeck-us.net
---
 drivers/iio/adc/max1363.c |   13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
index 1e84b5b..31f3485 100644
--- a/drivers/iio/adc/max1363.c
+++ b/drivers/iio/adc/max1363.c
@@ -1605,19 +1605,20 @@ static int __devinit max1363_probe(struct i2c_client 
*client,
 
return 0;
 error_free_irq:
-   free_irq(st-client-irq, indio_dev);
+   if (client-irq)
+   free_irq(st-client-irq, indio_dev);
 error_uninit_buffer:
iio_buffer_unregister(indio_dev);
 error_cleanup_buffer:
max1363_buffer_cleanup(indio_dev);
 error_free_available_scan_masks:
kfree(indio_dev-available_scan_masks);
-error_unregister_map:
-   iio_map_array_unregister(indio_dev, client-dev.platform_data);
 error_disable_reg:
regulator_disable(st-reg);
 error_put_reg:
regulator_put(st-reg);
+error_unregister_map:
+   iio_map_array_unregister(indio_dev, client-dev.platform_data);
 error_free_device:
iio_device_free(indio_dev);
 error_out:
@@ -1635,10 +1636,8 @@ static int __devexit max1363_remove(struct i2c_client 
*client)
iio_buffer_unregister(indio_dev);
max1363_buffer_cleanup(indio_dev);
kfree(indio_dev-available_scan_masks);
-   if (!IS_ERR(st-reg)) {
-   regulator_disable(st-reg);
-   regulator_put(st-reg);
-   }
+   regulator_disable(st-reg);
+   regulator_put(st-reg);
iio_map_array_unregister(indio_dev, client-dev.platform_data);
iio_device_free(indio_dev);
 
-- 
1.7.9.7

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/