diff mbox series

[1/3] iio: buffer: correctly return bytes written in output buffers

Message ID 20230216101452.591805-2-nuno.sa@analog.com (mailing list archive)
State Accepted
Headers show
Series output buffer write fops fixes | expand

Commit Message

Nuno Sa Feb. 16, 2023, 10:14 a.m. UTC
If for some reason 'rb->access->write()' does not write the full
requested data and the O_NONBLOCK is set, we would return 'n' to
userspace which is not really truth. Hence, let's return the number of
bytes we effectively wrote.

Fixes: 9eeee3b0bf190 ("iio: Add output buffer support")
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
 drivers/iio/industrialio-buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Lars-Peter Clausen Feb. 16, 2023, 1:40 p.m. UTC | #1
On 2/16/23 02:14, Nuno Sá wrote:
> If for some reason 'rb->access->write()' does not write the full
> requested data and the O_NONBLOCK is set, we would return 'n' to
> userspace which is not really truth. Hence, let's return the number of
> bytes we effectively wrote.
>
> Fixes: 9eeee3b0bf190 ("iio: Add output buffer support")
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>

Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>

> ---
>   drivers/iio/industrialio-buffer.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index 228598b82a2f..c56cf748fde1 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -220,7 +220,7 @@ static ssize_t iio_buffer_write(struct file *filp, const char __user *buf,
>   	} while (ret == 0);
>   	remove_wait_queue(&rb->pollq, &wait);
>   
> -	return ret < 0 ? ret : n;
> +	return ret < 0 ? ret : written;
>   }
>   
>   /**
Jonathan Cameron Feb. 18, 2023, 2:07 p.m. UTC | #2
On Thu, 16 Feb 2023 05:40:46 -0800
Lars-Peter Clausen <lars@metafoo.de> wrote:

> On 2/16/23 02:14, Nuno Sá wrote:
> > If for some reason 'rb->access->write()' does not write the full
> > requested data and the O_NONBLOCK is set, we would return 'n' to
> > userspace which is not really truth. Hence, let's return the number of
> > bytes we effectively wrote.
> >
> > Fixes: 9eeee3b0bf190 ("iio: Add output buffer support")
> > Signed-off-by: Nuno Sá <nuno.sa@analog.com>  
> 
> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

J
> 
> > ---
> >   drivers/iio/industrialio-buffer.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> > index 228598b82a2f..c56cf748fde1 100644
> > --- a/drivers/iio/industrialio-buffer.c
> > +++ b/drivers/iio/industrialio-buffer.c
> > @@ -220,7 +220,7 @@ static ssize_t iio_buffer_write(struct file *filp, const char __user *buf,
> >   	} while (ret == 0);
> >   	remove_wait_queue(&rb->pollq, &wait);
> >   
> > -	return ret < 0 ? ret : n;
> > +	return ret < 0 ? ret : written;
> >   }
> >   
> >   /**  
> 
>
diff mbox series

Patch

diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 228598b82a2f..c56cf748fde1 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -220,7 +220,7 @@  static ssize_t iio_buffer_write(struct file *filp, const char __user *buf,
 	} while (ret == 0);
 	remove_wait_queue(&rb->pollq, &wait);
 
-	return ret < 0 ? ret : n;
+	return ret < 0 ? ret : written;
 }
 
 /**