# Re: \[PATCHv2\] evdev: fix evdev\_write return value on partial writes

- List: linux-input
- 4 messages, 3 authors
- Page: https://ratatoskr.run/linux-input/2011/02/8916064/t

## Re: \[PATCHv2\] evdev: fix evdev\_write return value on partial writes

- From: Peter Korsgaard \<jacmet@sunsite.dk\>
- Date: 2011-02-04 11:00:38 
- Message: https://ratatoskr.run/linux-input/2011/02/8916064.md

```text
>>>>> "Henrik" == Henrik Rydberg [ref] writes:

Hi,

 >> I think that returning -EINVAL is good idea, so I am going to apply it.
 >> I also think we can change this loop to do-while kind since we already
 >> checked there enough space for an event.

 Henrik> The code below will return -EINVAL even if some parts of the buffer
 Henrik> was successfully read, though.

You mean written? I don't see that. The only place we return -EINVAL is
at the initial check.

 >> --- a/drivers/input/evdev.c
 >> +++ b/drivers/input/evdev.c
 >> @@ -321,6 +321,9 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer,
 >> struct input_event event;
 >> int retval;

 Henrik> Alternatively,

 Henrik> size_t num_written = 0;
 Henrik> int ret = 0;

Any reason for this bigger change? It's imho pretty clear as is. I don't
see any functional change from your version.

-- 
Bye, Peter Korsgaard
```

## Re: \[PATCHv2\] evdev: fix evdev\_write return value on partial writes

- From: Henrik Rydberg \<hidden\>
- Date: 2011-02-04 11:23:54 
- Message: https://ratatoskr.run/linux-input/2011/02/8916065.md

```text
>  Henrik> The code below will return -EINVAL even if some parts of the buffer
>  Henrik> was successfully read, though.
> 
> You mean written? I don't see that. The only place we return -EINVAL is
> at the initial check.

Right, it should have been written, and -EFAULT, referring to the code
in the loop.

Henrik
```

## Re: \[PATCHv2\] evdev: fix evdev\_write return value on partial writes

- From: Dmitry Torokhov \<dmitry.torokhov@gmail.com\>
- Date: 2011-02-04 17:15:30 
- Message: https://ratatoskr.run/linux-input/2011/02/8916067.md

```text
On Fri, Feb 04, 2011 at 12:23:14PM +0100, Henrik Rydberg wrote:
> >  Henrik> The code below will return -EINVAL even if some parts of the buffer
> >  Henrik> was successfully read, though.
> > 
> > You mean written? I don't see that. The only place we return -EINVAL is
> > at the initial check.
> 
> Right, it should have been written, and -EFAULT, referring to the code
> in the loop.
> 

If we faulted somewhere midway the only sane thing it to treat the whole
request as suspect and return -EFAULT. We really do not know what
happened to the other data (it could have gone past the buffer user
intended but haven't triggered the fault yet. We can't fully recover
either since we aleady retrievend the event that caused fault.

-- 
Dmitry
```

## Re: \[PATCHv2\] evdev: fix evdev\_write return value on partial writes

- From: Henrik Rydberg \<hidden\>
- Date: 2011-02-04 17:22:57 
- Message: https://ratatoskr.run/linux-input/2011/02/8916068.md

```text
On Fri, Feb 04, 2011 at 09:15:19AM -0800, Dmitry Torokhov wrote:
> On Fri, Feb 04, 2011 at 12:23:14PM +0100, Henrik Rydberg wrote:
> > >  Henrik> The code below will return -EINVAL even if some parts of the buffer
> > >  Henrik> was successfully read, though.
> > > 
> > > You mean written? I don't see that. The only place we return -EINVAL is
> > > at the initial check.
> > 
> > Right, it should have been written, and -EFAULT, referring to the code
> > in the loop.
> > 
> 
> If we faulted somewhere midway the only sane thing it to treat the whole
> request as suspect and return -EFAULT. We really do not know what
> happened to the other data (it could have gone past the buffer user
> intended but haven't triggered the fault yet. We can't fully recover
> either since we aleady retrievend the event that caused fault.

Alright. I think all ambiguities have now been exhausted, so ACK from
me as well. :-)

Thanks,
Henrik
```
