All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch/rfc] Make poll/select report error (POLLNVAL and EBADF) for unsupported files
@ 2010-02-14 22:27 Davide Libenzi
  2010-02-15 17:42 ` Eric Dumazet
  0 siblings, 1 reply; 6+ messages in thread
From: Davide Libenzi @ 2010-02-14 22:27 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: Andrew Morton, stephane.thiell

Currently poll and select consider a non poll-supported file as one with 
full event mask set, instead of reporting proper error to the caller.
This behavior can fool the caller of proper functionality being returned, 
while instead no valid event was processed/read from the device.
This came out linked to this bug report:

http://bugzilla.kernel.org/show_bug.cgi?id=15272

IMHO, it'd be more adequate to report proper error code, for files that do 
not support f_op->poll(), but then I am also not sure how much breakage 
can this bring to existing (already broken "in just the right way") 
applications.
Untested, discussion-only, patch.


Signed-off-by: Davide Libenzi <davidel@xmailserver.org>


- Davide


---
 fs/select.c |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

Index: linux-2.6.mod/fs/select.c
===================================================================
--- linux-2.6.mod.orig/fs/select.c	2010-02-14 14:06:12.000000000 -0800
+++ linux-2.6.mod/fs/select.c	2010-02-14 14:16:09.000000000 -0800
@@ -447,12 +447,13 @@ int do_select(int n, fd_set_bits *fds, s
 					continue;
 				file = fget_light(i, &fput_needed);
 				if (file) {
-					f_op = file->f_op;
-					mask = DEFAULT_POLLMASK;
-					if (f_op && f_op->poll) {
-						wait_key_set(wait, in, out, bit);
-						mask = (*f_op->poll)(file, wait);
+					if (unlikely((f_op = file->f_op) == NULL ||
+						     f_op->poll == NULL)) {
+						retval = -EBADF;
+						goto error_exit;
 					}
+					wait_key_set(wait, in, out, bit);
+					mask = (*f_op->poll)(file, wait);
 					fput_light(file, fput_needed);
 					if ((mask & POLLIN_SET) && (in & bit)) {
 						res_in |= bit;
@@ -501,7 +502,7 @@ int do_select(int n, fd_set_bits *fds, s
 					   to, slack))
 			timed_out = 1;
 	}
-
+error_exit:
 	poll_freewait(&table);
 
 	return retval;
@@ -720,15 +721,14 @@ static inline unsigned int do_pollfd(str
 		file = fget_light(fd, &fput_needed);
 		mask = POLLNVAL;
 		if (file != NULL) {
-			mask = DEFAULT_POLLMASK;
 			if (file->f_op && file->f_op->poll) {
 				if (pwait)
 					pwait->key = pollfd->events |
 							POLLERR | POLLHUP;
 				mask = file->f_op->poll(file, pwait);
+				/* Mask out unneeded events. */
+				mask &= pollfd->events | POLLERR | POLLHUP;
 			}
-			/* Mask out unneeded events. */
-			mask &= pollfd->events | POLLERR | POLLHUP;
 			fput_light(file, fput_needed);
 		}
 	}


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

end of thread, other threads:[~2010-02-17 18:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-14 22:27 [patch/rfc] Make poll/select report error (POLLNVAL and EBADF) for unsupported files Davide Libenzi
2010-02-15 17:42 ` Eric Dumazet
2010-02-15 17:47   ` Eric Dumazet
2010-02-15 17:50   ` Davide Libenzi
2010-02-17 17:21     ` THIELL Stephane
2010-02-17 18:16       ` Davide Libenzi

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.