LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>,
	linux-kernel@vger.kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	"J. Bruce Fields" <bfields@fieldses.org>
Subject: Re: [PATCH] Change wait_for_completion_*_timeout to return a signed long
Date: Thu, 6 Jan 2011 11:33:27 +1100	[thread overview]
Message-ID: <20110106113327.5d224a8c@notabene.brown> (raw)
In-Reply-To: <20110105145725.3fa6d659.akpm@linux-foundation.org>

On Wed, 5 Jan 2011 14:57:25 -0800 Andrew Morton <akpm@linux-foundation.org>
wrote:

> On Wed, 5 Jan 2011 12:50:16 +1100
> NeilBrown <neilb@suse.de> wrote:
> 
> > 
> > wait_for_completion_*_timeout can return:
> > 
> >  0 if the wait timed out
> >  -ve if the wait was interrupted
> >  +ve if the completion was completed.
> > 
> > As they currently return an 'unsigned long', the last two cases are not
> > easily distinguished which can easily result in buggy code, as is the
> > case for the recently added wait_for_completion_interruptible_timeout
> > call in net/sunrpc/cache.c
> > 
> > So change them both to return 'long'.  As MAX_SCHEDULE_TIMEOUT is
> > LONG_MAX, a large +ve return value should never overflow.
> > 
> > ...
> >
> > --- a/include/linux/completion.h
> > +++ b/include/linux/completion.h
> > @@ -80,11 +80,11 @@ extern void wait_for_completion(struct completion *);
> >  extern int wait_for_completion_interruptible(struct completion *x);
> >  extern int wait_for_completion_killable(struct completion *x);
> >  extern unsigned long wait_for_completion_timeout(struct completion *x,
> >  						   unsigned long timeout);
> > -extern unsigned long wait_for_completion_interruptible_timeout(
> > -			struct completion *x, unsigned long timeout);
> > -extern unsigned long wait_for_completion_killable_timeout(
> > -			struct completion *x, unsigned long timeout);
> > +extern long wait_for_completion_interruptible_timeout(
> > +	struct completion *x, unsigned long timeout);
> > +extern long wait_for_completion_killable_timeout(
> > +	struct completion *x, unsigned long timeout);
> >  extern bool try_wait_for_completion(struct completion *x);
> >  extern bool completion_done(struct completion *x);
> >  
> 
> That's a half-patch, isn't it?  wait_for_completion_interruptible()
> still incorrectly returns `int' and wait_for_completion_timeout() still
> returns `unsigned long'.

Half a patch is better than half a bug report is better than half an oops
message is better than none ..... (am I showing my age?)


wait_for_completion_interruptile returns either a negative error (-ERESTART)
or 0.  So 'int' is fine.  Ditto for wait_for_completion_killable.
wait_for_completion_timeout returns a positive timeout-remaining or 0, so
'unsigned long' is fine.

It is only when we come to combining 'interruptible' and 'timeout' that we
need signed and long.

Now maybe it would be good to use "signed long" for all of them because
consistency is a nice thing.  Or maybe it is best to specify in each case the
return type that is most clearly meaningful because that communicates more
clearly.
I really cannot say - I just wanted to fix a bug :-)

NeilBrown

      reply	other threads:[~2011-01-06  0:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-05  1:50 NeilBrown
2011-01-05 14:07 ` [tip:sched/core] sched: Change wait_for_completion_*_timeout() " tip-bot for NeilBrown
2011-01-11 21:44   ` J. Bruce Fields
2011-01-11 22:07     ` NeilBrown
2011-02-15 16:20       ` [stable] " Greg KH
2011-01-05 22:57 ` [PATCH] Change wait_for_completion_*_timeout " Andrew Morton
2011-01-06  0:33   ` NeilBrown [this message]

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=20110106113327.5d224a8c@notabene.brown \
    --to=neilb@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=bfields@fieldses.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    --subject='Re: [PATCH] Change wait_for_completion_*_timeout to return a signed long' \
    /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

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).