diff mbox

[2/3] iio: light: lm3533-als: Print error message on invalid resistance

Message ID 1445796586-28683-2-git-send-email-bjorn.andersson@sonymobile.com (mailing list archive)
State New, archived
Headers show

Commit Message

Bjorn Andersson Oct. 25, 2015, 6:09 p.m. UTC
Print an error message to indicate that invalid configuration data was
provided in the platform_data, rather than just aborting initialization.

Signed-off-by: Bjorn Andersson <bjorn.andersson@sonymobile.com>
---

This patch can be picked independently of the other 2, but included in the
series for "completeness".

 drivers/iio/light/lm3533-als.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Joe Perches Oct. 27, 2015, 7:18 p.m. UTC | #1
On Sun, 2015-10-25 at 11:09 -0700, Bjorn Andersson wrote:
> Print an error message to indicate that invalid configuration data was
> provided in the platform_data, rather than just aborting initialization.

Perhaps it'd be nicer to show the 3 values.

> diff --git a/drivers/iio/light/lm3533-als.c b/drivers/iio/light/lm3533-als.c
[]
> @@ -743,8 +743,10 @@ static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
>  {
>  	int ret;
>  
> -	if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX)
> +	if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) {
> +		dev_err(&als->pdev->dev, "invalid resistor value\n");
>  		return -EINVAL;
> +	};
>  
>  	ret = lm3533_write(als->lm3533, LM3533_REG_ALS_RESISTOR_SELECT, val);
>  	if (ret) {
Bjorn Andersson Oct. 28, 2015, 6:37 p.m. UTC | #2
On Tue 27 Oct 12:18 PDT 2015, Joe Perches wrote:

> On Sun, 2015-10-25 at 11:09 -0700, Bjorn Andersson wrote:
> > Print an error message to indicate that invalid configuration data was
> > provided in the platform_data, rather than just aborting initialization.
> 
> Perhaps it'd be nicer to show the 3 values.
> 

I do agree that it would be helpful to hint the developer about the
expected range. The problem I see here though is that, in the case of
devicetree we've now moved from resistance to a register value.

E.g. specifying 500kOhm in dt would make this piece complain about a
resistance of 0 being invalid and I would have to read the code and/or
datasheet anyways to find the valid range.


The reason I did not put this error print in the dt parser was that I
did not want to replicate the resistor limits and I figured it would be
useful for platform_data users as well. But if this is going to be
informative I think I need to move it.

So would you be okay with not improving the message? Or would you like
me to just move it into the code in patch 1 - and leave the
platform_data case as it was (with a silent failure)?

> > diff --git a/drivers/iio/light/lm3533-als.c b/drivers/iio/light/lm3533-als.c
> []
> > @@ -743,8 +743,10 @@ static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
> >  {
> >  	int ret;
> >  
> > -	if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX)
> > +	if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) {
> > +		dev_err(&als->pdev->dev, "invalid resistor value\n");
> >  		return -EINVAL;
> > +	};
> >  

Regards,
Bjorn
Joe Perches Oct. 28, 2015, 6:53 p.m. UTC | #3
On Wed, 2015-10-28 at 11:37 -0700, Bjorn Andersson wrote:
> On Tue 27 Oct 12:18 PDT 2015, Joe Perches wrote:
> > On Sun, 2015-10-25 at 11:09 -0700, Bjorn Andersson wrote:
> > > Print an error message to indicate that invalid configuration data was
> > > provided in the platform_data, rather than just aborting initialization.
> > Perhaps it'd be nicer to show the 3 values.
> I do agree that it would be helpful to hint the developer about the
> expected range. The problem I see here though is that, in the case of
> devicetree we've now moved from resistance to a register value.
[]
> So would you be okay with not improving the message? Or would you like
> me to just move it into the code in patch 1 - and leave the
> platform_data case as it was (with a silent failure)?
[]
> > > diff --git a/drivers/iio/light/lm3533-als.c b/drivers/iio/light/lm3533-als.c
> > []
> > > @@ -743,8 +743,10 @@ static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
> > >  {
> > >  	int ret;
> > >  
> > > -	if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX)
> > > +	if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) {
> > > +		dev_err(&als->pdev->dev, "invalid resistor value\n");
> > >  		return -EINVAL;
> > > +	};
> > >  

What I suggested was just a trivial proposal.
Whatever you do is fine with me.
diff mbox

Patch

diff --git a/drivers/iio/light/lm3533-als.c b/drivers/iio/light/lm3533-als.c
index 076bc46fad03..e56937c40a18 100644
--- a/drivers/iio/light/lm3533-als.c
+++ b/drivers/iio/light/lm3533-als.c
@@ -743,8 +743,10 @@  static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
 {
 	int ret;
 
-	if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX)
+	if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) {
+		dev_err(&als->pdev->dev, "invalid resistor value\n");
 		return -EINVAL;
+	};
 
 	ret = lm3533_write(als->lm3533, LM3533_REG_ALS_RESISTOR_SELECT, val);
 	if (ret) {