linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] power: battery: pointer math issue in gab_probe()
@ 2012-09-29  7:13 Dan Carpenter
  2012-09-30  4:08 ` anish kumar
  2012-11-17  2:36 ` Anton Vorontsov
  0 siblings, 2 replies; 7+ messages in thread
From: Dan Carpenter @ 2012-09-29  7:13 UTC (permalink / raw)
  To: Anton Vorontsov, anish kumar
  Cc: David Woodhouse, linux-kernel, kernel-janitors

psy->properties is an enum (32 bit type) so adding sizeof() puts us
four times further along than we intended.  It should be cast to a char
pointer before doing the math.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Casting to void * would also work on GCC, at least.

diff --git a/drivers/power/generic-adc-battery.c b/drivers/power/generic-adc-battery.c
index 9bdf444..776f118 100644
--- a/drivers/power/generic-adc-battery.c
+++ b/drivers/power/generic-adc-battery.c
@@ -279,7 +279,8 @@ static int __devinit gab_probe(struct platform_device *pdev)
 	}
 
 	memcpy(psy->properties, gab_props, sizeof(gab_props));
-	properties = psy->properties + sizeof(gab_props);
+	properties = (enum power_supply_property *)
+				((char *)psy->properties + sizeof(gab_props));
 
 	/*
 	 * getting channel from iio and copying the battery properties

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

* Re: [patch] power: battery: pointer math issue in gab_probe()
  2012-09-29  7:13 [patch] power: battery: pointer math issue in gab_probe() Dan Carpenter
@ 2012-09-30  4:08 ` anish kumar
  2012-09-30  7:06   ` Dan Carpenter
  2012-11-05 12:34   ` anish kumar
  2012-11-17  2:36 ` Anton Vorontsov
  1 sibling, 2 replies; 7+ messages in thread
From: anish kumar @ 2012-09-30  4:08 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Anton Vorontsov, David Woodhouse, linux-kernel, kernel-janitors

On Sat, 2012-09-29 at 10:13 +0300, Dan Carpenter wrote:
> psy->properties is an enum (32 bit type) so adding sizeof() puts us
> four times further along than we intended.  It should be cast to a char
> pointer before doing the math.
You really read this driver to find out this one.
Good one.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> Casting to void * would also work on GCC, at least.
> 
> diff --git a/drivers/power/generic-adc-battery.c b/drivers/power/generic-adc-battery.c
> index 9bdf444..776f118 100644
> --- a/drivers/power/generic-adc-battery.c
> +++ b/drivers/power/generic-adc-battery.c
> @@ -279,7 +279,8 @@ static int __devinit gab_probe(struct platform_device *pdev)
>  	}
>  
>  	memcpy(psy->properties, gab_props, sizeof(gab_props));
> -	properties = psy->properties + sizeof(gab_props);
> +	properties = (enum power_supply_property *)
> +				((char *)psy->properties + sizeof(gab_props));
>  
>  	/*
>  	 * getting channel from iio and copying the battery properties



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

* Re: [patch] power: battery: pointer math issue in gab_probe()
  2012-09-30  4:08 ` anish kumar
@ 2012-09-30  7:06   ` Dan Carpenter
  2012-11-05 12:34   ` anish kumar
  1 sibling, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2012-09-30  7:06 UTC (permalink / raw)
  To: anish kumar
  Cc: Anton Vorontsov, David Woodhouse, linux-kernel, kernel-janitors

On Sun, Sep 30, 2012 at 09:38:45AM +0530, anish kumar wrote:
> On Sat, 2012-09-29 at 10:13 +0300, Dan Carpenter wrote:
> > psy->properties is an enum (32 bit type) so adding sizeof() puts us
> > four times further along than we intended.  It should be cast to a char
> > pointer before doing the math.
> You really read this driver to find out this one.
> Good one.

Nah.  It's a static checker thing with Smatch
(http://smatch.sf.net).  When you add pointer + sizeof(), the
pointer should always be char.

regards,
dan carpenter


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

* Re: [patch] power: battery: pointer math issue in gab_probe()
  2012-09-30  4:08 ` anish kumar
  2012-09-30  7:06   ` Dan Carpenter
@ 2012-11-05 12:34   ` anish kumar
  2012-11-05 13:09     ` Dan Carpenter
  1 sibling, 1 reply; 7+ messages in thread
From: anish kumar @ 2012-11-05 12:34 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Anton Vorontsov, David Woodhouse, linux-kernel, kernel-janitors

Hello Dan,

Is this patch of yours picked up by anyone?
On Sun, 2012-09-30 at 09:38 +0530, anish kumar wrote:
> On Sat, 2012-09-29 at 10:13 +0300, Dan Carpenter wrote:
> > psy->properties is an enum (32 bit type) so adding sizeof() puts us
> > four times further along than we intended.  It should be cast to a char
> > pointer before doing the math.
> You really read this driver to find out this one.
> Good one.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > Casting to void * would also work on GCC, at least.
> > 
> > diff --git a/drivers/power/generic-adc-battery.c b/drivers/power/generic-adc-battery.c
> > index 9bdf444..776f118 100644
> > --- a/drivers/power/generic-adc-battery.c
> > +++ b/drivers/power/generic-adc-battery.c
> > @@ -279,7 +279,8 @@ static int __devinit gab_probe(struct platform_device *pdev)
> >  	}
> >  
> >  	memcpy(psy->properties, gab_props, sizeof(gab_props));
> > -	properties = psy->properties + sizeof(gab_props);
> > +	properties = (enum power_supply_property *)
> > +				((char *)psy->properties + sizeof(gab_props));
> >  
> >  	/*
> >  	 * getting channel from iio and copying the battery properties
> 



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

* Re: [patch] power: battery: pointer math issue in gab_probe()
  2012-11-05 12:34   ` anish kumar
@ 2012-11-05 13:09     ` Dan Carpenter
  2012-11-05 18:37       ` Anton Vorontsov
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Carpenter @ 2012-11-05 13:09 UTC (permalink / raw)
  To: anish kumar
  Cc: Anton Vorontsov, David Woodhouse, linux-kernel, kernel-janitors

On Mon, Nov 05, 2012 at 09:34:21PM +0900, anish kumar wrote:
> Hello Dan,
> 
> Is this patch of yours picked up by anyone?

David this should go through you?

regards,
dan carpenter


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

* Re: [patch] power: battery: pointer math issue in gab_probe()
  2012-11-05 13:09     ` Dan Carpenter
@ 2012-11-05 18:37       ` Anton Vorontsov
  0 siblings, 0 replies; 7+ messages in thread
From: Anton Vorontsov @ 2012-11-05 18:37 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: anish kumar, David Woodhouse, linux-kernel, kernel-janitors

On Mon, Nov 05, 2012 at 04:09:45PM +0300, Dan Carpenter wrote:
> On Mon, Nov 05, 2012 at 09:34:21PM +0900, anish kumar wrote:
> > Hello Dan,
> > 
> > Is this patch of yours picked up by anyone?
> 
> David this should go through you?

I'll merge it soon. Sorry for the delay, quite busy lately. :-/

Thanks!
Anton.

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

* Re: [patch] power: battery: pointer math issue in gab_probe()
  2012-09-29  7:13 [patch] power: battery: pointer math issue in gab_probe() Dan Carpenter
  2012-09-30  4:08 ` anish kumar
@ 2012-11-17  2:36 ` Anton Vorontsov
  1 sibling, 0 replies; 7+ messages in thread
From: Anton Vorontsov @ 2012-11-17  2:36 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: anish kumar, David Woodhouse, linux-kernel, kernel-janitors

On Sat, Sep 29, 2012 at 10:13:46AM +0300, Dan Carpenter wrote:
> psy->properties is an enum (32 bit type) so adding sizeof() puts us
> four times further along than we intended.  It should be cast to a char
> pointer before doing the math.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> Casting to void * would also work on GCC, at least.

Applied, thanks a lot!

> 
> diff --git a/drivers/power/generic-adc-battery.c b/drivers/power/generic-adc-battery.c
> index 9bdf444..776f118 100644
> --- a/drivers/power/generic-adc-battery.c
> +++ b/drivers/power/generic-adc-battery.c
> @@ -279,7 +279,8 @@ static int __devinit gab_probe(struct platform_device *pdev)
>  	}
>  
>  	memcpy(psy->properties, gab_props, sizeof(gab_props));
> -	properties = psy->properties + sizeof(gab_props);
> +	properties = (enum power_supply_property *)
> +				((char *)psy->properties + sizeof(gab_props));
>  
>  	/*
>  	 * getting channel from iio and copying the battery properties

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

end of thread, other threads:[~2012-11-17  2:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-29  7:13 [patch] power: battery: pointer math issue in gab_probe() Dan Carpenter
2012-09-30  4:08 ` anish kumar
2012-09-30  7:06   ` Dan Carpenter
2012-11-05 12:34   ` anish kumar
2012-11-05 13:09     ` Dan Carpenter
2012-11-05 18:37       ` Anton Vorontsov
2012-11-17  2:36 ` Anton Vorontsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).