* [PATCH 07/30] mtd: Get rid of pointless cast of kzalloc() return value in AT26xxx driver
[not found] <1554af80879a7ef2f78a4d654f23c248203500d9.1187912217.git.jesper.juhl@gmail.com>
@ 2007-08-23 23:50 ` Jesper Juhl
2007-08-23 23:51 ` [PATCH 08/30] mtd: Avoid a pointless kmalloc() return value cast in TQM8xxL mapping handling code Jesper Juhl
2007-08-23 23:52 ` [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c Jesper Juhl
2 siblings, 0 replies; 15+ messages in thread
From: Jesper Juhl @ 2007-08-23 23:50 UTC (permalink / raw)
To: Linux Kernel Mailing List
Cc: linux-mtd, Jesper Juhl, Hans J Koch, David Woodhouse
kzalloc() returns a void pointer - no need to cast it in
drivers/mtd/devices/at91_dataflash26.c::add_dataflash()
Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
---
drivers/mtd/devices/at91_dataflash26.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/devices/at91_dataflash26.c b/drivers/mtd/devices/at91_dataflash26.c
index 64ce37f..9c4aac4 100644
--- a/drivers/mtd/devices/at91_dataflash26.c
+++ b/drivers/mtd/devices/at91_dataflash26.c
@@ -360,8 +360,7 @@ static int __init add_dataflash(int channel, char *name, int nr_pages,
device->read = at91_dataflash26_read;
device->write = at91_dataflash26_write;
- priv = (struct dataflash_local *)kzalloc(sizeof(struct dataflash_local),
- GFP_KERNEL);
+ priv = kzalloc(sizeof(struct dataflash_local), GFP_KERNEL);
if (!priv) {
kfree(device);
return -ENOMEM;
--
1.5.2.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 08/30] mtd: Avoid a pointless kmalloc() return value cast in TQM8xxL mapping handling code
[not found] <1554af80879a7ef2f78a4d654f23c248203500d9.1187912217.git.jesper.juhl@gmail.com>
2007-08-23 23:50 ` [PATCH 07/30] mtd: Get rid of pointless cast of kzalloc() return value in AT26xxx driver Jesper Juhl
@ 2007-08-23 23:51 ` Jesper Juhl
2007-08-23 23:52 ` [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c Jesper Juhl
2 siblings, 0 replies; 15+ messages in thread
From: Jesper Juhl @ 2007-08-23 23:51 UTC (permalink / raw)
To: Linux Kernel Mailing List
Cc: Kirk Lee, linux-mtd, Jesper Juhl, David Woodhouse
In drivers/mtd/maps/tqm8xxl.c::init_tqm_mtd() it is pointless casting
the return value of kmalloc() since it returns void*.
Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
---
drivers/mtd/maps/tqm8xxl.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/maps/tqm8xxl.c b/drivers/mtd/maps/tqm8xxl.c
index 37e4ded..1d75ce4 100644
--- a/drivers/mtd/maps/tqm8xxl.c
+++ b/drivers/mtd/maps/tqm8xxl.c
@@ -141,8 +141,7 @@ int __init init_tqm_mtd(void)
goto error_mem;
}
- map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL);
-
+ map_banks[idx]->name = kmalloc(16, GFP_KERNEL);
if (!map_banks[idx]->name) {
ret = -ENOMEM;
/* FIXME: What if some MTD devices were probed already? */
--
1.5.2.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
[not found] <1554af80879a7ef2f78a4d654f23c248203500d9.1187912217.git.jesper.juhl@gmail.com>
2007-08-23 23:50 ` [PATCH 07/30] mtd: Get rid of pointless cast of kzalloc() return value in AT26xxx driver Jesper Juhl
2007-08-23 23:51 ` [PATCH 08/30] mtd: Avoid a pointless kmalloc() return value cast in TQM8xxL mapping handling code Jesper Juhl
@ 2007-08-23 23:52 ` Jesper Juhl
2007-08-24 10:41 ` Denys Vlasenko
2 siblings, 1 reply; 15+ messages in thread
From: Jesper Juhl @ 2007-08-23 23:52 UTC (permalink / raw)
To: Linux Kernel Mailing List; +Cc: linux-mtd, Jesper Juhl, David Woodhouse
kmalloc() returns a void pointer.
No need to cast it.
Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
---
drivers/mtd/maps/pmcmsp-flash.c | 13 +++++--------
1 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/mtd/maps/pmcmsp-flash.c b/drivers/mtd/maps/pmcmsp-flash.c
index 7e0377e..dfdb120 100644
--- a/drivers/mtd/maps/pmcmsp-flash.c
+++ b/drivers/mtd/maps/pmcmsp-flash.c
@@ -73,12 +73,9 @@ int __init init_msp_flash(void)
return -ENXIO;
printk(KERN_NOTICE "Found %d PMC flash devices\n", fcnt);
- msp_flash = (struct mtd_info **)kmalloc(
- fcnt * sizeof(struct map_info *), GFP_KERNEL);
- msp_parts = (struct mtd_partition **)kmalloc(
- fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
- msp_maps = (struct map_info *)kmalloc(
- fcnt * sizeof(struct mtd_info), GFP_KERNEL);
+ msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL);
+ msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
+ msp_maps = kmalloc(fcnt * sizeof(struct mtd_info), GFP_KERNEL);
memset(msp_maps, 0, fcnt * sizeof(struct mtd_info));
/* loop over the flash devices, initializing each */
@@ -95,8 +92,8 @@ int __init init_msp_flash(void)
continue;
}
- msp_parts[i] = (struct mtd_partition *)kmalloc(
- pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
+ msp_parts[i] = kmalloc(pcnt * sizeof(struct mtd_partition),
+ GFP_KERNEL);
memset(msp_parts[i], 0, pcnt * sizeof(struct mtd_partition));
/* now initialize the devices proper */
--
1.5.2.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
2007-08-23 23:52 ` [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c Jesper Juhl
@ 2007-08-24 10:41 ` Denys Vlasenko
2007-08-24 10:43 ` Robert P. J. Day
2007-08-24 10:48 ` Jesper Juhl
0 siblings, 2 replies; 15+ messages in thread
From: Denys Vlasenko @ 2007-08-24 10:41 UTC (permalink / raw)
To: Jesper Juhl; +Cc: linux-mtd, David Woodhouse, Linux Kernel Mailing List
On Friday 24 August 2007 00:52, Jesper Juhl wrote:
> kmalloc() returns a void pointer.
> No need to cast it.
> - msp_flash = (struct mtd_info **)kmalloc(
> - fcnt * sizeof(struct map_info *), GFP_KERNEL);
> - msp_parts = (struct mtd_partition **)kmalloc(
> - fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
> - msp_maps = (struct map_info *)kmalloc(
> - fcnt * sizeof(struct mtd_info), GFP_KERNEL);
> + msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL);
> + msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
> + msp_maps = kmalloc(fcnt * sizeof(struct mtd_info), GFP_KERNEL);
> memset(msp_maps, 0, fcnt * sizeof(struct mtd_info));
This one wants kzalloc.
> - msp_parts[i] = (struct mtd_partition *)kmalloc(
> - pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
> + msp_parts[i] = kmalloc(pcnt * sizeof(struct mtd_partition),
> + GFP_KERNEL);
> memset(msp_parts[i], 0, pcnt * sizeof(struct mtd_partition));
>
> /* now initialize the devices proper */
Same
--
vda
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
2007-08-24 10:41 ` Denys Vlasenko
@ 2007-08-24 10:43 ` Robert P. J. Day
2007-08-25 22:27 ` Jesper Juhl
2007-08-24 10:48 ` Jesper Juhl
1 sibling, 1 reply; 15+ messages in thread
From: Robert P. J. Day @ 2007-08-24 10:43 UTC (permalink / raw)
To: Denys Vlasenko
Cc: David Woodhouse, Jesper Juhl, linux-mtd,
Linux Kernel Mailing List
On Fri, 24 Aug 2007, Denys Vlasenko wrote:
> On Friday 24 August 2007 00:52, Jesper Juhl wrote:
> > kmalloc() returns a void pointer.
> > No need to cast it.
>
> > - msp_flash = (struct mtd_info **)kmalloc(
> > - fcnt * sizeof(struct map_info *), GFP_KERNEL);
> > - msp_parts = (struct mtd_partition **)kmalloc(
> > - fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
> > - msp_maps = (struct map_info *)kmalloc(
> > - fcnt * sizeof(struct mtd_info), GFP_KERNEL);
> > + msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL);
> > + msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
> > + msp_maps = kmalloc(fcnt * sizeof(struct mtd_info), GFP_KERNEL);
> > memset(msp_maps, 0, fcnt * sizeof(struct mtd_info));
>
> This one wants kzalloc.
>
> > - msp_parts[i] = (struct mtd_partition *)kmalloc(
> > - pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
> > + msp_parts[i] = kmalloc(pcnt * sizeof(struct mtd_partition),
> > + GFP_KERNEL);
> > memset(msp_parts[i], 0, pcnt * sizeof(struct mtd_partition));
> >
> > /* now initialize the devices proper */
>
> Same
actually, i would think kcalloc would be more appropriate here, no?
rday
--
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://crashcourse.ca
========================================================================
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
2007-08-24 10:41 ` Denys Vlasenko
2007-08-24 10:43 ` Robert P. J. Day
@ 2007-08-24 10:48 ` Jesper Juhl
1 sibling, 0 replies; 15+ messages in thread
From: Jesper Juhl @ 2007-08-24 10:48 UTC (permalink / raw)
To: Denys Vlasenko; +Cc: linux-mtd, David Woodhouse, Linux Kernel Mailing List
On 24/08/07, Denys Vlasenko <vda.linux@googlemail.com> wrote:
> On Friday 24 August 2007 00:52, Jesper Juhl wrote:
> > kmalloc() returns a void pointer.
> > No need to cast it.
>
> > - msp_flash = (struct mtd_info **)kmalloc(
> > - fcnt * sizeof(struct map_info *), GFP_KERNEL);
> > - msp_parts = (struct mtd_partition **)kmalloc(
> > - fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
> > - msp_maps = (struct map_info *)kmalloc(
> > - fcnt * sizeof(struct mtd_info), GFP_KERNEL);
> > + msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL);
> > + msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
> > + msp_maps = kmalloc(fcnt * sizeof(struct mtd_info), GFP_KERNEL);
> > memset(msp_maps, 0, fcnt * sizeof(struct mtd_info));
>
> This one wants kzalloc.
>
> > - msp_parts[i] = (struct mtd_partition *)kmalloc(
> > - pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
> > + msp_parts[i] = kmalloc(pcnt * sizeof(struct mtd_partition),
> > + GFP_KERNEL);
> > memset(msp_parts[i], 0, pcnt * sizeof(struct mtd_partition));
> >
> > /* now initialize the devices proper */
>
> Same
Ok, thank you for that feedback.
I'll respin the patch with that change when I resubmit all the ones
that don't get picked up (probably next week).
--
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
2007-08-24 10:43 ` Robert P. J. Day
@ 2007-08-25 22:27 ` Jesper Juhl
2007-08-25 23:59 ` Robert P. J. Day
0 siblings, 1 reply; 15+ messages in thread
From: Jesper Juhl @ 2007-08-25 22:27 UTC (permalink / raw)
To: Robert P. J. Day
Cc: Denys Vlasenko, David Woodhouse, linux-mtd,
Linux Kernel Mailing List
On 24/08/07, Robert P. J. Day <rpjday@mindspring.com> wrote:
> On Fri, 24 Aug 2007, Denys Vlasenko wrote:
>
> > On Friday 24 August 2007 00:52, Jesper Juhl wrote:
> > > kmalloc() returns a void pointer.
> > > No need to cast it.
> >
> > > - msp_flash = (struct mtd_info **)kmalloc(
> > > - fcnt * sizeof(struct map_info *), GFP_KERNEL);
> > > - msp_parts = (struct mtd_partition **)kmalloc(
> > > - fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
> > > - msp_maps = (struct map_info *)kmalloc(
> > > - fcnt * sizeof(struct mtd_info), GFP_KERNEL);
> > > + msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL);
> > > + msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
> > > + msp_maps = kmalloc(fcnt * sizeof(struct mtd_info), GFP_KERNEL);
> > > memset(msp_maps, 0, fcnt * sizeof(struct mtd_info));
> >
> > This one wants kzalloc.
> >
> > > - msp_parts[i] = (struct mtd_partition *)kmalloc(
> > > - pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
> > > + msp_parts[i] = kmalloc(pcnt * sizeof(struct mtd_partition),
> > > + GFP_KERNEL);
> > > memset(msp_parts[i], 0, pcnt * sizeof(struct mtd_partition));
> > >
> > > /* now initialize the devices proper */
> >
> > Same
>
> actually, i would think kcalloc would be more appropriate here, no?
>
Why?
msp_parts[i] = kzalloc(pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
seems better to me than
msp_parts[i] = kcalloc(1, pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
--
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
2007-08-25 22:27 ` Jesper Juhl
@ 2007-08-25 23:59 ` Robert P. J. Day
2007-08-26 0:28 ` Jesper Juhl
0 siblings, 1 reply; 15+ messages in thread
From: Robert P. J. Day @ 2007-08-25 23:59 UTC (permalink / raw)
To: Jesper Juhl
Cc: Denys Vlasenko, linux-mtd, David Woodhouse,
Linux Kernel Mailing List
On Sun, 26 Aug 2007, Jesper Juhl wrote:
> On 24/08/07, Robert P. J. Day <rpjday@mindspring.com> wrote:
> > actually, i would think kcalloc would be more appropriate here, no?
> >
>
> Why?
>
> msp_parts[i] = kzalloc(pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
>
> seems better to me than
>
> msp_parts[i] = kcalloc(1, pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
i was thinking more along the lines of
msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition), GFP_KERNEL);
which was kind of the obvious implication, no? unless there's a
reason kcalloc() wouldn't work here, this is pretty much what
kcalloc() was designed for.
rday
--
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://crashcourse.ca
========================================================================
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
2007-08-26 0:28 ` Jesper Juhl
@ 2007-08-26 0:23 ` Robert P. J. Day
2007-08-26 0:36 ` Jesper Juhl
2007-08-26 14:28 ` Denys Vlasenko
0 siblings, 2 replies; 15+ messages in thread
From: Robert P. J. Day @ 2007-08-26 0:23 UTC (permalink / raw)
To: Jesper Juhl
Cc: Denys Vlasenko, David Woodhouse, linux-mtd,
Linux Kernel Mailing List
On Sun, 26 Aug 2007, Jesper Juhl wrote:
> On 26/08/07, Robert P. J. Day <rpjday@mindspring.com> wrote:
> > i was thinking more along the lines of
> >
> > msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition), GFP_KERNEL);
> >
> > which was kind of the obvious implication, no?
>
> I guess
>
> > unless there's a reason kcalloc() wouldn't work here, this is
> > pretty much what kcalloc() was designed for.
> >
> When Denys brought up the zeroing thing and mentioned kzalloc() I
> did consider kcalloc() instead, but kzalloc() makes this allocation
> nicely look like the preceding ones visually and I couldn't convince
> myself that kcalloc() would give us any real benefit here.
>
> What exactely would using kcalloc() over kzalloc() here buy us?
technically, nothing. but if you're not going to use kcalloc() when
you're explicitly allocating an array of identical objects (that you
want zero-filled, as a bonus), then what's the point of ever having
defined a kcalloc() routine in the first place?
rday
--
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://crashcourse.ca
========================================================================
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
2007-08-25 23:59 ` Robert P. J. Day
@ 2007-08-26 0:28 ` Jesper Juhl
2007-08-26 0:23 ` Robert P. J. Day
0 siblings, 1 reply; 15+ messages in thread
From: Jesper Juhl @ 2007-08-26 0:28 UTC (permalink / raw)
To: Robert P. J. Day
Cc: Denys Vlasenko, linux-mtd, David Woodhouse,
Linux Kernel Mailing List
On 26/08/07, Robert P. J. Day <rpjday@mindspring.com> wrote:
> On Sun, 26 Aug 2007, Jesper Juhl wrote:
>
> > On 24/08/07, Robert P. J. Day <rpjday@mindspring.com> wrote:
>
> > > actually, i would think kcalloc would be more appropriate here, no?
> > >
> >
> > Why?
> >
> > msp_parts[i] = kzalloc(pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
> >
> > seems better to me than
> >
> > msp_parts[i] = kcalloc(1, pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
>
> i was thinking more along the lines of
>
> msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition), GFP_KERNEL);
>
> which was kind of the obvious implication, no?
I guess
> unless there's a
> reason kcalloc() wouldn't work here, this is pretty much what
> kcalloc() was designed for.
>
When Denys brought up the zeroing thing and mentioned kzalloc() I did
consider kcalloc() instead, but kzalloc() makes this allocation nicely
look like the preceding ones visually and I couldn't convince myself
that kcalloc() would give us any real benefit here.
What exactely would using kcalloc() over kzalloc() here buy us?
--
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
2007-08-26 0:23 ` Robert P. J. Day
@ 2007-08-26 0:36 ` Jesper Juhl
2007-08-26 1:52 ` Kyle Moffett
2007-08-26 14:28 ` Denys Vlasenko
1 sibling, 1 reply; 15+ messages in thread
From: Jesper Juhl @ 2007-08-26 0:36 UTC (permalink / raw)
To: Robert P. J. Day
Cc: Denys Vlasenko, David Woodhouse, linux-mtd,
Linux Kernel Mailing List
On 26/08/07, Robert P. J. Day <rpjday@mindspring.com> wrote:
> On Sun, 26 Aug 2007, Jesper Juhl wrote:
>
> > On 26/08/07, Robert P. J. Day <rpjday@mindspring.com> wrote:
>
> > > i was thinking more along the lines of
> > >
> > > msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition), GFP_KERNEL);
> > >
> > > which was kind of the obvious implication, no?
> >
> > I guess
> >
> > > unless there's a reason kcalloc() wouldn't work here, this is
> > > pretty much what kcalloc() was designed for.
> > >
> > When Denys brought up the zeroing thing and mentioned kzalloc() I
> > did consider kcalloc() instead, but kzalloc() makes this allocation
> > nicely look like the preceding ones visually and I couldn't convince
> > myself that kcalloc() would give us any real benefit here.
> >
> > What exactely would using kcalloc() over kzalloc() here buy us?
>
> technically, nothing. but if you're not going to use kcalloc() when
> you're explicitly allocating an array of identical objects (that you
> want zero-filled, as a bonus), then what's the point of ever having
> defined a kcalloc() routine in the first place?
>
I wonder a bit about that myself...
I have found some other issues in that function that I want to fix, so
I'll be respinning the patch as a patch series instead - and why not;
I'll just go with kcalloc() and see what the maintainers have to say,
it's not like I personally care much one way or the other.
--
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
2007-08-26 0:36 ` Jesper Juhl
@ 2007-08-26 1:52 ` Kyle Moffett
0 siblings, 0 replies; 15+ messages in thread
From: Kyle Moffett @ 2007-08-26 1:52 UTC (permalink / raw)
To: Jesper Juhl
Cc: Denys Vlasenko, David Woodhouse, linux-mtd, Robert P. J. Day,
Linux Kernel Mailing List
On Aug 25, 2007, at 20:36:32, Jesper Juhl wrote:
> On 26/08/07, Robert P. J. Day <rpjday@mindspring.com> wrote:
>> technically, nothing. but if you're not going to use kcalloc()
>> when you're explicitly allocating an array of identical objects
>> (that you want zero-filled, as a bonus), then what's the point of
>> ever having defined a kcalloc() routine in the first place?
>>
> I wonder a bit about that myself...
>
> I have found some other issues in that function that I want to fix,
> so I'll be respinning the patch as a patch series instead - and why
> not; I'll just go with kcalloc() and see what the maintainers have
> to say, it's not like I personally care much one way or the other.
I think the original reasoning behind kcalloc() was that it did some
extra input checking, so that if the product of the two numbers
overflowed, it would fail with NULL instead of allocating
insufficient space. In the kernel it doesn't matter in practice
since you MUST have additional checking on the size of allocated
memory anyways, not even considering the fact that >PAGE_SIZE
allocations are probably going to fail with decent frequency regardless.
Cheers,
Kyle Moffett
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
2007-08-26 0:23 ` Robert P. J. Day
2007-08-26 0:36 ` Jesper Juhl
@ 2007-08-26 14:28 ` Denys Vlasenko
2007-08-26 14:37 ` Jan Engelhardt
1 sibling, 1 reply; 15+ messages in thread
From: Denys Vlasenko @ 2007-08-26 14:28 UTC (permalink / raw)
To: Robert P. J. Day
Cc: David Woodhouse, Jesper Juhl, linux-mtd,
Linux Kernel Mailing List
On Sunday 26 August 2007 01:23, Robert P. J. Day wrote:
> On Sun, 26 Aug 2007, Jesper Juhl wrote:
> > On 26/08/07, Robert P. J. Day <rpjday@mindspring.com> wrote:
> > > i was thinking more along the lines of
> > >
> > > msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition), GFP_KERNEL);
> > >
> > > which was kind of the obvious implication, no?
> >
> > I guess
> >
> > > unless there's a reason kcalloc() wouldn't work here, this is
> > > pretty much what kcalloc() was designed for.
> >
> > When Denys brought up the zeroing thing and mentioned kzalloc() I
> > did consider kcalloc() instead, but kzalloc() makes this allocation
> > nicely look like the preceding ones visually and I couldn't convince
> > myself that kcalloc() would give us any real benefit here.
> >
> > What exactely would using kcalloc() over kzalloc() here buy us?
>
> technically, nothing.
The idea of calloc is that it can check for underflow in parameter.
calloc(-1, 10000000) => easy to detect
malloc(-1 * 10000000) => malloc(-10000000) => not so trivial
--
vda
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
2007-08-26 14:28 ` Denys Vlasenko
@ 2007-08-26 14:37 ` Jan Engelhardt
2007-08-26 22:10 ` Jesper Juhl
0 siblings, 1 reply; 15+ messages in thread
From: Jan Engelhardt @ 2007-08-26 14:37 UTC (permalink / raw)
To: Denys Vlasenko
Cc: David Woodhouse, Jesper Juhl, linux-mtd, Robert P. J. Day,
Linux Kernel Mailing List
On Aug 26 2007 15:28, Denys Vlasenko wrote:
>> >
>> > What exactely would using kcalloc() over kzalloc() here buy us?
>>
>> technically, nothing.
>
>The idea of calloc is that it can check for underflow in parameter.
Actually, overflow.
calloc(0xFFFF0000, 0x1000) => will return NULL
malloc(0xFFFF0000 * 0x1000) => silent 32 bit multiplication/truncation,
will allocate less than requested.
>calloc(-1, 10000000) => easy to detect
>malloc(-1 * 10000000) => malloc(-10000000) => not so trivial
Jan
--
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
2007-08-26 14:37 ` Jan Engelhardt
@ 2007-08-26 22:10 ` Jesper Juhl
0 siblings, 0 replies; 15+ messages in thread
From: Jesper Juhl @ 2007-08-26 22:10 UTC (permalink / raw)
To: Jan Engelhardt
Cc: Denys Vlasenko, David Woodhouse, linux-mtd, Robert P. J. Day,
Linux Kernel Mailing List
On 26/08/07, Jan Engelhardt <jengelh@computergmbh.de> wrote:
>
> On Aug 26 2007 15:28, Denys Vlasenko wrote:
> >> >
> >> > What exactely would using kcalloc() over kzalloc() here buy us?
> >>
> >> technically, nothing.
> >
> >The idea of calloc is that it can check for underflow in parameter.
>
> Actually, overflow.
>
> calloc(0xFFFF0000, 0x1000) => will return NULL
> malloc(0xFFFF0000 * 0x1000) => silent 32 bit multiplication/truncation,
> will allocate less than requested.
>
> >calloc(-1, 10000000) => easy to detect
> >malloc(-1 * 10000000) => malloc(-10000000) => not so trivial
>
Ok, that makes a bit of sense. Thank you.
--
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2007-08-26 22:10 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1554af80879a7ef2f78a4d654f23c248203500d9.1187912217.git.jesper.juhl@gmail.com>
2007-08-23 23:50 ` [PATCH 07/30] mtd: Get rid of pointless cast of kzalloc() return value in AT26xxx driver Jesper Juhl
2007-08-23 23:51 ` [PATCH 08/30] mtd: Avoid a pointless kmalloc() return value cast in TQM8xxL mapping handling code Jesper Juhl
2007-08-23 23:52 ` [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c Jesper Juhl
2007-08-24 10:41 ` Denys Vlasenko
2007-08-24 10:43 ` Robert P. J. Day
2007-08-25 22:27 ` Jesper Juhl
2007-08-25 23:59 ` Robert P. J. Day
2007-08-26 0:28 ` Jesper Juhl
2007-08-26 0:23 ` Robert P. J. Day
2007-08-26 0:36 ` Jesper Juhl
2007-08-26 1:52 ` Kyle Moffett
2007-08-26 14:28 ` Denys Vlasenko
2007-08-26 14:37 ` Jan Engelhardt
2007-08-26 22:10 ` Jesper Juhl
2007-08-24 10:48 ` Jesper Juhl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox