All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] mfd: ab8500-core: Return zero in get_register_interruptible()
@ 2018-10-18  8:05 ` Dan Carpenter
  0 siblings, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2018-10-18  8:05 UTC (permalink / raw)
  To: Linus Walleij, Mattias Wallin
  Cc: Lee Jones, linux-arm-kernel, linux-kernel, kernel-janitors

I just noticed this in review.  The get_register_interruptible() should
return zero on success but it instead returns the value that it read.

I looked at all the places that called this directly and they check for
negatives and treat greater than or equal to zero as success.  This
function is also called as the ->get_register() function pointer.  Some
of the callers of that treat all non-zero returns as errors, so it's
possible that this bug causes some problems in real life.

I could not find any callers that rely on the current behavior, and this
makes the function align with the get_register_interruptible() in
ab3100-core.c.

Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/mfd/ab8500-core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
index 30d09d177171..66458a329127 100644
--- a/drivers/mfd/ab8500-core.c
+++ b/drivers/mfd/ab8500-core.c
@@ -252,16 +252,18 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
 	mutex_lock(&ab8500->lock);
 
 	ret = ab8500->read(ab8500, addr);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
 			addr, ret);
-	else
-		*value = ret;
+		return ret;
+	}
+
+	*value = ret;
 
 	mutex_unlock(&ab8500->lock);
 	dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
 
-	return ret;
+	return 0;
 }
 
 static int ab8500_get_register(struct device *dev, u8 bank,
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 2/2] mfd: ab8500-core: Return zero in get_register_interruptible()
@ 2018-10-18  8:05 ` Dan Carpenter
  0 siblings, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2018-10-18  8:05 UTC (permalink / raw)
  To: linux-arm-kernel

I just noticed this in review.  The get_register_interruptible() should
return zero on success but it instead returns the value that it read.

I looked at all the places that called this directly and they check for
negatives and treat greater than or equal to zero as success.  This
function is also called as the ->get_register() function pointer.  Some
of the callers of that treat all non-zero returns as errors, so it's
possible that this bug causes some problems in real life.

I could not find any callers that rely on the current behavior, and this
makes the function align with the get_register_interruptible() in
ab3100-core.c.

Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/mfd/ab8500-core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
index 30d09d177171..66458a329127 100644
--- a/drivers/mfd/ab8500-core.c
+++ b/drivers/mfd/ab8500-core.c
@@ -252,16 +252,18 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
 	mutex_lock(&ab8500->lock);
 
 	ret = ab8500->read(ab8500, addr);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
 			addr, ret);
-	else
-		*value = ret;
+		return ret;
+	}
+
+	*value = ret;
 
 	mutex_unlock(&ab8500->lock);
 	dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
 
-	return ret;
+	return 0;
 }
 
 static int ab8500_get_register(struct device *dev, u8 bank,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 2/2] mfd: ab8500-core: Return zero in get_register_interruptible()
@ 2018-10-18  8:05 ` Dan Carpenter
  0 siblings, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2018-10-18  8:05 UTC (permalink / raw)
  To: linux-arm-kernel

I just noticed this in review.  The get_register_interruptible() should
return zero on success but it instead returns the value that it read.

I looked at all the places that called this directly and they check for
negatives and treat greater than or equal to zero as success.  This
function is also called as the ->get_register() function pointer.  Some
of the callers of that treat all non-zero returns as errors, so it's
possible that this bug causes some problems in real life.

I could not find any callers that rely on the current behavior, and this
makes the function align with the get_register_interruptible() in
ab3100-core.c.

Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/mfd/ab8500-core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
index 30d09d177171..66458a329127 100644
--- a/drivers/mfd/ab8500-core.c
+++ b/drivers/mfd/ab8500-core.c
@@ -252,16 +252,18 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
 	mutex_lock(&ab8500->lock);
 
 	ret = ab8500->read(ab8500, addr);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
 			addr, ret);
-	else
-		*value = ret;
+		return ret;
+	}
+
+	*value = ret;
 
 	mutex_unlock(&ab8500->lock);
 	dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
 
-	return ret;
+	return 0;
 }
 
 static int ab8500_get_register(struct device *dev, u8 bank,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/2] mfd: ab8500-core: Return zero in get_register_interruptible()
  2018-10-18  8:05 ` Dan Carpenter
  (?)
@ 2018-10-25  8:25   ` Lee Jones
  -1 siblings, 0 replies; 20+ messages in thread
From: Lee Jones @ 2018-10-25  8:25 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Linus Walleij, Mattias Wallin, linux-arm-kernel, linux-kernel,
	kernel-janitors

On Thu, 18 Oct 2018, Dan Carpenter wrote:

> I just noticed this in review.  The get_register_interruptible() should
> return zero on success but it instead returns the value that it read.
> 
> I looked at all the places that called this directly and they check for
> negatives and treat greater than or equal to zero as success.  This
> function is also called as the ->get_register() function pointer.  Some
> of the callers of that treat all non-zero returns as errors, so it's
> possible that this bug causes some problems in real life.
> 
> I could not find any callers that rely on the current behavior, and this
> makes the function align with the get_register_interruptible() in
> ab3100-core.c.
> 
> Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/mfd/ab8500-core.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
> index 30d09d177171..66458a329127 100644
> --- a/drivers/mfd/ab8500-core.c
> +++ b/drivers/mfd/ab8500-core.c
> @@ -252,16 +252,18 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
>  	mutex_lock(&ab8500->lock);
>  
>  	ret = ab8500->read(ab8500, addr);
> -	if (ret < 0)
> +	if (ret < 0) {
>  		dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
>  			addr, ret);
> -	else
> -		*value = ret;
> +		return ret;

Looks like you just broke the AB8500.

What is it you're trying to achieve here?  Apart from attempting to
return with the mutex still held, what semantics have you changed?

> +	}
> +
> +	*value = ret;
>  
>  	mutex_unlock(&ab8500->lock);
>  	dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
>  
> -	return ret;
> +	return 0;
>  }
>  
>  static int ab8500_get_register(struct device *dev, u8 bank,

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/2] mfd: ab8500-core: Return zero in get_register_interruptible()
@ 2018-10-25  8:25   ` Lee Jones
  0 siblings, 0 replies; 20+ messages in thread
From: Lee Jones @ 2018-10-25  8:25 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 18 Oct 2018, Dan Carpenter wrote:

> I just noticed this in review.  The get_register_interruptible() should
> return zero on success but it instead returns the value that it read.
> 
> I looked at all the places that called this directly and they check for
> negatives and treat greater than or equal to zero as success.  This
> function is also called as the ->get_register() function pointer.  Some
> of the callers of that treat all non-zero returns as errors, so it's
> possible that this bug causes some problems in real life.
> 
> I could not find any callers that rely on the current behavior, and this
> makes the function align with the get_register_interruptible() in
> ab3100-core.c.
> 
> Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/mfd/ab8500-core.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
> index 30d09d177171..66458a329127 100644
> --- a/drivers/mfd/ab8500-core.c
> +++ b/drivers/mfd/ab8500-core.c
> @@ -252,16 +252,18 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
>  	mutex_lock(&ab8500->lock);
>  
>  	ret = ab8500->read(ab8500, addr);
> -	if (ret < 0)
> +	if (ret < 0) {
>  		dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
>  			addr, ret);
> -	else
> -		*value = ret;
> +		return ret;

Looks like you just broke the AB8500.

What is it you're trying to achieve here?  Apart from attempting to
return with the mutex still held, what semantics have you changed?

> +	}
> +
> +	*value = ret;
>  
>  	mutex_unlock(&ab8500->lock);
>  	dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
>  
> -	return ret;
> +	return 0;
>  }
>  
>  static int ab8500_get_register(struct device *dev, u8 bank,

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 2/2] mfd: ab8500-core: Return zero in get_register_interruptible()
@ 2018-10-25  8:25   ` Lee Jones
  0 siblings, 0 replies; 20+ messages in thread
From: Lee Jones @ 2018-10-25  8:25 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 18 Oct 2018, Dan Carpenter wrote:

> I just noticed this in review.  The get_register_interruptible() should
> return zero on success but it instead returns the value that it read.
> 
> I looked at all the places that called this directly and they check for
> negatives and treat greater than or equal to zero as success.  This
> function is also called as the ->get_register() function pointer.  Some
> of the callers of that treat all non-zero returns as errors, so it's
> possible that this bug causes some problems in real life.
> 
> I could not find any callers that rely on the current behavior, and this
> makes the function align with the get_register_interruptible() in
> ab3100-core.c.
> 
> Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/mfd/ab8500-core.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
> index 30d09d177171..66458a329127 100644
> --- a/drivers/mfd/ab8500-core.c
> +++ b/drivers/mfd/ab8500-core.c
> @@ -252,16 +252,18 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
>  	mutex_lock(&ab8500->lock);
>  
>  	ret = ab8500->read(ab8500, addr);
> -	if (ret < 0)
> +	if (ret < 0) {
>  		dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
>  			addr, ret);
> -	else
> -		*value = ret;
> +		return ret;

Looks like you just broke the AB8500.

What is it you're trying to achieve here?  Apart from attempting to
return with the mutex still held, what semantics have you changed?

> +	}
> +
> +	*value = ret;
>  
>  	mutex_unlock(&ab8500->lock);
>  	dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
>  
> -	return ret;
> +	return 0;
>  }
>  
>  static int ab8500_get_register(struct device *dev, u8 bank,

-- 
Lee Jones [???]
Linaro Services Technical Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/2] mfd: ab8500-core: Return zero in get_register_interruptible()
  2018-10-25  8:25   ` Lee Jones
  (?)
@ 2018-10-25  8:46     ` Dan Carpenter
  -1 siblings, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2018-10-25  8:46 UTC (permalink / raw)
  To: Lee Jones
  Cc: Linus Walleij, Mattias Wallin, linux-arm-kernel, linux-kernel,
	kernel-janitors

On Thu, Oct 25, 2018 at 09:25:08AM +0100, Lee Jones wrote:
> On Thu, 18 Oct 2018, Dan Carpenter wrote:
> 
> > I just noticed this in review.  The get_register_interruptible() should
> > return zero on success but it instead returns the value that it read.
> > 
> > I looked at all the places that called this directly and they check for
> > negatives and treat greater than or equal to zero as success.  This
> > function is also called as the ->get_register() function pointer.  Some
> > of the callers of that treat all non-zero returns as errors, so it's
> > possible that this bug causes some problems in real life.
> > 
> > I could not find any callers that rely on the current behavior, and this
> > makes the function align with the get_register_interruptible() in
> > ab3100-core.c.
> > 
> > Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> >  drivers/mfd/ab8500-core.c | 10 ++++++----
> >  1 file changed, 6 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
> > index 30d09d177171..66458a329127 100644
> > --- a/drivers/mfd/ab8500-core.c
> > +++ b/drivers/mfd/ab8500-core.c
> > @@ -252,16 +252,18 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
> >  	mutex_lock(&ab8500->lock);
> >  
> >  	ret = ab8500->read(ab8500, addr);
> > -	if (ret < 0)
> > +	if (ret < 0) {
> >  		dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
> >  			addr, ret);
> > -	else
> > -		*value = ret;
> > +		return ret;
> 
> Looks like you just broke the AB8500.
> 


Oh wow.  I screwed up the locking.


> What is it you're trying to achieve here?  Apart from attempting to
> return with the mutex still held, what semantics have you changed?
> 

Sorry that wasn't clear.  Here is the relevant bits from the commit
message.

> > function is also called as the ->get_register() function pointer.  Some
> > of the callers of that treat all non-zero returns as errors, so it's
> > possible that this bug causes some problems in real life.

We're returning positive non-zero values on success instead of zero.
It's definitely a bug, but I'm not sure if it has an impact in real
life.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/2] mfd: ab8500-core: Return zero in get_register_interruptible()
@ 2018-10-25  8:46     ` Dan Carpenter
  0 siblings, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2018-10-25  8:46 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 25, 2018 at 09:25:08AM +0100, Lee Jones wrote:
> On Thu, 18 Oct 2018, Dan Carpenter wrote:
> 
> > I just noticed this in review.  The get_register_interruptible() should
> > return zero on success but it instead returns the value that it read.
> > 
> > I looked at all the places that called this directly and they check for
> > negatives and treat greater than or equal to zero as success.  This
> > function is also called as the ->get_register() function pointer.  Some
> > of the callers of that treat all non-zero returns as errors, so it's
> > possible that this bug causes some problems in real life.
> > 
> > I could not find any callers that rely on the current behavior, and this
> > makes the function align with the get_register_interruptible() in
> > ab3100-core.c.
> > 
> > Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> >  drivers/mfd/ab8500-core.c | 10 ++++++----
> >  1 file changed, 6 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
> > index 30d09d177171..66458a329127 100644
> > --- a/drivers/mfd/ab8500-core.c
> > +++ b/drivers/mfd/ab8500-core.c
> > @@ -252,16 +252,18 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
> >  	mutex_lock(&ab8500->lock);
> >  
> >  	ret = ab8500->read(ab8500, addr);
> > -	if (ret < 0)
> > +	if (ret < 0) {
> >  		dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
> >  			addr, ret);
> > -	else
> > -		*value = ret;
> > +		return ret;
> 
> Looks like you just broke the AB8500.
> 


Oh wow.  I screwed up the locking.


> What is it you're trying to achieve here?  Apart from attempting to
> return with the mutex still held, what semantics have you changed?
> 

Sorry that wasn't clear.  Here is the relevant bits from the commit
message.

> > function is also called as the ->get_register() function pointer.  Some
> > of the callers of that treat all non-zero returns as errors, so it's
> > possible that this bug causes some problems in real life.

We're returning positive non-zero values on success instead of zero.
It's definitely a bug, but I'm not sure if it has an impact in real
life.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 2/2] mfd: ab8500-core: Return zero in get_register_interruptible()
@ 2018-10-25  8:46     ` Dan Carpenter
  0 siblings, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2018-10-25  8:46 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 25, 2018 at 09:25:08AM +0100, Lee Jones wrote:
> On Thu, 18 Oct 2018, Dan Carpenter wrote:
> 
> > I just noticed this in review.  The get_register_interruptible() should
> > return zero on success but it instead returns the value that it read.
> > 
> > I looked at all the places that called this directly and they check for
> > negatives and treat greater than or equal to zero as success.  This
> > function is also called as the ->get_register() function pointer.  Some
> > of the callers of that treat all non-zero returns as errors, so it's
> > possible that this bug causes some problems in real life.
> > 
> > I could not find any callers that rely on the current behavior, and this
> > makes the function align with the get_register_interruptible() in
> > ab3100-core.c.
> > 
> > Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> >  drivers/mfd/ab8500-core.c | 10 ++++++----
> >  1 file changed, 6 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
> > index 30d09d177171..66458a329127 100644
> > --- a/drivers/mfd/ab8500-core.c
> > +++ b/drivers/mfd/ab8500-core.c
> > @@ -252,16 +252,18 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
> >  	mutex_lock(&ab8500->lock);
> >  
> >  	ret = ab8500->read(ab8500, addr);
> > -	if (ret < 0)
> > +	if (ret < 0) {
> >  		dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
> >  			addr, ret);
> > -	else
> > -		*value = ret;
> > +		return ret;
> 
> Looks like you just broke the AB8500.
> 


Oh wow.  I screwed up the locking.


> What is it you're trying to achieve here?  Apart from attempting to
> return with the mutex still held, what semantics have you changed?
> 

Sorry that wasn't clear.  Here is the relevant bits from the commit
message.

> > function is also called as the ->get_register() function pointer.  Some
> > of the callers of that treat all non-zero returns as errors, so it's
> > possible that this bug causes some problems in real life.

We're returning positive non-zero values on success instead of zero.
It's definitely a bug, but I'm not sure if it has an impact in real
life.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/2] mfd: ab8500-core: Return zero in get_register_interruptible()
  2018-10-25  8:46     ` Dan Carpenter
  (?)
@ 2018-10-25 10:10       ` Lee Jones
  -1 siblings, 0 replies; 20+ messages in thread
From: Lee Jones @ 2018-10-25 10:10 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Linus Walleij, Mattias Wallin, linux-arm-kernel, linux-kernel,
	kernel-janitors

On Thu, 25 Oct 2018, Dan Carpenter wrote:

> On Thu, Oct 25, 2018 at 09:25:08AM +0100, Lee Jones wrote:
> > On Thu, 18 Oct 2018, Dan Carpenter wrote:
> > 
> > > I just noticed this in review.  The get_register_interruptible() should
> > > return zero on success but it instead returns the value that it read.
> > > 
> > > I looked at all the places that called this directly and they check for
> > > negatives and treat greater than or equal to zero as success.  This
> > > function is also called as the ->get_register() function pointer.  Some
> > > of the callers of that treat all non-zero returns as errors, so it's
> > > possible that this bug causes some problems in real life.
> > > 
> > > I could not find any callers that rely on the current behavior, and this
> > > makes the function align with the get_register_interruptible() in
> > > ab3100-core.c.
> > > 
> > > Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > > ---
> > >  drivers/mfd/ab8500-core.c | 10 ++++++----
> > >  1 file changed, 6 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
> > > index 30d09d177171..66458a329127 100644
> > > --- a/drivers/mfd/ab8500-core.c
> > > +++ b/drivers/mfd/ab8500-core.c
> > > @@ -252,16 +252,18 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
> > >  	mutex_lock(&ab8500->lock);
> > >  
> > >  	ret = ab8500->read(ab8500, addr);
> > > -	if (ret < 0)
> > > +	if (ret < 0) {
> > >  		dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
> > >  			addr, ret);
> > > -	else
> > > -		*value = ret;
> > > +		return ret;
> > 
> > Looks like you just broke the AB8500.
> > 
> 
> 
> Oh wow.  I screwed up the locking.
> 
> 
> > What is it you're trying to achieve here?  Apart from attempting to
> > return with the mutex still held, what semantics have you changed?
> > 
> 
> Sorry that wasn't clear.  Here is the relevant bits from the commit
> message.
> 
> > > function is also called as the ->get_register() function pointer.  Some
> > > of the callers of that treat all non-zero returns as errors, so it's
> > > possible that this bug causes some problems in real life.
> 
> We're returning positive non-zero values on success instead of zero.
> It's definitely a bug, but I'm not sure if it has an impact in real
> life.

Oh, I see.

Maybe:

	return (ret > 0) ? 0 : ret;

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/2] mfd: ab8500-core: Return zero in get_register_interruptible()
@ 2018-10-25 10:10       ` Lee Jones
  0 siblings, 0 replies; 20+ messages in thread
From: Lee Jones @ 2018-10-25 10:10 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 25 Oct 2018, Dan Carpenter wrote:

> On Thu, Oct 25, 2018 at 09:25:08AM +0100, Lee Jones wrote:
> > On Thu, 18 Oct 2018, Dan Carpenter wrote:
> > 
> > > I just noticed this in review.  The get_register_interruptible() should
> > > return zero on success but it instead returns the value that it read.
> > > 
> > > I looked at all the places that called this directly and they check for
> > > negatives and treat greater than or equal to zero as success.  This
> > > function is also called as the ->get_register() function pointer.  Some
> > > of the callers of that treat all non-zero returns as errors, so it's
> > > possible that this bug causes some problems in real life.
> > > 
> > > I could not find any callers that rely on the current behavior, and this
> > > makes the function align with the get_register_interruptible() in
> > > ab3100-core.c.
> > > 
> > > Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > > ---
> > >  drivers/mfd/ab8500-core.c | 10 ++++++----
> > >  1 file changed, 6 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
> > > index 30d09d177171..66458a329127 100644
> > > --- a/drivers/mfd/ab8500-core.c
> > > +++ b/drivers/mfd/ab8500-core.c
> > > @@ -252,16 +252,18 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
> > >  	mutex_lock(&ab8500->lock);
> > >  
> > >  	ret = ab8500->read(ab8500, addr);
> > > -	if (ret < 0)
> > > +	if (ret < 0) {
> > >  		dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
> > >  			addr, ret);
> > > -	else
> > > -		*value = ret;
> > > +		return ret;
> > 
> > Looks like you just broke the AB8500.
> > 
> 
> 
> Oh wow.  I screwed up the locking.
> 
> 
> > What is it you're trying to achieve here?  Apart from attempting to
> > return with the mutex still held, what semantics have you changed?
> > 
> 
> Sorry that wasn't clear.  Here is the relevant bits from the commit
> message.
> 
> > > function is also called as the ->get_register() function pointer.  Some
> > > of the callers of that treat all non-zero returns as errors, so it's
> > > possible that this bug causes some problems in real life.
> 
> We're returning positive non-zero values on success instead of zero.
> It's definitely a bug, but I'm not sure if it has an impact in real
> life.

Oh, I see.

Maybe:

	return (ret > 0) ? 0 : ret;

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 2/2] mfd: ab8500-core: Return zero in get_register_interruptible()
@ 2018-10-25 10:10       ` Lee Jones
  0 siblings, 0 replies; 20+ messages in thread
From: Lee Jones @ 2018-10-25 10:10 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 25 Oct 2018, Dan Carpenter wrote:

> On Thu, Oct 25, 2018 at 09:25:08AM +0100, Lee Jones wrote:
> > On Thu, 18 Oct 2018, Dan Carpenter wrote:
> > 
> > > I just noticed this in review.  The get_register_interruptible() should
> > > return zero on success but it instead returns the value that it read.
> > > 
> > > I looked at all the places that called this directly and they check for
> > > negatives and treat greater than or equal to zero as success.  This
> > > function is also called as the ->get_register() function pointer.  Some
> > > of the callers of that treat all non-zero returns as errors, so it's
> > > possible that this bug causes some problems in real life.
> > > 
> > > I could not find any callers that rely on the current behavior, and this
> > > makes the function align with the get_register_interruptible() in
> > > ab3100-core.c.
> > > 
> > > Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > > ---
> > >  drivers/mfd/ab8500-core.c | 10 ++++++----
> > >  1 file changed, 6 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
> > > index 30d09d177171..66458a329127 100644
> > > --- a/drivers/mfd/ab8500-core.c
> > > +++ b/drivers/mfd/ab8500-core.c
> > > @@ -252,16 +252,18 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
> > >  	mutex_lock(&ab8500->lock);
> > >  
> > >  	ret = ab8500->read(ab8500, addr);
> > > -	if (ret < 0)
> > > +	if (ret < 0) {
> > >  		dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
> > >  			addr, ret);
> > > -	else
> > > -		*value = ret;
> > > +		return ret;
> > 
> > Looks like you just broke the AB8500.
> > 
> 
> 
> Oh wow.  I screwed up the locking.
> 
> 
> > What is it you're trying to achieve here?  Apart from attempting to
> > return with the mutex still held, what semantics have you changed?
> > 
> 
> Sorry that wasn't clear.  Here is the relevant bits from the commit
> message.
> 
> > > function is also called as the ->get_register() function pointer.  Some
> > > of the callers of that treat all non-zero returns as errors, so it's
> > > possible that this bug causes some problems in real life.
> 
> We're returning positive non-zero values on success instead of zero.
> It's definitely a bug, but I'm not sure if it has an impact in real
> life.

Oh, I see.

Maybe:

	return (ret > 0) ? 0 : ret;

-- 
Lee Jones [???]
Linaro Services Technical Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 2/2 v2] mfd: ab8500-core: Return zero in get_register_interruptible()
  2018-10-25 10:10       ` Lee Jones
@ 2018-10-25 12:43         ` Dan Carpenter
  -1 siblings, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2018-10-25 12:43 UTC (permalink / raw)
  To: linux-arm-kernel

This function is supposed to return zero on success or negative error
codes on error.  Unfortunately, there is a bug so it sometimes returns
non-zero, positive numbers on success.

I noticed this bug during review and I can't test it.  It does appear
that the return is sometimes propogated back to _regmap_read() where all
non-zero returns are treated as failure so this may affect run time.

Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: In v1, I introduced an new error path and forgot to drop the lock.

 drivers/mfd/ab8500-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
index 30d09d177171..11ab17f64c64 100644
--- a/drivers/mfd/ab8500-core.c
+++ b/drivers/mfd/ab8500-core.c
@@ -261,7 +261,7 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
 	mutex_unlock(&ab8500->lock);
 	dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
 
-	return ret;
+	return (ret < 0) ? ret : 0;
 }
 
 static int ab8500_get_register(struct device *dev, u8 bank,

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 2/2 v2] mfd: ab8500-core: Return zero in get_register_interruptible()
@ 2018-10-25 12:43         ` Dan Carpenter
  0 siblings, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2018-10-25 12:43 UTC (permalink / raw)
  To: linux-arm-kernel

This function is supposed to return zero on success or negative error
codes on error.  Unfortunately, there is a bug so it sometimes returns
non-zero, positive numbers on success.

I noticed this bug during review and I can't test it.  It does appear
that the return is sometimes propogated back to _regmap_read() where all
non-zero returns are treated as failure so this may affect run time.

Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: In v1, I introduced an new error path and forgot to drop the lock.

 drivers/mfd/ab8500-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
index 30d09d177171..11ab17f64c64 100644
--- a/drivers/mfd/ab8500-core.c
+++ b/drivers/mfd/ab8500-core.c
@@ -261,7 +261,7 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
 	mutex_unlock(&ab8500->lock);
 	dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
 
-	return ret;
+	return (ret < 0) ? ret : 0;
 }
 
 static int ab8500_get_register(struct device *dev, u8 bank,

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/2 v2] mfd: ab8500-core: Return zero in get_register_interruptible()
  2018-10-25 12:43         ` Dan Carpenter
@ 2018-10-26  8:30           ` Lee Jones
  -1 siblings, 0 replies; 20+ messages in thread
From: Lee Jones @ 2018-10-26  8:30 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 25 Oct 2018, Dan Carpenter wrote:

> This function is supposed to return zero on success or negative error
> codes on error.  Unfortunately, there is a bug so it sometimes returns
> non-zero, positive numbers on success.
> 
> I noticed this bug during review and I can't test it.  It does appear
> that the return is sometimes propogated back to _regmap_read() where all
> non-zero returns are treated as failure so this may affect run time.
> 
> Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: In v1, I introduced an new error path and forgot to drop the lock.
> 
>  drivers/mfd/ab8500-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Looks okay at first blush.

I'd really like Linus to review/test though.

> diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
> index 30d09d177171..11ab17f64c64 100644
> --- a/drivers/mfd/ab8500-core.c
> +++ b/drivers/mfd/ab8500-core.c
> @@ -261,7 +261,7 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
>  	mutex_unlock(&ab8500->lock);
>  	dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
>  
> -	return ret;
> +	return (ret < 0) ? ret : 0;
>  }
>  
>  static int ab8500_get_register(struct device *dev, u8 bank,

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 2/2 v2] mfd: ab8500-core: Return zero in get_register_interruptible()
@ 2018-10-26  8:30           ` Lee Jones
  0 siblings, 0 replies; 20+ messages in thread
From: Lee Jones @ 2018-10-26  8:30 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 25 Oct 2018, Dan Carpenter wrote:

> This function is supposed to return zero on success or negative error
> codes on error.  Unfortunately, there is a bug so it sometimes returns
> non-zero, positive numbers on success.
> 
> I noticed this bug during review and I can't test it.  It does appear
> that the return is sometimes propogated back to _regmap_read() where all
> non-zero returns are treated as failure so this may affect run time.
> 
> Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: In v1, I introduced an new error path and forgot to drop the lock.
> 
>  drivers/mfd/ab8500-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Looks okay at first blush.

I'd really like Linus to review/test though.

> diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
> index 30d09d177171..11ab17f64c64 100644
> --- a/drivers/mfd/ab8500-core.c
> +++ b/drivers/mfd/ab8500-core.c
> @@ -261,7 +261,7 @@ static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
>  	mutex_unlock(&ab8500->lock);
>  	dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
>  
> -	return ret;
> +	return (ret < 0) ? ret : 0;
>  }
>  
>  static int ab8500_get_register(struct device *dev, u8 bank,

-- 
Lee Jones [???]
Linaro Services Technical Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/2 v2] mfd: ab8500-core: Return zero in get_register_interruptible()
  2018-10-25 12:43         ` Dan Carpenter
@ 2018-10-31 13:35           ` Linus Walleij
  -1 siblings, 0 replies; 20+ messages in thread
From: Linus Walleij @ 2018-10-31 13:35 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 25, 2018 at 2:44 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:

> This function is supposed to return zero on success or negative error
> codes on error.  Unfortunately, there is a bug so it sometimes returns
> non-zero, positive numbers on success.
>
> I noticed this bug during review and I can't test it.  It does appear
> that the return is sometimes propogated back to _regmap_read() where all
> non-zero returns are treated as failure so this may affect run time.
>
> Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: In v1, I introduced an new error path and forgot to drop the lock.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

I've got some cleanup work to do with this driver.
Getting to it.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 2/2 v2] mfd: ab8500-core: Return zero in get_register_interruptible()
@ 2018-10-31 13:35           ` Linus Walleij
  0 siblings, 0 replies; 20+ messages in thread
From: Linus Walleij @ 2018-10-31 13:35 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 25, 2018 at 2:44 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:

> This function is supposed to return zero on success or negative error
> codes on error.  Unfortunately, there is a bug so it sometimes returns
> non-zero, positive numbers on success.
>
> I noticed this bug during review and I can't test it.  It does appear
> that the return is sometimes propogated back to _regmap_read() where all
> non-zero returns are treated as failure so this may affect run time.
>
> Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: In v1, I introduced an new error path and forgot to drop the lock.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

I've got some cleanup work to do with this driver.
Getting to it.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/2 v2] mfd: ab8500-core: Return zero in get_register_interruptible()
  2018-10-25 12:43         ` Dan Carpenter
@ 2018-11-13  7:41           ` Lee Jones
  -1 siblings, 0 replies; 20+ messages in thread
From: Lee Jones @ 2018-11-13  7:41 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 25 Oct 2018, Dan Carpenter wrote:

> This function is supposed to return zero on success or negative error
> codes on error.  Unfortunately, there is a bug so it sometimes returns
> non-zero, positive numbers on success.
> 
> I noticed this bug during review and I can't test it.  It does appear
> that the return is sometimes propogated back to _regmap_read() where all
> non-zero returns are treated as failure so this may affect run time.
> 
> Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: In v1, I introduced an new error path and forgot to drop the lock.
> 
>  drivers/mfd/ab8500-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 2/2 v2] mfd: ab8500-core: Return zero in get_register_interruptible()
@ 2018-11-13  7:41           ` Lee Jones
  0 siblings, 0 replies; 20+ messages in thread
From: Lee Jones @ 2018-11-13  7:41 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 25 Oct 2018, Dan Carpenter wrote:

> This function is supposed to return zero on success or negative error
> codes on error.  Unfortunately, there is a bug so it sometimes returns
> non-zero, positive numbers on success.
> 
> I noticed this bug during review and I can't test it.  It does appear
> that the return is sometimes propogated back to _regmap_read() where all
> non-zero returns are treated as failure so this may affect run time.
> 
> Fixes: 47c1697508f2 ("mfd: Align ab8500 with the abx500 interface")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: In v1, I introduced an new error path and forgot to drop the lock.
> 
>  drivers/mfd/ab8500-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

-- 
Lee Jones [???]
Linaro Services Technical Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2018-11-13  7:41 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-18  8:05 [PATCH 2/2] mfd: ab8500-core: Return zero in get_register_interruptible() Dan Carpenter
2018-10-18  8:05 ` Dan Carpenter
2018-10-18  8:05 ` Dan Carpenter
2018-10-25  8:25 ` Lee Jones
2018-10-25  8:25   ` Lee Jones
2018-10-25  8:25   ` Lee Jones
2018-10-25  8:46   ` Dan Carpenter
2018-10-25  8:46     ` Dan Carpenter
2018-10-25  8:46     ` Dan Carpenter
2018-10-25 10:10     ` Lee Jones
2018-10-25 10:10       ` Lee Jones
2018-10-25 10:10       ` Lee Jones
2018-10-25 12:43       ` [PATCH 2/2 v2] " Dan Carpenter
2018-10-25 12:43         ` Dan Carpenter
2018-10-26  8:30         ` Lee Jones
2018-10-26  8:30           ` Lee Jones
2018-10-31 13:35         ` Linus Walleij
2018-10-31 13:35           ` Linus Walleij
2018-11-13  7:41         ` Lee Jones
2018-11-13  7:41           ` Lee Jones

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.