All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roland Dreier <rdreier@cisco.com>
To: "Ahmed S. Darwish" <darwish.07@gmail.com>
Cc: Richard Knutsson <ricknu-0@student.ltu.se>,
	linux-kernel@vger.kernel.org, randy.dunlap@oracle.com
Subject: Re: A CodingStyle suggestion
Date: Sat, 03 Feb 2007 16:21:18 -0800	[thread overview]
Message-ID: <aday7neydq9.fsf@cisco.com> (raw)
In-Reply-To: <20070204000532.GA20721@Ahmed> (Ahmed S. Darwish's message of "Sun, 4 Feb 2007 02:05:32 +0200")

 > Good catch :). A small grep of `access_ok' reveals that it's always used in the 
 > form of:
 > if (!access_ok()) { .. }
 > 
 > I can conclude that verbal/imperative methods like `kmalloc, add_work' be 
 > checked as:
 > ret = do_work();
 > if (ret) { ... }
 > and predicate methods like `acess_ok, pci_dev_present' be checked like:
 > if (!access_ok) { ... }
 > if (pci_dev_present) { ...}
 > 
 > Any comments ?

I don't think that's really the distinction that matters.  I think
really the issue is that assignment within an if is hard to read, so

	ret = foo(a, b);
        if (ret) { ... }

is clearly preferred to

	if ((ret = foo(a,b))) { ... }

However, in my opinion something like

	if (foo(a,b)) { ... }

if perfectly fine if the return value of foo is not needed anywhere
else.  In other words, there's no sense introducing a temporary
variable to hold the return value if you're never going to do anything
with it other than check it on the next line.

 - R.

  reply	other threads:[~2007-02-04  0:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-03 21:58 A CodingStyle suggestion Ahmed S. Darwish
2007-02-03 21:59 ` Randy Dunlap
2007-02-04 12:48   ` Theodore Tso
2007-02-04 12:55     ` Manu Abraham
2007-02-04 12:57     ` Robert P. J. Day
2007-02-03 22:56 ` Richard Knutsson
2007-02-04  0:05   ` Ahmed S. Darwish
2007-02-04  0:21     ` Roland Dreier [this message]
2007-02-04  0:40       ` Randy Dunlap
2007-02-04  6:35         ` Willy Tarreau
2007-02-04  0:22     ` Tim Schmielau
2007-02-04  0:39     ` Richard Knutsson
2007-02-04 12:10 ` Ahmed S. Darwish
2007-02-04 12:36 ` Manu Abraham

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=aday7neydq9.fsf@cisco.com \
    --to=rdreier@cisco.com \
    --cc=darwish.07@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=randy.dunlap@oracle.com \
    --cc=ricknu-0@student.ltu.se \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.