All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jamie Lokier <jamie@shareable.org>
To: Jesper Juhl <juhl-lkml@dif.dk>
Cc: Matthew Wilcox <matthew@wil.cx>,
	Linus Torvalds <torvalds@osdl.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Remove pointless <0 comparison for unsigned variable in fs/fcntl.c
Date: Tue, 23 Nov 2004 10:42:15 +0000	[thread overview]
Message-ID: <20041123104215.GE27064@mail.shareable.org> (raw)
In-Reply-To: <41A30612.2040700@dif.dk>

Jesper Juhl wrote:
> >>	case F_SETSIG:
> >>		/* arg == 0 restores default behaviour. */
> >>-		if (arg < 0 || arg > _NSIG) {
> >>+		if (arg > _NSIG) {
> >>			break;
> >
> Let's find out.

The unusual thing about this function is that "arg" is really
polymorphic, but given type "unsigned long" in the kernel.  It is
really a way to hold arbitrary values of any type.

Just look at the way it becomes "unsigned int" (dupfd) or "struct
flock" (lock) or "long" (leases) or "int" (setown).

F_SETOWN is interesting because you really can pass a negative int
argument and get a meaningful result, even though it's passed around
as unsigned long for a little while.

Signal numbers are usually "int".  The intended behaviour of fcntl(fd,
F_SETSIG, sig) from userspace is that a negative sig returns EINVAL.

I.e. writing fcntl(fd, F_SETSIG, -1) in userspace will compile without
any warnings.  The intended behaviour is that a negative sig returns
EINVAL.  The kernel code illustrates that intention.

It isn't obvious that arg is unsigned long in this function, when
reading the code.  I had to scroll to the top of the function to check
that this patch doesn't change its behaviour.  For that reason I think
the "< 0" test is useful, as it illustrates the intended behaviour and
causes no harm.

-- Jamie

  reply	other threads:[~2004-11-23 10:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-21 22:55 [PATCH] Remove pointless <0 comparison for unsigned variable in fs/fcntl.c Jesper Juhl
2004-11-22  1:02 ` Matthew Wilcox
2004-11-23  9:42   ` Jesper Juhl
2004-11-23 10:42     ` Jamie Lokier [this message]
2004-11-23 18:28       ` Bryan Henderson
2004-11-23 18:03     ` Linus Torvalds
2004-11-23 18:39       ` Jesper Juhl
2004-11-23 18:37         ` Linus Torvalds
2004-11-23 19:20           ` linux-os
2004-11-23 23:16           ` Jesper Juhl
2004-11-23 19:13       ` Timur Tabi
2004-11-23 23:09         ` Jesper Juhl
2004-11-23 23:03           ` Timur Tabi
2004-11-23 23:19             ` Jesper Juhl
2004-11-23 23:09               ` Timur Tabi
2004-11-23 23:28                 ` Jesper Juhl
2004-11-25 22:34             ` Valdis.Kletnieks

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=20041123104215.GE27064@mail.shareable.org \
    --to=jamie@shareable.org \
    --cc=juhl-lkml@dif.dk \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew@wil.cx \
    --cc=torvalds@osdl.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 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.