linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Antti Palosaari <crope@iki.fi>
To: Mauro Carvalho Chehab <m.chehab@samsung.com>
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>,
	Mauro Carvalho Chehab <mchehab@infradead.org>
Subject: Re: [PATCH 32/46] [media] e4000: simplify boolean tests
Date: Thu, 04 Sep 2014 04:27:57 +0300	[thread overview]
Message-ID: <5407C01D.5090400@iki.fi> (raw)
In-Reply-To: <20140903221215.3843a9e9.m.chehab@samsung.com>



On 09/04/2014 04:12 AM, Mauro Carvalho Chehab wrote:
> Em Thu, 04 Sep 2014 02:56:19 +0300
> Antti Palosaari <crope@iki.fi> escreveu:
>
>> Which is static analyzer you are referring to fix these?
>
> Coccinelle. See: scripts/coccinelle/misc/boolinit.cocci
>
>> Using true/false for boolean datatype sounds OK, but personally I
>> dislike use of negation operator. For my eyes (foo = 0) / (foo == false)
>> is better and I have changed all the time negate operators to equal
>> operators from my drivers.
>
> The usage of the negation operator on such tests is there since
> the beginning of C.

ugh! :(

>
> By being shorter, a reviewer can read it faster and, at least for
> me, it is a non-brain to understand !foo. On the other hand,
> "false" is not part of standard C. So, it takes more time for my
> brain to parse it.

No, it just opposite for me and many others.

>
> Anyway, from my side, the real reasone for using it is not due to
> that. It is that I (and other Kernel developers) run from time to
> time static analyzers like smatch and coccinelle, in order to identify
> real errors. Having a less-polluted log helps to identify the newer
> errors/warnings.

Have you ever looked Documentation/CodingStyle ?
How about that example, from CodingStyle:
int fun(int a)
{
	int result = 0;
	char *buffer = kmalloc(SIZE);

	if (buffer == NULL)
		return -ENOMEM;

	if (condition1) {
		while (loop1) {
			...
		}
		result = 1;
		goto out;
	}
	...
out:
	kfree(buffer);
	return result;
}

As it shows, it is (buffer == NULL) *not* (!buffer). And if you like to 
do it differently then update CodingStyle first! Add clear mention that 
it should be (!buffer) and change given example to match your style. 
Otherwise, I am happy to do as CodingStyle shows!

Antti

>
> Regards,
> Mauro
>>
>> regards
>> Antti
>>
>> On 09/03/2014 11:33 PM, Mauro Carvalho Chehab wrote:
>>> Instead of using if (foo == false), just use
>>> if (!foo).
>>>
>>> That allows a faster mental parsing when analyzing the
>>> code.
>>>
>>> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
>>>
>>> diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
>>> index 90d93348f20c..cd9cf643f602 100644
>>> --- a/drivers/media/tuners/e4000.c
>>> +++ b/drivers/media/tuners/e4000.c
>>> @@ -400,7 +400,7 @@ static int e4000_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
>>>    	struct e4000 *s = container_of(ctrl->handler, struct e4000, hdl);
>>>    	int ret;
>>>
>>> -	if (s->active == false)
>>> +	if (!s->active)
>>>    		return 0;
>>>
>>>    	switch (ctrl->id) {
>>> @@ -423,7 +423,7 @@ static int e4000_s_ctrl(struct v4l2_ctrl *ctrl)
>>>    	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
>>>    	int ret;
>>>
>>> -	if (s->active == false)
>>> +	if (!s->active)
>>>    		return 0;
>>>
>>>    	switch (ctrl->id) {
>>>
>>

-- 
http://palosaari.fi/

  reply	other threads:[~2014-09-04  1:28 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-03 20:27 [PATCH 00/46] Several static analizer fixes Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 01/46] [media] dmxdev: don't use before checking file->private_data Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 02/46] [media] marvel-ccic: don't initialize static vars with 0 Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 03/46] [media] soc_camera: use kmemdup() Mauro Carvalho Chehab
2014-09-03 20:44   ` Guennadi Liakhovetski
2014-09-03 20:54     ` Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 04/46] [media] vivid-vid-out: use memdup_user() Mauro Carvalho Chehab
2014-09-03 20:49   ` Hans Verkuil
2014-09-03 20:57     ` Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 05/46] [media] s5k5baf: remove an uneeded semicolon Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 06/46] [media] bttv-driver: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 07/46] [media] soc_camera: remove uneeded semicolons Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 08/46] [media] stv0900_core: don't allocate a temporary var Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 09/46] [media] em28xx: use true/false for boolean vars Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 10/46] [media] tuner-core: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 11/46] [media] af9013: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 12/46] [media] cxd2820r: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 13/46] [media] m88ds3103: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 14/46] [media] af9013: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 15/46] [media] tda10071: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 16/46] [media] smiapp-core: " Mauro Carvalho Chehab
2014-09-04  7:03   ` Sakari Ailus
2014-09-04 12:58     ` Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 17/46] [media] ov9740: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 18/46] [media] omap3isp: " Mauro Carvalho Chehab
2014-09-04 20:24   ` Laurent Pinchart
2014-09-03 20:32 ` [PATCH 19/46] [media] ti-vpe: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 20/46] [media] vivid-tpg: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 21/46] [media] radio: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 22/46] [media] ene_ir: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 23/46] [media] au0828-dvb: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 24/46] [media] lmedm04: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 25/46] [media] af9005: " Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 26/46] [media] msi2500: simplify boolean tests Mauro Carvalho Chehab
2014-09-03 20:32 ` [PATCH 27/46] [media] drxk_hard: simplify test logic Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 28/46] [media] lm3560: simplify boolean tests Mauro Carvalho Chehab
2014-09-04  7:08   ` Sakari Ailus
2014-09-05  5:30     ` Daniel Jeong
2014-09-03 20:33 ` [PATCH 29/46] [media] lm3560: simplify a boolean test Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 30/46] [media] omap: simplify test logic Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 31/46] [media] via-camera: simplify boolean tests Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 32/46] [media] e4000: " Mauro Carvalho Chehab
2014-09-03 23:56   ` Antti Palosaari
2014-09-04  1:12     ` Mauro Carvalho Chehab
2014-09-04  1:27       ` Antti Palosaari [this message]
2014-09-04  2:30         ` Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 33/46] [media] s5p-tv: Simplify the return logic Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 34/46] [media] siano: just return 0 instead of using a var Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 35/46] [media] stv0367: " Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 36/46] [media] media-devnode: " Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 37/46] [media] bt8xx: " Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 38/46] [media] saa7164: " Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 39/46] [media] davinci: " Mauro Carvalho Chehab
2014-09-03 20:43   ` Prabhakar Lad
2014-09-03 20:33 ` [PATCH 40/46] [media] marvel-ccic: " Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 41/46] [media] fintek-cir: " Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 42/46] [media] ite-cir: " Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 43/46] [media] nuvoton-cir: " Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 44/46] [media] mt2060: " Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 45/46] [media] mxl5005s: " Mauro Carvalho Chehab
2014-09-03 20:33 ` [PATCH 46/46] [media] cx231xx: " Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5407C01D.5090400@iki.fi \
    --to=crope@iki.fi \
    --cc=linux-media@vger.kernel.org \
    --cc=m.chehab@samsung.com \
    --cc=mchehab@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).