[PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc

Subsystems: atm, the rest

STALE6880d

7 messages, 3 authors, 2007-11-27 · open the first message on its own page

[PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc

From: Joonwoo Park <hidden>
Date: 2007-11-26 09:03:56

atm/ambassador: kmalloc + memset conversion to kzalloc

Signed-off-by: Joonwoo Park <redacted>

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;
---

Re: [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc

From: Robert P. J. Day <hidden>
Date: 2007-11-26 09:14:06

On Mon, 26 Nov 2007, Joonwoo Park wrote:
quoted hunk
atm/ambassador: kmalloc + memset conversion to kzalloc

Signed-off-by: Joonwoo Park <redacted>

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
========================================================================

Re: [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc

From: Joonwoo Park <hidden>
Date: 2007-11-26 10:24:15

2007/11/26, Robert P. J. Day [off-list ref]:
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

Re: [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc

From: Robert P. J. Day <hidden>
Date: 2007-11-26 10:31:44

On Mon, 26 Nov 2007, Joonwoo Park wrote:
2007/11/26, Robert P. J. Day [off-list ref]:
quoted
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
========================================================================

Re: [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc

From: Joonwoo Park <hidden>
Date: 2007-11-26 10:53:32

2007/11/26, Robert P. J. Day [off-list ref]:
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

Re: [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc

From: Robert P. J. Day <hidden>
Date: 2007-11-26 11:22:43

On Mon, 26 Nov 2007, Joonwoo Park wrote:
2007/11/26, Robert P. J. Day [off-list ref]:
quoted
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
========================================================================

Re: [PATCH 4/4] atm/ambassador: kmalloc + memset conversion to kzalloc

From: chas williams - CONTRACTOR <hidden>
Date: 2007-11-27 15:20:40

In message [off-list ref],"Rober
t P. J. Day" writes:
quoted
quoted
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help