From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mauro Carvalho Chehab Date: Wed, 26 Jan 2011 09:29:42 +0000 Subject: Re: [PATCH] video/saa7164: Fix sparse warning: Using plain integer Message-Id: <4D3FE986.9030603@infradead.org> List-Id: References: <1295988851-23561-1-git-send-email-peterhuewe@gmx.de> <201101252354.31217.PeterHuewe@gmx.de> In-Reply-To: <201101252354.31217.PeterHuewe@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: =?ISO-8859-1?Q?Peter_H=FCwe?= Cc: Julia Lawall , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Steven Toth , Tejun Heo , Dan Carpenter Em 25-01-2011 20:54, Peter H=FCwe escreveu: > Am Dienstag 25 Januar 2011, 23:20:44 schrieb Julia Lawall: >> On Tue, 25 Jan 2011, Peter Huewe wrote: >>> This patch fixes the warning "Using plain integer as NULL pointer", >>> generated by sparse, by replacing the offending 0s with NULL. >> >> I recall (a number of years ago) being told that for things like kmalloc, >> the proper test was !x, not x =3D NULL. >> >> julia >> >=20 >=20 > Hi Julia, >=20 > thanks for your input. > So do I understand you correctly if I say > if(!x) is better than if(x=3DNULL) in any case? >=20 > Or only for the kmalloc family? >=20 > Do you remember the reason why !x should be preferred? >=20 > In Documentation/CodingStyle , Chapter 7: Centralized exiting of functio= ns=20 > there is a function fun with looks like this: > int fun(int a) > { > int result =3D 0; > char *buffer =3D kmalloc(SIZE); >=20 > if (buffer =3D NULL) > return -ENOMEM; >=20 > if (condition1) { > while (loop1) { > ... > } > result =3D 1; > goto out; > } > ... > out: > kfree(buffer); > return result; > } >=20 >=20 > --> So if (buffer =3D NULL) is in the official CodingStyle - maybe we = should=20 > add a paragraph there as well ;) >=20 >=20 > Don't get me wrong, I just want to learn ;) Both ways are acceptable. But because C is a Spartan language, and because I need to review lots of code, I prefer the more synthetic way: if (!buf) That means less things to read, and saves me a few microsseconds of reading and processing it on my mind. In general, such tests occur just after a mal= loc or a malloc-like function, so it is really obvious that you're testing for a pointer. Cheers, Mauro -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" = in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html