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] [day] [month] [year] [list]
Date:	Mon, 16 Jun 2014 21:49:03 +0300
From:	Dan Carpenter <dan.carpenter@...cle.com>
To:	Stephan Gabert <stephan.gabert@....de>
Cc:	pe1dnn@...at.org, gregkh@...uxfoundation.org,
	devel@...verdev.osuosl.org, linux-kernel@...r.kernel.org,
	nicolas.pfeiffer@....de, linux-kernel@...cs.fau.de
Subject: Re: [PATCH 3/5] staging/wlags49_h2: correct check of the return
 value of register_netdev()

On Mon, Jun 16, 2014 at 04:50:51PM +0200, Stephan Gabert wrote:
> As mentioned in net/core/dev.c register_netdev() explicitly returns a
> negative errno code on failure.
> 
> So in case of failure, one should rather test whether ret is negative
> than just unlike 0.

No.  In the kernel the normal way is to say:

	if (ret)
		return ret;

Zero is succes and non-zero is error code.

	if (ret != 0)
		return ret;

That's a double negative and pointlessly confusing.

	if (ret != 0 != 0 != 0)

That's a hextuple negative and awesomely confusing.

There are times where a double negative is ok.  When you are talking
about numbers specifically:

	if (ret != 0 && ret != 3) {

That means ret is not zero or three, but zero doesn't mean success or
failure, it's just a number.

For strcmp() functions you should always compare against zero
because that is the idiom.

	if (strcmp(foo, bar) < 0)
	if (strcmp(foo, bar) != 0)

The first "<" means "foo" is before "bar" and "!=" means not equal.

	if (ret < 0)
		return ret;

Probably means that now ret is either zero or a positive value???  It is
ambiguous.

regards,
dan carpenter

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