* [PATCH] staging/iio: Use correct argument for sizeof
@ 2013-01-21 21:14 Peter Huewe
2013-01-22 6:43 ` Dan Carpenter
2013-01-22 11:58 ` Jonathan Cameron
0 siblings, 2 replies; 6+ messages in thread
From: Peter Huewe @ 2013-01-21 21:14 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Greg Kroah-Hartman, linux-iio, devel, linux-kernel, Peter Huewe
found with coccicheck
sizeof when applied to a pointer typed expression gives the size of
the pointer
The semantic patch that makes this output is available
in scripts/coccinelle/misc/noderef.cocci.
More information about semantic patching is available at
http://coccinelle.lip6.fr/
Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
---
drivers/staging/iio/iio_hwmon.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
index c7a5f97..97ad645 100644
--- a/drivers/staging/iio/iio_hwmon.c
+++ b/drivers/staging/iio/iio_hwmon.c
@@ -93,7 +93,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
while (st->channels[st->num_channels].indio_dev)
st->num_channels++;
- st->attrs = kzalloc(sizeof(st->attrs) * (st->num_channels + 1),
+ st->attrs = kzalloc(sizeof(*st->attrs) * (st->num_channels + 1),
GFP_KERNEL);
if (st->attrs == NULL) {
ret = -ENOMEM;
--
1.7.8.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] staging/iio: Use correct argument for sizeof
2013-01-21 21:14 [PATCH] staging/iio: Use correct argument for sizeof Peter Huewe
@ 2013-01-22 6:43 ` Dan Carpenter
2013-01-22 7:02 ` Dan Carpenter
2013-01-22 8:02 ` Lars-Peter Clausen
2013-01-22 11:58 ` Jonathan Cameron
1 sibling, 2 replies; 6+ messages in thread
From: Dan Carpenter @ 2013-01-22 6:43 UTC (permalink / raw)
To: Peter Huewe
Cc: Jonathan Cameron, linux-iio, Greg Kroah-Hartman, devel, linux-kernel
On Mon, Jan 21, 2013 at 10:14:02PM +0100, Peter Huewe wrote:
> found with coccicheck
> sizeof when applied to a pointer typed expression gives the size of
> the pointer
>
The original code is correct, in this case. We're storing an array
of pointers and the last element in the array is a NULL.
> The semantic patch that makes this output is available
> in scripts/coccinelle/misc/noderef.cocci.
>
> More information about semantic patching is available at
> http://coccinelle.lip6.fr/
Can you remove those two boiler plate lines? We all have google.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] staging/iio: Use correct argument for sizeof
2013-01-22 6:43 ` Dan Carpenter
@ 2013-01-22 7:02 ` Dan Carpenter
2013-01-22 8:02 ` Lars-Peter Clausen
1 sibling, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2013-01-22 7:02 UTC (permalink / raw)
To: Peter Huewe
Cc: linux-iio, Greg Kroah-Hartman, devel, Jonathan Cameron, linux-kernel
These two lines are what I meant. Not the other stuff before.
> > More information about semantic patching is available at
> > http://coccinelle.lip6.fr/
regards,
dan carpenter
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] staging/iio: Use correct argument for sizeof
2013-01-22 6:43 ` Dan Carpenter
2013-01-22 7:02 ` Dan Carpenter
@ 2013-01-22 8:02 ` Lars-Peter Clausen
2013-01-22 8:05 ` Dan Carpenter
1 sibling, 1 reply; 6+ messages in thread
From: Lars-Peter Clausen @ 2013-01-22 8:02 UTC (permalink / raw)
To: Dan Carpenter
Cc: Peter Huewe, Jonathan Cameron, linux-iio, Greg Kroah-Hartman,
devel, linux-kernel
On 01/22/2013 07:43 AM, Dan Carpenter wrote:
> On Mon, Jan 21, 2013 at 10:14:02PM +0100, Peter Huewe wrote:
>> found with coccicheck
>> sizeof when applied to a pointer typed expression gives the size of
>> the pointer
>>
>
> The original code is correct, in this case. We're storing an array
> of pointers and the last element in the array is a NULL.
>
The patch changed sizeof(st->attrs) to sizeof(*st->attrs). The type of
st->attrs is struct attribute **, so both sizeofs return the same value (the
size of an pointer) and the code happens to work, still the later is
semantically more correct.
>> The semantic patch that makes this output is available
>> in scripts/coccinelle/misc/noderef.cocci.
>>
>> More information about semantic patching is available at
>> http://coccinelle.lip6.fr/
>
> Can you remove those two boiler plate lines? We all have google.
It would be nice to have a pointer to the specific cocci script used to
generate the patch though.
- Lars
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] staging/iio: Use correct argument for sizeof
2013-01-22 8:02 ` Lars-Peter Clausen
@ 2013-01-22 8:05 ` Dan Carpenter
0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2013-01-22 8:05 UTC (permalink / raw)
To: Lars-Peter Clausen
Cc: devel, linux-iio, Greg Kroah-Hartman, linux-kernel, Jonathan Cameron
On Tue, Jan 22, 2013 at 09:02:05AM +0100, Lars-Peter Clausen wrote:
> On 01/22/2013 07:43 AM, Dan Carpenter wrote:
> > On Mon, Jan 21, 2013 at 10:14:02PM +0100, Peter Huewe wrote:
> >> found with coccicheck
> >> sizeof when applied to a pointer typed expression gives the size of
> >> the pointer
> >>
> >
> > The original code is correct, in this case. We're storing an array
> > of pointers and the last element in the array is a NULL.
> >
>
> The patch changed sizeof(st->attrs) to sizeof(*st->attrs). The type of
> st->attrs is struct attribute **, so both sizeofs return the same value (the
> size of an pointer) and the code happens to work, still the later is
> semantically more correct.
>
Yeah. You're right, my bad. The patch is fine.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] staging/iio: Use correct argument for sizeof
2013-01-21 21:14 [PATCH] staging/iio: Use correct argument for sizeof Peter Huewe
2013-01-22 6:43 ` Dan Carpenter
@ 2013-01-22 11:58 ` Jonathan Cameron
1 sibling, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2013-01-22 11:58 UTC (permalink / raw)
To: Peter Huewe
Cc: Jonathan Cameron, Greg Kroah-Hartman, linux-iio, devel, linux-kernel
On 01/21/2013 09:14 PM, Peter Huewe wrote:
> found with coccicheck
> sizeof when applied to a pointer typed expression gives the size of
> the pointer
>
> The semantic patch that makes this output is available
> in scripts/coccinelle/misc/noderef.cocci.
>
> More information about semantic patching is available at
> http://coccinelle.lip6.fr/
>
> Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Added to togreg branch of iio.git
Thanks,
> ---
> drivers/staging/iio/iio_hwmon.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
> index c7a5f97..97ad645 100644
> --- a/drivers/staging/iio/iio_hwmon.c
> +++ b/drivers/staging/iio/iio_hwmon.c
> @@ -93,7 +93,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
> while (st->channels[st->num_channels].indio_dev)
> st->num_channels++;
>
> - st->attrs = kzalloc(sizeof(st->attrs) * (st->num_channels + 1),
> + st->attrs = kzalloc(sizeof(*st->attrs) * (st->num_channels + 1),
> GFP_KERNEL);
> if (st->attrs == NULL) {
> ret = -ENOMEM;
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-01-22 11:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-21 21:14 [PATCH] staging/iio: Use correct argument for sizeof Peter Huewe
2013-01-22 6:43 ` Dan Carpenter
2013-01-22 7:02 ` Dan Carpenter
2013-01-22 8:02 ` Lars-Peter Clausen
2013-01-22 8:05 ` Dan Carpenter
2013-01-22 11:58 ` Jonathan Cameron
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).