From: Amit Shah <amit.shah@redhat.com>
To: Steven Liu <lingjiujianke@gmail.com>
Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org
Subject: Re: [PATCH] fix a code style in drivers/char/virtio_console.c
Date: Tue, 18 May 2010 12:02:41 +0530 [thread overview]
Message-ID: <20100518063241.GB27262@amit-laptop.redhat.com> (raw)
In-Reply-To: <AANLkTimXLkzb-CyhbkOaubAOiSsIkGKW0y5Cblrwfvst@mail.gmail.com>
Hello,
On (Tue) May 18 2010 [13:41:29], Steven Liu wrote:
> Hi, Amit,
>
> if 'err' initialised in this path, it needn't do err = -ENOMEM
> after,isn't it?
What I mean is if we later add some code that just does:
if (err)
goto fail;
then 'ret' can be -ENOMEM, as it was initialised to, which would be
fine. But if a later patch adds something like:
+ ret = -EIO;
+ err = ...
+ if (err)
+ goto fail;
+
err = ...
if (err)
goto fail;
In this case, the 2nd if() would now return EIO instead of ENOMEM as
earlier.
Also, this style of coding can prevent uninitialised usage of 'ret', eg:
int ret;
if (err)
goto fail;
fail:
return ret;
In this case, the compiler will warn about 'ret' being used
uninitialised.
This is just a coding style issue. I had initially coded it the way your
patch does, but Rusty asked me to change that and I like this new style
better: there's less scope for surprises.
Amit
next prev parent reply other threads:[~2010-05-18 6:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-18 5:17 Steven Liu
2010-05-18 5:22 ` Amit Shah
2010-05-18 5:41 ` Steven Liu
2010-05-18 6:32 ` Amit Shah [this message]
2010-05-18 6:41 ` Steven Liu
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=20100518063241.GB27262@amit-laptop.redhat.com \
--to=amit.shah@redhat.com \
--cc=lingjiujianke@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=virtualization@lists.linux-foundation.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
all inboxes | Powered by JetHome®