Skip to contentSkip to conversation

PHY Abstraction Layer III (now with more splitiness)

RFC PATCH Randy Dunlap 2 participants 2 messages Jul 27, 2005 – Jul 28, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw
Quoted 56 lines · Randy Dunlap
Quoted 29 lines
Quoted 25 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:

Quoted 5 lines

if (NULL = dev)

which is instantly caught by the compiler.

Just my 32 cents

Yes, we know about that argument. :)

Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 6 lines
Quoted 6 lines
(quoted diff) +6 -0
+    /* Otherwise, we allocate the device, and initialize the
+     * default values */
+    dev = kmalloc(sizeof(*dev), GFP_KERNEL);
+
+    if (NULL == dev) {
+        errno = -ENOMEM;
Quoted 9 lines

Review

Quoted 6 lines
(quoted diff) +4 -0
+        return NULL;
+    }
+
+    memset(dev, 0, sizeof(*dev));

The kernel provides kcalloc.

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

Quoted 5 lines
Quoted 1 line

It's more global than that.

Should we move the function, then, to include/linux/slab.h? Or somewhere else?

It's there, like Francois said. Get use a current tree.

---
~Randy

#1 lore raw
Quoted 16 lines · Randy Dunlap
Quoted 16 lines

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:

Quoted 7 lines
Quoted 5 lines

if (NULL = dev)

which is instantly caught by the compiler.

Just my 32 cents

Yes, we know about that argument. :)

The counter-argument basically goes like this:

1. All relevant compilers (GCC) warn on "if (dev = NULL)", so you will only miss the bug if you ignore compiler warnings. Ignoring compiler warnings is not generally endorsed by the kernel crowd.

2. Very hard to read, "if (NULL = dev)" is. Reversing the order is a fun thing to do for small green characters in fantasy and scifi stories and fairly popular in peotry as well. But understanding the meaning of reverse order sentences takes more time. In the kernel, peer review is an important aspect and making the code hard to read hurts peer review.

And maybe you can add another one:

3. Im my personal experience, reverse order comparisons were a good indicator of buggy code.

Jörn

Signature · 2 lines
Schrödinger's cat is <BLINK>not</BLINK> dead.
-- Illiad