PHY Abstraction Layer III (now with more splitiness)
Subsystems (2)
Quoted 20 lines · Francois Romieu
Quoted 15 lines
Review
Quoted 13 lines
(quoted diff) +10
-0+int mdiobus_register(struct mii_bus *bus) +{ + int i; + int err = 0; + + spin_lock_init(&bus->mdio_lock); + + if (NULL == bus || NULL == bus->name || + NULL == bus->read || + NULL == bus->write)Be spartan:
Quoted 1 line
if (!bus || !bus->name || !bus->read || !bus->write)
Quoted 2 lines
I think we have to agree to disagree here. I could be convinced, but I'm partial to using NULL explicitly.
But there are 2 issues here (at least). One is to use NULL or not. The other is using (constant == var) or (var == constant).
It's not described in CodingStlye afaik, but most recent email on the subject strongly prefers (var == constant) [in my unscientific survey -- of bits in my head].
So using the suggested style will fix both of these. :)
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5
-0+ /* Otherwise, we allocate the device, and initialize the + * default values */ + dev = kmalloc(sizeof(*dev), GFP_KERNEL); + + if (NULL == dev) {Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +5
-0+ errno = -ENOMEM; + return NULL; + } + + memset(dev, 0, sizeof(*dev));The kernel provides kcalloc.
Quoted 3 lines
I went looking for it, and found it in
fs/cifs/misc.c. I'm hesitant to link to a function defined in the filesystem code just to save 1 line of code
It's more global than that.
~Randy
Quoted 28 lines · Randy Dunlap
Quoted 24 lines · Francois Romieu
Quoted 17 lines
Quoted 5 lines
Review
Quoted 10 lines
(quoted diff) +10
-0+int mdiobus_register(struct mii_bus *bus) +{ + int i; + int err = 0; + + spin_lock_init(&bus->mdio_lock); + + if (NULL == bus || NULL == bus->name || + NULL == bus->read || + NULL == bus->write)Be spartan:
Quoted 2 lines
if (!bus || !bus->name || !bus->read || !bus->write)Quoted 3 lines
I think we have to agree to disagree here. I could be convinced, but I'm partial to using NULL explicitly.
Quoted 8 lines
But there are 2 issues here (at least). One is to use NULL or not. The other is using (constant == var) or (var == constant).
It's not described in CodingStlye afaik, but most recent email on the subject strongly prefers (var == constant) [in my unscientific survey -- of bits in my head].
So using the suggested style will fix both of these. :)
Ok, here I won't agree to disagree with you. !foo as a check for NULL is a reasonable idea, but not my style. If that's the preferred style for the kernel, I will do that.
But (var == constant) is a style that asks for errors. By putting the constant first in these checks, you never run the risk of leaving a bug like this:
if (dev = NULL)
...
This kind of error is quite frustrating to detect, and the eye will often miss it when scanning for errors. If you follow constant == var, though, then the bug looks like this:
if (NULL = dev)
which is instantly caught by the compiler.
Just my 32 cents
Quoted 19 lines
Quoted 19 lines
Quoted 17 lines
Quoted 4 lines
Review
Quoted 10 lines
(quoted diff) +10
-0+ /* Otherwise, we allocate the device, and initialize the + * default values */ + dev = kmalloc(sizeof(*dev), GFP_KERNEL); + + if (NULL == dev) { + errno = -ENOMEM; + return NULL; + } + + memset(dev, 0, sizeof(*dev));The kernel provides kcalloc.
Quoted 6 lines
Quoted 4 lines
I went looking for it, and found it in
fs/cifs/misc.c. I'm hesitant to link to a function defined in the filesystem code just to save 1 line of codeIt's more global than that.
Should we move the function, then, to include/linux/slab.h? Or somewhere else?
Andy Fleming <[email protected]> :
[kcalloc]
Quoted 2 lines
Should we move the function, then, to
include/linux/slab.h? Or somewhere else?
It is already in mm/slab.c
[rc = request_irq(...)]
It appears in drivers/net/*c. Jeff Garzik used to suggest something similar but it does not matter as long as you do not need to return an error status (KERN_ERR is probably a bit too strong then).
[initialization of struct phy_setting settings]
#define NITZ(d,t,s) { .speed = s, .duplex = d, .setting = t }
static struct phy_setting settings[] = {
NITZ(DUPLEX_FULL, SUPPORTED_10000baseT_Full, 10000),
NITZ(DUPLEX_FULL, SUPPORTED_1000baseT_Full, SPEED_1000),
NITZ(DUPLEX_HALF, SUPPORTED_1000baseT_Half, SPEED_1000),
NITZ(DUPLEX_FULL, SUPPORTED_100baseT_Full, SPEED_100),
NITZ(DUPLEX_HALF, SUPPORTED_100baseT_Half, SPEED_100),
NITZ(DUPLEX_FULL, SUPPORTED_10baseT_Full, SPEED_10),
NITZ(DUPLEX_HALF, SUPPORTED_10baseT_Half, SPEED_10),
};#undef NITZ
--
Ueimor