mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: core: Fix suspicious sizeof usage
@ 2017-04-25  1:16 Orson Zhai
  2017-04-27  5:32 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Orson Zhai @ 2017-04-25  1:16 UTC (permalink / raw)
  To: jic23, knaack.h, lars, pmeerw; +Cc: linux-iio, linux-kernel, Orson Zhai

Pointer size is variours in different system, say 32bit for 4 and 64bit
for 8. The 'sizeof(infomask)' may lead to wrong bit numbers.

Signed-off-by: Orson Zhai <orson.zhai@spreadtrum.com>
---
 drivers/iio/industrialio-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 3ff91e0..795f53c 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1089,7 +1089,7 @@ static int iio_device_add_info_mask_type(struct iio_dev *indio_dev,
 {
 	int i, ret, attrcount = 0;
 
-	for_each_set_bit(i, infomask, sizeof(infomask)*8) {
+	for_each_set_bit(i, infomask, sizeof(*infomask)*8) {
 		if (i >= ARRAY_SIZE(iio_chan_info_postfix))
 			return -EINVAL;
 		ret = __iio_add_chan_devattr(iio_chan_info_postfix[i],
@@ -1118,7 +1118,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev,
 	int i, ret, attrcount = 0;
 	char *avail_postfix;
 
-	for_each_set_bit(i, infomask, sizeof(infomask) * 8) {
+	for_each_set_bit(i, infomask, sizeof(*infomask) * 8) {
 		avail_postfix = kasprintf(GFP_KERNEL,
 					  "%s_available",
 					  iio_chan_info_postfix[i]);
-- 
1.9.1

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

* Re: [PATCH] iio: core: Fix suspicious sizeof usage
  2017-04-25  1:16 [PATCH] iio: core: Fix suspicious sizeof usage Orson Zhai
@ 2017-04-27  5:32 ` Jonathan Cameron
  2017-04-27  7:29   ` Orson Zhai
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2017-04-27  5:32 UTC (permalink / raw)
  To: Orson Zhai, knaack.h, lars, pmeerw; +Cc: linux-iio, linux-kernel

On 25/04/17 02:16, Orson Zhai wrote:
> Pointer size is variours in different system, say 32bit for 4 and 64bit
> for 8. The 'sizeof(infomask)' may lead to wrong bit numbers.
> 
> Signed-off-by: Orson Zhai <orson.zhai@spreadtrum.com>
That's certainly been there a while.  oops.

Anyhow, whilst clearly garbage, it doesn't actually have an effect
at the moment due to the relatively small number of bits that can be
set and the fact this is limited by 32 bit platforms anyway.

So applied to the togreg branch of iio.git and pushed out as
testing for the auto builders to play with it.

Thanks,

Jonathan
> ---
>  drivers/iio/industrialio-core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 3ff91e0..795f53c 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1089,7 +1089,7 @@ static int iio_device_add_info_mask_type(struct iio_dev *indio_dev,
>  {
>  	int i, ret, attrcount = 0;
>  
> -	for_each_set_bit(i, infomask, sizeof(infomask)*8) {
> +	for_each_set_bit(i, infomask, sizeof(*infomask)*8) {
>  		if (i >= ARRAY_SIZE(iio_chan_info_postfix))
>  			return -EINVAL;
>  		ret = __iio_add_chan_devattr(iio_chan_info_postfix[i],
> @@ -1118,7 +1118,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev,
>  	int i, ret, attrcount = 0;
>  	char *avail_postfix;
>  
> -	for_each_set_bit(i, infomask, sizeof(infomask) * 8) {
> +	for_each_set_bit(i, infomask, sizeof(*infomask) * 8) {
>  		avail_postfix = kasprintf(GFP_KERNEL,
>  					  "%s_available",
>  					  iio_chan_info_postfix[i]);
> 

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

* Re: [PATCH] iio: core: Fix suspicious sizeof usage
  2017-04-27  5:32 ` Jonathan Cameron
@ 2017-04-27  7:29   ` Orson Zhai
  0 siblings, 0 replies; 3+ messages in thread
From: Orson Zhai @ 2017-04-27  7:29 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: knaack.h, lars, pmeerw, linux-iio, linux-kernel

On Thu, Apr 27, 2017 at 06:32:22AM +0100, Jonathan Cameron wrote:
> On 25/04/17 02:16, Orson Zhai wrote:
> > Pointer size is variours in different system, say 32bit for 4 and 64bit
> > for 8. The 'sizeof(infomask)' may lead to wrong bit numbers.
> > 
> > Signed-off-by: Orson Zhai <orson.zhai@spreadtrum.com>
> That's certainly been there a while.  oops.
> 
> Anyhow, whilst clearly garbage, it doesn't actually have an effect
> at the moment due to the relatively small number of bits that can be
> set and the fact this is limited by 32 bit platforms anyway.
> 
> So applied to the togreg branch of iio.git and pushed out as
> testing for the auto builders to play with it.

Thank you!

-Orson

> 
> Thanks,
> 
> Jonathan
> > ---
> >  drivers/iio/industrialio-core.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> > index 3ff91e0..795f53c 100644
> > --- a/drivers/iio/industrialio-core.c
> > +++ b/drivers/iio/industrialio-core.c
> > @@ -1089,7 +1089,7 @@ static int iio_device_add_info_mask_type(struct iio_dev *indio_dev,
> >  {
> >  	int i, ret, attrcount = 0;
> >  
> > -	for_each_set_bit(i, infomask, sizeof(infomask)*8) {
> > +	for_each_set_bit(i, infomask, sizeof(*infomask)*8) {
> >  		if (i >= ARRAY_SIZE(iio_chan_info_postfix))
> >  			return -EINVAL;
> >  		ret = __iio_add_chan_devattr(iio_chan_info_postfix[i],
> > @@ -1118,7 +1118,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev,
> >  	int i, ret, attrcount = 0;
> >  	char *avail_postfix;
> >  
> > -	for_each_set_bit(i, infomask, sizeof(infomask) * 8) {
> > +	for_each_set_bit(i, infomask, sizeof(*infomask) * 8) {
> >  		avail_postfix = kasprintf(GFP_KERNEL,
> >  					  "%s_available",
> >  					  iio_chan_info_postfix[i]);
> > 
> 

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

end of thread, other threads:[~2017-04-27  7:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-25  1:16 [PATCH] iio: core: Fix suspicious sizeof usage Orson Zhai
2017-04-27  5:32 ` Jonathan Cameron
2017-04-27  7:29   ` Orson Zhai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®