All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Thompson <daniel.thompson@linaro.org>
To: Aditya Pakki <pakki001@umn.edu>
Cc: kjlu@umn.edu, Lee Jones <lee.jones@linaro.org>,
	Jingoo Han <jingoohan1@gmail.com>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] v2 bakclight: fix missing checks in ambient_light_zone_store
Date: Mon, 7 Jan 2019 11:12:14 +0000	[thread overview]
Message-ID: <20190107111214.hl3issz5yzs5muqc@holly.lan> (raw)
In-Reply-To: <20190105184807.4827-1-pakki001@umn.edu>

On Sat, Jan 05, 2019 at 12:48:07PM -0600, Aditya Pakki wrote:
> In adp8870_bl_ambient_light_zone_store, set, clear, and write

I'm curious...

What attracted you to this particular _store function? AFAICT the same
ignoring of return values occurs in other _store functions in this file?


> can return an error but are not checked. The fix adds a check for these
> cases and returns -1 to match the return type (ssize_t).

This isn't right. The caller of the store function expects -errno
values (this is the default for almost all kernel functions).


> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
>  drivers/video/backlight/adp8870_bl.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/video/backlight/adp8870_bl.c b/drivers/video/backlight/adp8870_bl.c
> index 8d50e0299578..56a640587a82 100644
> --- a/drivers/video/backlight/adp8870_bl.c
> +++ b/drivers/video/backlight/adp8870_bl.c
> @@ -800,10 +800,14 @@ static ssize_t adp8870_bl_ambient_light_zone_store(struct device *dev,
>  
>  	if (val == 0) {
>  		/* Enable automatic ambient light sensing */
> -		adp8870_set_bits(data->client, ADP8870_MDCR, CMP_AUTOEN);
> +		ret = adp8870_set_bits(data->client, ADP8870_MDCR, CMP_AUTOEN);
> +		if (ret < 0)
> +			goto adp8870_bl_err;

There's nothing *wrong* with goto for error handling but is it
really needed here (there is no recovery code)?


>  	} else if ((val > 0) && (val < 6)) {
>  		/* Disable automatic ambient light sensing */
> -		adp8870_clr_bits(data->client, ADP8870_MDCR, CMP_AUTOEN);
> +		ret = adp8870_clr_bits(data->client, ADP8870_MDCR, CMP_AUTOEN);
> +		if (ret < 0)
> +			goto adp8870_bl_err;

+1

>  
>  		/* Set user supplied ambient light zone */
>  		mutex_lock(&data->lock);
> @@ -811,12 +815,18 @@ static ssize_t adp8870_bl_ambient_light_zone_store(struct device *dev,
>  		if (!ret) {
>  			reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT);
>  			reg_val |= (val - 1) << CFGR_BLV_SHIFT;
> -			adp8870_write(data->client, ADP8870_CFGR, reg_val);
> +			ret = adp8870_write(data->client, ADP8870_CFGR,
> +						reg_val);
>  		}
>  		mutex_unlock(&data->lock);
> +		if (ret < 0)
> +			goto adp8870_bl_err;

+1


Daniel.

>  	}
>  
>  	return count;
> +
> +adp8870_bl_err:
> +	return -1;
>  }
>  static DEVICE_ATTR(ambient_light_zone, 0664,
>  		adp8870_bl_ambient_light_zone_show,
> -- 
> 2.17.1
> 

WARNING: multiple messages have this Message-ID (diff)
From: Daniel Thompson <daniel.thompson@linaro.org>
To: Aditya Pakki <pakki001@umn.edu>
Cc: linux-fbdev@vger.kernel.org,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	Jingoo Han <jingoohan1@gmail.com>,
	kjlu@umn.edu, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org, Lee Jones <lee.jones@linaro.org>
Subject: Re: [PATCH] v2 bakclight: fix missing checks in ambient_light_zone_store
Date: Mon, 07 Jan 2019 11:12:14 +0000	[thread overview]
Message-ID: <20190107111214.hl3issz5yzs5muqc@holly.lan> (raw)
In-Reply-To: <20190105184807.4827-1-pakki001@umn.edu>

On Sat, Jan 05, 2019 at 12:48:07PM -0600, Aditya Pakki wrote:
> In adp8870_bl_ambient_light_zone_store, set, clear, and write

I'm curious...

What attracted you to this particular _store function? AFAICT the same
ignoring of return values occurs in other _store functions in this file?


> can return an error but are not checked. The fix adds a check for these
> cases and returns -1 to match the return type (ssize_t).

This isn't right. The caller of the store function expects -errno
values (this is the default for almost all kernel functions).


> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
>  drivers/video/backlight/adp8870_bl.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/video/backlight/adp8870_bl.c b/drivers/video/backlight/adp8870_bl.c
> index 8d50e0299578..56a640587a82 100644
> --- a/drivers/video/backlight/adp8870_bl.c
> +++ b/drivers/video/backlight/adp8870_bl.c
> @@ -800,10 +800,14 @@ static ssize_t adp8870_bl_ambient_light_zone_store(struct device *dev,
>  
>  	if (val = 0) {
>  		/* Enable automatic ambient light sensing */
> -		adp8870_set_bits(data->client, ADP8870_MDCR, CMP_AUTOEN);
> +		ret = adp8870_set_bits(data->client, ADP8870_MDCR, CMP_AUTOEN);
> +		if (ret < 0)
> +			goto adp8870_bl_err;

There's nothing *wrong* with goto for error handling but is it
really needed here (there is no recovery code)?


>  	} else if ((val > 0) && (val < 6)) {
>  		/* Disable automatic ambient light sensing */
> -		adp8870_clr_bits(data->client, ADP8870_MDCR, CMP_AUTOEN);
> +		ret = adp8870_clr_bits(data->client, ADP8870_MDCR, CMP_AUTOEN);
> +		if (ret < 0)
> +			goto adp8870_bl_err;

+1

>  
>  		/* Set user supplied ambient light zone */
>  		mutex_lock(&data->lock);
> @@ -811,12 +815,18 @@ static ssize_t adp8870_bl_ambient_light_zone_store(struct device *dev,
>  		if (!ret) {
>  			reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT);
>  			reg_val |= (val - 1) << CFGR_BLV_SHIFT;
> -			adp8870_write(data->client, ADP8870_CFGR, reg_val);
> +			ret = adp8870_write(data->client, ADP8870_CFGR,
> +						reg_val);
>  		}
>  		mutex_unlock(&data->lock);
> +		if (ret < 0)
> +			goto adp8870_bl_err;

+1


Daniel.

>  	}
>  
>  	return count;
> +
> +adp8870_bl_err:
> +	return -1;
>  }
>  static DEVICE_ATTR(ambient_light_zone, 0664,
>  		adp8870_bl_ambient_light_zone_show,
> -- 
> 2.17.1
> 

WARNING: multiple messages have this Message-ID (diff)
From: Daniel Thompson <daniel.thompson@linaro.org>
To: Aditya Pakki <pakki001@umn.edu>
Cc: linux-fbdev@vger.kernel.org,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	Jingoo Han <jingoohan1@gmail.com>,
	kjlu@umn.edu, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org, Lee Jones <lee.jones@linaro.org>
Subject: Re: [PATCH] v2 bakclight: fix missing checks in ambient_light_zone_store
Date: Mon, 7 Jan 2019 11:12:14 +0000	[thread overview]
Message-ID: <20190107111214.hl3issz5yzs5muqc@holly.lan> (raw)
In-Reply-To: <20190105184807.4827-1-pakki001@umn.edu>

On Sat, Jan 05, 2019 at 12:48:07PM -0600, Aditya Pakki wrote:
> In adp8870_bl_ambient_light_zone_store, set, clear, and write

I'm curious...

What attracted you to this particular _store function? AFAICT the same
ignoring of return values occurs in other _store functions in this file?


> can return an error but are not checked. The fix adds a check for these
> cases and returns -1 to match the return type (ssize_t).

This isn't right. The caller of the store function expects -errno
values (this is the default for almost all kernel functions).


> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
>  drivers/video/backlight/adp8870_bl.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/video/backlight/adp8870_bl.c b/drivers/video/backlight/adp8870_bl.c
> index 8d50e0299578..56a640587a82 100644
> --- a/drivers/video/backlight/adp8870_bl.c
> +++ b/drivers/video/backlight/adp8870_bl.c
> @@ -800,10 +800,14 @@ static ssize_t adp8870_bl_ambient_light_zone_store(struct device *dev,
>  
>  	if (val == 0) {
>  		/* Enable automatic ambient light sensing */
> -		adp8870_set_bits(data->client, ADP8870_MDCR, CMP_AUTOEN);
> +		ret = adp8870_set_bits(data->client, ADP8870_MDCR, CMP_AUTOEN);
> +		if (ret < 0)
> +			goto adp8870_bl_err;

There's nothing *wrong* with goto for error handling but is it
really needed here (there is no recovery code)?


>  	} else if ((val > 0) && (val < 6)) {
>  		/* Disable automatic ambient light sensing */
> -		adp8870_clr_bits(data->client, ADP8870_MDCR, CMP_AUTOEN);
> +		ret = adp8870_clr_bits(data->client, ADP8870_MDCR, CMP_AUTOEN);
> +		if (ret < 0)
> +			goto adp8870_bl_err;

+1

>  
>  		/* Set user supplied ambient light zone */
>  		mutex_lock(&data->lock);
> @@ -811,12 +815,18 @@ static ssize_t adp8870_bl_ambient_light_zone_store(struct device *dev,
>  		if (!ret) {
>  			reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT);
>  			reg_val |= (val - 1) << CFGR_BLV_SHIFT;
> -			adp8870_write(data->client, ADP8870_CFGR, reg_val);
> +			ret = adp8870_write(data->client, ADP8870_CFGR,
> +						reg_val);
>  		}
>  		mutex_unlock(&data->lock);
> +		if (ret < 0)
> +			goto adp8870_bl_err;

+1


Daniel.

>  	}
>  
>  	return count;
> +
> +adp8870_bl_err:
> +	return -1;
>  }
>  static DEVICE_ATTR(ambient_light_zone, 0664,
>  		adp8870_bl_ambient_light_zone_show,
> -- 
> 2.17.1
> 
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2019-01-07 11:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-05 18:48 [PATCH] v2 bakclight: fix missing checks in ambient_light_zone_store Aditya Pakki
2019-01-05 18:48 ` Aditya Pakki
2019-01-07 11:12 ` Daniel Thompson [this message]
2019-01-07 11:12   ` Daniel Thompson
2019-01-07 11:12   ` Daniel Thompson
2019-01-07 11:13 ` Daniel Thompson
2019-01-07 11:13   ` Daniel Thompson
2019-01-07 11:13   ` Daniel Thompson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190107111214.hl3issz5yzs5muqc@holly.lan \
    --to=daniel.thompson@linaro.org \
    --cc=b.zolnierkie@samsung.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jingoohan1@gmail.com \
    --cc=kjlu@umn.edu \
    --cc=lee.jones@linaro.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pakki001@umn.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.