netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc
@ 2007-11-26  9:02 Joonwoo Park
  2007-11-26  9:11 ` Robert P. J. Day
  0 siblings, 1 reply; 7+ messages in thread
From: Joonwoo Park @ 2007-11-26  9:02 UTC (permalink / raw)
  To: netdev, chas; +Cc: linux-kernel

atm/ambassador: kmalloc + memset conversion to kzalloc

Signed-off-by: Joonwoo Park <joonwpark81@gmail.com>

Thanks.
Joonwoo

---
diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
index b34b382..4f99ba3 100644
--- a/drivers/atm/ambassador.c
+++ b/drivers/atm/ambassador.c
@@ -2163,7 +2163,6 @@ static int __devinit amb_init (amb_dev * dev)
 static void setup_dev(amb_dev *dev, struct pci_dev *pci_dev) 
 {
       unsigned char pool;
-      memset (dev, 0, sizeof(amb_dev));
       
       // set up known dev items straight away
       dev->pci_dev = pci_dev; 
@@ -2253,7 +2252,7 @@ static int __devinit amb_probe(struct pci_dev *pci_dev, const struct pci_device_
 		goto out_disable;
 	}
 
-	dev = kmalloc (sizeof(amb_dev), GFP_KERNEL);
+	dev = kzalloc(sizeof(amb_dev), GFP_KERNEL);
 	if (!dev) {
 		PRINTK (KERN_ERR, "out of memory!");
 		err = -ENOMEM;
---


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

* Re: [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc
  2007-11-26  9:02 [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc Joonwoo Park
@ 2007-11-26  9:11 ` Robert P. J. Day
  2007-11-26 10:23   ` Joonwoo Park
  0 siblings, 1 reply; 7+ messages in thread
From: Robert P. J. Day @ 2007-11-26  9:11 UTC (permalink / raw)
  To: Joonwoo Park; +Cc: netdev, chas, linux-kernel

On Mon, 26 Nov 2007, Joonwoo Park wrote:

> atm/ambassador: kmalloc + memset conversion to kzalloc
>
> Signed-off-by: Joonwoo Park <joonwpark81@gmail.com>
>
> Thanks.
> Joonwoo
>
> ---
> diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
> index b34b382..4f99ba3 100644
> --- a/drivers/atm/ambassador.c
> +++ b/drivers/atm/ambassador.c
> @@ -2163,7 +2163,6 @@ static int __devinit amb_init (amb_dev * dev)
>  static void setup_dev(amb_dev *dev, struct pci_dev *pci_dev)
>  {
>        unsigned char pool;
> -      memset (dev, 0, sizeof(amb_dev));
>
>        // set up known dev items straight away
>        dev->pci_dev = pci_dev;
> @@ -2253,7 +2252,7 @@ static int __devinit amb_probe(struct pci_dev *pci_dev, const struct pci_device_
>  		goto out_disable;
>  	}
>
> -	dev = kmalloc (sizeof(amb_dev), GFP_KERNEL);
> +	dev = kzalloc(sizeof(amb_dev), GFP_KERNEL);
>  	if (!dev) {
>  		PRINTK (KERN_ERR, "out of memory!");
>  		err = -ENOMEM;
> ---

i'm not sure the above is a safe thing to do, as you're zeroing that
area, then making a function call and assuming, upon entry to the
function call, that the caller has done the right thing.  i don't see
how you can count on that, depending on who else might want to call
that routine and whether they get sloppy about it.  unless you're
prepared to guarantee that there will never be another call to
setup_dev() from elsewhere.


rday


========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

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

* Re: [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc
  2007-11-26  9:11 ` Robert P. J. Day
@ 2007-11-26 10:23   ` Joonwoo Park
  2007-11-26 10:29     ` Robert P. J. Day
  0 siblings, 1 reply; 7+ messages in thread
From: Joonwoo Park @ 2007-11-26 10:23 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: netdev, chas, linux-kernel

2007/11/26, Robert P. J. Day <rpjday@crashcourse.ca>:
> i'm not sure the above is a safe thing to do, as you're zeroing that
> area, then making a function call and assuming, upon entry to the
> function call, that the caller has done the right thing.  i don't see
> how you can count on that, depending on who else might want to call
> that routine and whether they get sloppy about it.  unless you're
> prepared to guarantee that there will never be another call to
> setup_dev() from elsewhere.
>

Thanks for your response.
But setup_dev is static function and only amb_init calls it.
IMO it's safe.

Thanks.
Joonwoo

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

* Re: [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc
  2007-11-26 10:23   ` Joonwoo Park
@ 2007-11-26 10:29     ` Robert P. J. Day
  2007-11-26 10:53       ` Joonwoo Park
  0 siblings, 1 reply; 7+ messages in thread
From: Robert P. J. Day @ 2007-11-26 10:29 UTC (permalink / raw)
  To: Joonwoo Park; +Cc: netdev, chas, linux-kernel

On Mon, 26 Nov 2007, Joonwoo Park wrote:

> 2007/11/26, Robert P. J. Day <rpjday@crashcourse.ca>:
> > i'm not sure the above is a safe thing to do, as you're zeroing that
> > area, then making a function call and assuming, upon entry to the
> > function call, that the caller has done the right thing.  i don't see
> > how you can count on that, depending on who else might want to call
> > that routine and whether they get sloppy about it.  unless you're
> > prepared to guarantee that there will never be another call to
> > setup_dev() from elsewhere.
>
> Thanks for your response. But setup_dev is static function and only
> amb_init calls it.

i realized that.  but all you can say is that only amb_init() calls
setup_dev() *currently*.  when you're not looking, someone else might
(for whatever reason) call setup_dev() from elsewhere, and *that* call
might not zero that memory area.

IMHO, the only safe transforms of kmalloc+memset -> kzalloc are those
in which the flow of control is unmistakable and invariant.  splitting
that across a function call seems like a dangerous thing to do.
(except, of course, in the case, where the kzalloc() is added inside
the function -- then all callers are entitled to simplify *their*
code.  but that's different.)

in any event, i just thought i'd point it out.  if you're absolutely
sure there will never be another call to setup_dev() from somewhere
else, then, yes, it's safe.

rday

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

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

* Re: [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc
  2007-11-26 10:29     ` Robert P. J. Day
@ 2007-11-26 10:53       ` Joonwoo Park
  2007-11-26 11:20         ` Robert P. J. Day
  0 siblings, 1 reply; 7+ messages in thread
From: Joonwoo Park @ 2007-11-26 10:53 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: netdev, chas, linux-kernel

2007/11/26, Robert P. J. Day <rpjday@crashcourse.ca>:
> i realized that.  but all you can say is that only amb_init() calls
> setup_dev() *currently*.  when you're not looking, someone else might
> (for whatever reason) call setup_dev() from elsewhere, and *that* call
> might not zero that memory area.
>
> IMHO, the only safe transforms of kmalloc+memset -> kzalloc are those
> in which the flow of control is unmistakable and invariant.  splitting
> that across a function call seems like a dangerous thing to do.
> (except, of course, in the case, where the kzalloc() is added inside
> the function -- then all callers are entitled to simplify *their*
> code.  but that's different.)
>
> in any event, i just thought i'd point it out.  if you're absolutely
> sure there will never be another call to setup_dev() from somewhere
> else, then, yes, it's safe.
>

I understood your opinions. and partially agree with you.
But isn't it a unfounded fear?

Thanks
Joonwoo

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

* Re: [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc
  2007-11-26 10:53       ` Joonwoo Park
@ 2007-11-26 11:20         ` Robert P. J. Day
  2007-11-27 14:40           ` chas williams - CONTRACTOR
  0 siblings, 1 reply; 7+ messages in thread
From: Robert P. J. Day @ 2007-11-26 11:20 UTC (permalink / raw)
  To: Joonwoo Park; +Cc: netdev, chas, linux-kernel

On Mon, 26 Nov 2007, Joonwoo Park wrote:

> 2007/11/26, Robert P. J. Day <rpjday@crashcourse.ca>:
> > i realized that.  but all you can say is that only amb_init() calls
> > setup_dev() *currently*.  when you're not looking, someone else might
> > (for whatever reason) call setup_dev() from elsewhere, and *that* call
> > might not zero that memory area.
> >
> > IMHO, the only safe transforms of kmalloc+memset -> kzalloc are those
> > in which the flow of control is unmistakable and invariant.  splitting
> > that across a function call seems like a dangerous thing to do.
> > (except, of course, in the case, where the kzalloc() is added inside
> > the function -- then all callers are entitled to simplify *their*
> > code.  but that's different.)
> >
> > in any event, i just thought i'd point it out.  if you're absolutely
> > sure there will never be another call to setup_dev() from somewhere
> > else, then, yes, it's safe.
> >
>
> I understood your opinions. and partially agree with you.
> But isn't it a unfounded fear?

i don't know, i just thought i'd mention it.  if no one thinks it's an
issue, it's certainly fine with me.

rday

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

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

* Re: [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc
  2007-11-26 11:20         ` Robert P. J. Day
@ 2007-11-27 14:40           ` chas williams - CONTRACTOR
  0 siblings, 0 replies; 7+ messages in thread
From: chas williams - CONTRACTOR @ 2007-11-27 14:40 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: Joonwoo Park, netdev, linux-kernel

In message <alpine.LFD.0.9999.0711260619580.10766@localhost.localdomain>,"Rober
t P. J. Day" writes:
>> > in any event, i just thought i'd point it out.  if you're absolutely
>> > sure there will never be another call to setup_dev() from somewhere
>> > else, then, yes, it's safe.
>>
>> I understood your opinions. and partially agree with you.
>> But isn't it a unfounded fear?
>
>i don't know, i just thought i'd mention it.  if no one thinks it's an
>issue, it's certainly fine with me.

its very unlikely that setup_dev() is likely to be called from another
code path.  this patch looks fine to me.  i will take it and get it
submitted on the next merge.

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

end of thread, other threads:[~2007-11-27 14:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-26  9:02 [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc Joonwoo Park
2007-11-26  9:11 ` Robert P. J. Day
2007-11-26 10:23   ` Joonwoo Park
2007-11-26 10:29     ` Robert P. J. Day
2007-11-26 10:53       ` Joonwoo Park
2007-11-26 11:20         ` Robert P. J. Day
2007-11-27 14:40           ` chas williams - CONTRACTOR

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).