Re: [PATCH] Intel Manageability Engine Interface driver

From: Lennart Sorensen
Date: Tue Oct 23 2007 - 11:04:40 EST


On Mon, Oct 22, 2007 at 11:40:01AM -0700, Andrew Morton wrote:
> - Here:
>
> + if (0 == memcmp(&heci_wd_guid,
>
> we boringly prefer "if (foo == 0)" rather than "if (0 == foo)". (lots
> of places).

But 0 == blah is safer. If you accidentally do 0 = blah the compiler
will tell you. Just because people have always done it the other way
around doesn't make it the right way to do it. I have noticed many
people have started to realize this in the last few years.

It is also much clearer that you are comparing against a constant and
not doing an assignment when the constant comes before the variable.

I think to encourage people doing it the less safe way is just silly.

Some places in the kernel that already uses the constant first are:

./sound/oss/btaudio.c
./sound/usb/usx2y/
./net/sctp/
./arch/x86_64/mm/init.c
./arch/cris/arch-v32/drivers/cryptocop.c
./drivers/i2c/algos/i2c-algo-pcf.c
./drivers/mtd/devices/doc2000.c
./drivers/net/iseries_veth.c
./drivers/net/hp100.c
./drivers/net/phy/phy.c
./drivers/net/xen-netfront.c
./drivers/scsi/scsi_error.c
./drivers/scsi/sr_ioctl.c
./drivers/scsi/ch.c
./drivers/scsi/sg.c
./drivers/scsi/sr_vendor.c
./drivers/scsi/scsi_debug.c
./drivers/media/video/tea6415c.c
./drivers/media/video/tvaudio.c
./drivers/media/video/bt8xx/
./drivers/char/ip2/
./drivers/isdn/hisax/
./drivers/sbus/char/
./fs/nfsd/

and I am sure there a quite a few more. It ought to be encouraged for
all new code to avoid stupid typo bugs that are hard to see.

--
Len Sorensen
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/