linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org,
	Wanlong Gao <gaowanlong@cn.fujitsu.com>,
	Che-Liang Chiou <clchiou@chromium.org>,
	David Herrmann <dh.herrmann@googlemail.com>
Subject: Re: [PATCH] Input: serio_raw - signal EFAULT even if read/write partially succeeds
Date: Mon, 30 Apr 2012 11:12:23 +0100	[thread overview]
Message-ID: <20120430111223.4941a9f0@pyramind.ukuu.org.uk> (raw)
In-Reply-To: <20120430064450.GA29212@core.coreip.homeip.net>

On Sun, 29 Apr 2012 23:44:51 -0700
Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:

> When copy_to/from_user fails in the middle of transfer we should not
> report to the user that read/write partially succeeded but rather
> report -EFAULT right away, so that application will know that it got
> its buffers all wrong.

Actually POSIX/SuS is quite explicit that if a write or read partially
succeeds you return the partial result. The error will be returned only
if nothing was written or read, or in some cases can be buffered by the
code for the next read/write attempt (eg for sockets).

In the wait_event_interruptible() case it's even more important as a
signal handler and syscall restart needs to do the right thing. Looking
at the patch it looks like a signal interrupting loses you data with this
change appplied. The -EFAULT one is a corner case, the signal handlers
causing data loss one is not.

EFAULT matters for certain crazy software like persistent storage managers
which use -EFAULT and segfault/bus error catching to implement full
persistent storage. Those people may well be somewhat out of their tree.

> -		if (!(file->f_flags & O_NONBLOCK))
> +		if (!(file->f_flags & O_NONBLOCK)) {
>  			error = wait_event_interruptible(serio_raw->wait,
>  					serio_raw->head != serio_raw->tail ||
>  					serio_raw->dead);
> -	} while (!error);
> +			if (error)
> +				return error;

And we lose data as far as I can see, so a timer event will cause the app
to malfunction.

Alan

  reply	other threads:[~2012-04-30 10:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-30  6:44 [PATCH] Input: serio_raw - signal EFAULT even if read/write partially succeeds Dmitry Torokhov
2012-04-30 10:12 ` Alan Cox [this message]
2012-04-30 16:34   ` Dmitry Torokhov
2012-04-30 21:26     ` Alan Cox
2012-04-30 21:54       ` Dmitry Torokhov

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=20120430111223.4941a9f0@pyramind.ukuu.org.uk \
    --to=alan@lxorguk.ukuu.org.uk \
    --cc=clchiou@chromium.org \
    --cc=dh.herrmann@googlemail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gaowanlong@cn.fujitsu.com \
    --cc=linux-input@vger.kernel.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 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).