From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Walls Date: Wed, 26 Jan 2011 00:30:13 +0000 Subject: Re: [PATCH] video/saa7164: Fix sparse warning: Using plain integer Message-Id: <1296001813.25686.27.camel@localhost> List-Id: References: <1295988851-23561-1-git-send-email-peterhuewe@gmx.de> <201101252354.31217.PeterHuewe@gmx.de> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: Devin Heitmueller Cc: Peter =?ISO-8859-1?Q?H=FCwe?= , Julia Lawall , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Steven Toth , Tejun Heo , Dan Carpenter On Tue, 2011-01-25 at 18:05 -0500, Devin Heitmueller wrote: > On Tue, Jan 25, 2011 at 5:54 PM, Peter H=C3=BCwe wrot= e: > > Hi Julia, > > > > thanks for your input. > > So do I understand you correctly if I say > > if(!x) is better than if(x=3DNULL) in any case? The machine code should be equivalent in size and speed. > > Or only for the kmalloc family? > > > > Do you remember the reason why !x should be preferred? > > > > In Documentation/CodingStyle , Chapter 7: Centralized exiting of funct= ions > > there is a function fun with looks like this: > > int fun(int a) > > { > > int result =3D 0; > > char *buffer =3D kmalloc(SIZE); > > > > if (buffer =3D NULL) > > return -ENOMEM; > > > > --> So if (buffer =3D NULL) is in the official CodingStyle - maybe w= e should > > add a paragraph there as well ;) CodingStyle shouldn't specify anything on the matter. There is no overall, optimal choice for all contexts. Arguing either way is as pointless as the Lilliputians' little-end vs. big-end dispute. > To my knowledge, the current CodingStyle doesn't enforce a particular > standard in this regard, leaving it at the discretion of the author. Correct, it does not. I just checked CodingStyle and checkpatch yesterday. > Whether to do (!foo) or (foo =3D NULL) is one of those debates people > have similar to whether to use tabs as whitespace. People have > differing opinions and there is no clearly "right" answer. It depends on one's measurement criteria for "optimizing" the written form of source code. I prefer more explicit statement of action is taking place over statements with fewer characters. It usually saves me time when revisiting code. More genrally I prefer any coding practice that saves me time when revisiting code. (Note the word "me" carries a lot of context with it.) Ambiguity and implicit behaviors ultimately waste my time. > Personally > I strongly prefer (foo =3D NULL) as it makes it blindingly obvious that > it's a pointer comparison, whereas (!foo) leaves you wondering whether > it's an integer or pointer comparison. Me too. > All that said, you shouldn't submit patches which arbitrarily change > from one format to the other. With regards to the proposed patch, you > should follow whatever style the author employed in the rest of the > file. That is another reasonable critereon in "optimizing" the written form of the source code. I tend to give it less weight though. Regards, Andy -- 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