lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 23 Oct 2007 11:04:29 -0400
From:	lsorense@...lub.uwaterloo.ca (Lennart Sorensen)
To:	Andrew Morton <akpm@...ux-foundation.org>
Cc:	Anas Nashif <nashif@...ux.intel.com>, linux-kernel@...r.kernel.org,
	Marek Dabek <marek.dabek@...el.com>
Subject: Re: [PATCH] Intel Manageability Engine Interface driver

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@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ