Skip to contentSkip to conversation

atm/ambassador: kmalloc + memset conversion to kzalloc

PATCH In review Joonwoo Park 3 participants 7 messages Nov 26, 2007 – Nov 27, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

atm/ambassador: kmalloc + memset conversion to kzalloc

Thanks.
Joonwoo

---

drivers/atm/ambassador.c +1 -2
index b34b382..4f99ba3 100644
@@ -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;

---

#1 lore raw
Quoted 21 lines · Joonwoo Park

atm/ambassador: kmalloc + memset conversion to kzalloc

Thanks.
Joonwoo

---

drivers/atm/ambassador.c +0 -1
index b34b382..4f99ba3 100644
@@ -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;

drivers/atm/ambassador.c static int __devinit amb_probe(struct pci_dev *pci_dev, const struct pci_device_

Quoted 9 lines
drivers/atm/ambassador.c +1 -2
@@ -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
========================================================================

#2 lore raw

2007/11/26, Robert P. J. Day <[email protected]>:

Quoted 8 lines

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

#3 lore raw
Quoted 11 lines · Joonwoo Park

2007/11/26, Robert P. J. Day <[email protected]>:

Quoted 7 lines

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

#4 lore raw

2007/11/26, Robert P. J. Day <[email protected]>:

Quoted 12 lines

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

Quoted 4 lines

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

#5 lore raw
Quoted 13 lines · Joonwoo Park

2007/11/26, Robert P. J. Day <[email protected]>:

Quoted 12 lines

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

Quoted 7 lines
Quoted 4 lines

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

#6 lore raw

In message <[email protected]>,"Rober

Quoted 9 lines · t P. J. Day
Quoted 6 lines
Quoted 3 lines

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.