From: Tejun Heo <htejun@gmail.com>
To: Louis Langholtz <lou_langholtz@me.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: kernel/params.c: 'err' variable "set but not used" and perhaps should be?
Date: Thu, 4 Jun 2015 05:22:37 +0900 [thread overview]
Message-ID: <20150603202237.GI20091@mtj.duckdns.org> (raw)
In-Reply-To: <7E8FFE0D-B9F7-4816-8ECF-2AA5980F3890@me.com>
Hello,
On Wed, Jun 03, 2015 at 01:41:40PM -0600, Louis Langholtz wrote:
> On Jun 1, 2015, at 7:32 PM, Rusty Russell <rusty@rustcorp.com.au> wrote:
> > That's hilarious.
> >
> > __attribute__((warn_unused_result)) was added to gcc as a hack so people
> > wouldn't forget to use the realloc return, which probably seemed sane.
> > Explains why you can't suppress it by casting to void, because for
> > realloc, that would be dumb.
> >
> > Everyone loved it so much, they sprinkled little must-check turds
> > everywhere! Because MY FUNCTION IS IMPORTANT YOU SIMPLETON, YOU MUST
> > CHECK THE RETURN!
> >
> > The problem with yelling "YOU MUST DO SOMETHING" is that the answer is
> > often "this is something, therefore it must be done". That's what
> > happened here.
>
> The function sysfs_create_file is marked as __must_check in the
> include/linux/sysfs.h file. This specific attribution appears to have been
> added to this function back on September 20, 2007 by Tejun Heo. I have CC'd
> Tejun so he has opportunity to respond to this criticism that you have raised.
Well, it's a while ago and I don't strongly object to removing it but
I still think it's a good idea to keep it around. The failure of the
function creates a userland visible behavior difference and it's kinda
easy to forget that it may fail as it often is the final action taken
on the object.
> > @@ -853,7 +853,8 @@ static void __init version_sysfs_builtin(void)
> > mk = locate_module_kobject(vattr->module_name);
> > if (mk) {
> > - err = sysfs_create_file(&mk->kobj, &vattr->mattr.attr);
> > + if (sysfs_create_file(&mk->kobj, &vattr->mattr.attr))
> > + doesnt_happen();
> > kobject_uevent(&mk->kobj, KOBJ_ADD);
> > kobject_put(&mk->kobj);
> > }
>
> Arguably then, the BUG_ON macro seems more appropriate for this situation
> than this suggested doesnt_happen macro or my original offering of a call to
> pr_warning.
It does happen. If you don't wanna roll back on failure, just wrap it
in WARN_ON() so that there's at least some indication that something
failed there? It'd kinda suck to be missing some interface files w/o
any indication, wouldn't it?
Thanks.
--
tejun
next prev parent reply other threads:[~2015-06-03 20:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <FFF42EF7-42DB-4D5C-9C86-D8773E20D255@me.com>
[not found] ` <87vbf628uy.fsf@rustcorp.com.au>
2015-06-03 19:41 ` kernel/params.c: 'err' variable "set but not used" and perhaps should be? Louis Langholtz
2015-06-03 20:22 ` Tejun Heo [this message]
2015-06-04 1:33 ` Rusty Russell
2015-06-04 2:19 ` Tejun Heo
2015-06-04 19:46 ` Rusty Russell
2015-06-04 20:30 ` Tejun Heo
2015-06-05 0:39 ` Rusty Russell
2015-06-05 14:24 ` Tejun Heo
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=20150603202237.GI20091@mtj.duckdns.org \
--to=htejun@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lou_langholtz@me.com \
--cc=rusty@rustcorp.com.au \
/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