diff mbox

[v2,1/1] Input: max8997_haptic - Check return values

Message ID 1401704643-27846-1-git-send-email-sachin.kamat@linaro.org
State New
Headers show

Commit Message

Sachin Kamat June 2, 2014, 10:24 a.m. UTC
Check the return value of regulator_enable and pwm_enable to
avoid errors.
Fixes the following warning:
drivers/input/misc/max8997_haptic.c:185:19: warning: ignoring return value of ‘regulator_enable’, declared with attribute warn_unused_result [-Wunused-result]

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Cc: Donggeun Kim <dg77.kim@samsung.com>
---
Changes since v1:
* checked the return value of pwm_enable as suggested by Dmitry.
* Make chip->enabled = true only if enablement is
successful.
---
 drivers/input/misc/max8997_haptic.c |   17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

Comments

Dmitry Torokhov June 8, 2014, 6:12 a.m. UTC | #1
On Mon, Jun 02, 2014 at 03:54:03PM +0530, Sachin Kamat wrote:
> Check the return value of regulator_enable and pwm_enable to
> avoid errors.
> Fixes the following warning:
> drivers/input/misc/max8997_haptic.c:185:19: warning: ignoring return value of ‘regulator_enable’, declared with attribute warn_unused_result [-Wunused-result]
> 
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
> Cc: Donggeun Kim <dg77.kim@samsung.com>
> ---
> Changes since v1:
> * checked the return value of pwm_enable as suggested by Dmitry.
> * Make chip->enabled = true only if enablement is
> successful.
> ---
>  drivers/input/misc/max8997_haptic.c |   17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/input/misc/max8997_haptic.c b/drivers/input/misc/max8997_haptic.c
> index 1fea5484941f..11f4d84625b3 100644
> --- a/drivers/input/misc/max8997_haptic.c
> +++ b/drivers/input/misc/max8997_haptic.c
> @@ -181,11 +181,20 @@ static void max8997_haptic_enable(struct max8997_haptic *chip)
>  	}
>  
>  	if (!chip->enabled) {
> -		chip->enabled = true;
> -		regulator_enable(chip->regulator);
> +		error = regulator_enable(chip->regulator);
> +		if (error) {
> +			dev_err(chip->dev, "Failed to enable regulator\n");
> +			goto out;
> +		}
>  		max8997_haptic_configure(chip);
> -		if (chip->mode == MAX8997_EXTERNAL_MODE)
> -			pwm_enable(chip->pwm);
> +		if (chip->mode == MAX8997_EXTERNAL_MODE) {
> +			error = pwm_enable(chip->pwm);
> +			if (error) {
> +				dev_err(chip->dev, "Failed to enable PWM\n");

I think we should also disable regulator here, I'll add it.

> +				goto out;
> +			}
> +		}
> +		chip->enabled = true;
>  	}
>  
>  out:
> -- 
> 1.7.9.5
>
Sachin Kamat June 9, 2014, 4:02 a.m. UTC | #2
On Sun, Jun 8, 2014 at 11:42 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> On Mon, Jun 02, 2014 at 03:54:03PM +0530, Sachin Kamat wrote:
>> Check the return value of regulator_enable and pwm_enable to
>> avoid errors.
>> Fixes the following warning:
>> drivers/input/misc/max8997_haptic.c:185:19: warning: ignoring return value of ‘regulator_enable’, declared with attribute warn_unused_result [-Wunused-result]
>>
>> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
>> Cc: Donggeun Kim <dg77.kim@samsung.com>
>> ---
>> Changes since v1:
>> * checked the return value of pwm_enable as suggested by Dmitry.
>> * Make chip->enabled = true only if enablement is
>> successful.
>> ---
>>  drivers/input/misc/max8997_haptic.c |   17 +++++++++++++----
>>  1 file changed, 13 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/input/misc/max8997_haptic.c b/drivers/input/misc/max8997_haptic.c
>> index 1fea5484941f..11f4d84625b3 100644
>> --- a/drivers/input/misc/max8997_haptic.c
>> +++ b/drivers/input/misc/max8997_haptic.c
>> @@ -181,11 +181,20 @@ static void max8997_haptic_enable(struct max8997_haptic *chip)
>>       }
>>
>>       if (!chip->enabled) {
>> -             chip->enabled = true;
>> -             regulator_enable(chip->regulator);
>> +             error = regulator_enable(chip->regulator);
>> +             if (error) {
>> +                     dev_err(chip->dev, "Failed to enable regulator\n");
>> +                     goto out;
>> +             }
>>               max8997_haptic_configure(chip);
>> -             if (chip->mode == MAX8997_EXTERNAL_MODE)
>> -                     pwm_enable(chip->pwm);
>> +             if (chip->mode == MAX8997_EXTERNAL_MODE) {
>> +                     error = pwm_enable(chip->pwm);
>> +                     if (error) {
>> +                             dev_err(chip->dev, "Failed to enable PWM\n");
>
> I think we should also disable regulator here, I'll add it.

Right. Thanks for fixing it, Dmitry.

Regards,
Sachin.
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/input/misc/max8997_haptic.c b/drivers/input/misc/max8997_haptic.c
index 1fea5484941f..11f4d84625b3 100644
--- a/drivers/input/misc/max8997_haptic.c
+++ b/drivers/input/misc/max8997_haptic.c
@@ -181,11 +181,20 @@  static void max8997_haptic_enable(struct max8997_haptic *chip)
 	}
 
 	if (!chip->enabled) {
-		chip->enabled = true;
-		regulator_enable(chip->regulator);
+		error = regulator_enable(chip->regulator);
+		if (error) {
+			dev_err(chip->dev, "Failed to enable regulator\n");
+			goto out;
+		}
 		max8997_haptic_configure(chip);
-		if (chip->mode == MAX8997_EXTERNAL_MODE)
-			pwm_enable(chip->pwm);
+		if (chip->mode == MAX8997_EXTERNAL_MODE) {
+			error = pwm_enable(chip->pwm);
+			if (error) {
+				dev_err(chip->dev, "Failed to enable PWM\n");
+				goto out;
+			}
+		}
+		chip->enabled = true;
 	}
 
 out: