All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] firewire: cdev: return -ENOTTY for unimplemented ioctls, not -EINVAL
@ 2011-07-09 14:42 Stefan Richter
  2011-07-09 14:43 ` [PATCH] firewire: cdev: prevent race between first get_info ioctl and bus reset event queuing Stefan Richter
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Richter @ 2011-07-09 14:42 UTC (permalink / raw)
  To: linux1394-devel; +Cc: linux-kernel

On Jun 27 Linus Torvalds wrote:
> The correct error code for "I don't understand this ioctl" is ENOTTY.
> The naming may be odd, but you should think of that error value as a
> "unrecognized ioctl number, you're feeding me random numbers that I
> don't understand and I assume for historical reasons that you tried to
> do some tty operation on me".
[...]
> The EINVAL thing goes way back, and is a disaster. It predates Linux
> itself, as far as I can tell. You'll find lots of man-pages that have
> this line in it:
> 
>   EINVAL Request or argp is not valid.
> 
> and it shows up in POSIX etc. And sadly, it generally shows up
> _before_ the line that says
> 
>   ENOTTY The specified request does not apply to the kind of object
> that the descriptor d references.
> 
> so a lot of people get to the EINVAL, and never even notice the ENOTTY.
[...]
> At least glibc (and hopefully other C libraries) use a _string_ that
> makes much more sense: strerror(ENOTTY) is "Inappropriate ioctl for
> device"

So let's correct this in the <linux/firewire-cdev.h> ABI while it is
still young, relative to distributor adoption.

Side note:  We return -ENOTTY not only on _IOC_TYPE or _IOC_NR mismatch,
but also on _IOC_SIZE mismatch.  An ioctl with an unsupported size of
argument structure can be seen as an unsupported version of that ioctl.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Cc: <stable@kernel.org>
---
 drivers/firewire/core-cdev.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: b/drivers/firewire/core-cdev.c
===================================================================
--- a/drivers/firewire/core-cdev.c
+++ b/drivers/firewire/core-cdev.c
@@ -1583,7 +1583,7 @@ static int dispatch_ioctl(struct client
 	if (_IOC_TYPE(cmd) != '#' ||
 	    _IOC_NR(cmd) >= ARRAY_SIZE(ioctl_handlers) ||
 	    _IOC_SIZE(cmd) > sizeof(buffer))
-		return -EINVAL;
+		return -ENOTTY;
 
 	if (_IOC_DIR(cmd) == _IOC_READ)
 		memset(&buffer, 0, _IOC_SIZE(cmd));


-- 
Stefan Richter
-=====-==-== -=== -=--=
http://arcgraph.de/sr/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-07-09 15:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-09 14:42 [PATCH] firewire: cdev: return -ENOTTY for unimplemented ioctls, not -EINVAL Stefan Richter
2011-07-09 14:43 ` [PATCH] firewire: cdev: prevent race between first get_info ioctl and bus reset event queuing Stefan Richter
2011-07-09 14:47   ` [PATCH] firewire: cdev: ABI documentation enhancements Stefan Richter
2011-07-09 14:48     ` [PATCH] firewire: document the sysfs ABIs Stefan Richter
2011-07-09 15:05     ` [PATCH] firewire: cdev: ABI documentation enhancements Stefan Richter

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.