From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Zile Xiong <xiongzile99@gmail.com>,
Tomasz Figa <tfiga@chromium.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Hans Verkuil <hverkuil@kernel.org>
Subject: Re: [RFC PATCH] media: vb2: use ssize_t for vb2_read/vb2_write
Date: Fri, 20 Mar 2026 08:59:50 +0100 [thread overview]
Message-ID: <7b2a7e76-9025-41b8-8136-7af867d8146d@samsung.com> (raw)
In-Reply-To: <20260320065445.75351-1-xiongzile99@gmail.com>
On 20.03.2026 07:54, Zile Xiong wrote:
> vb2_read() and vb2_write() return size_t, but propagate
> negative errno values from __vb2_perform_fileio().
>
> This relies on implicit signed/unsigned conversions in callers
> (e.g. vb2_fop_read()) to recover error codes:
>
> __vb2_perform_fileio() -> -EINVAL
> vb2_read() -> (size_t)-EINVAL
> vb2_fop_read() -> -EINVAL
>
> This relies on implicit conversions that are not obvious.
>
> These helpers are exported (EXPORT_SYMBOL_GPL) and part of the
> vb2 API, so changing their return type may affect existing users.
>
> However, they conceptually follow read/write semantics, where
> ssize_t is typically used to return either a byte count or a
> negative error code.
>
> Switch vb2_read() and vb2_write() to ssize_t, and update
> __vb2_perform_fileio() accordingly.
>
> This is an RFC to gather feedback.
>
> Signed-off-by: Zile Xiong <xiongzile99@gmail.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
vb2_fop_read() and vb2_fop_write() return ssize_t type, so the same
should be used for vb2_read() and vb2_write(), as well as
__vb2_perform_fileio(). This issue was there from the beginning of this
code, so it would make sense to add:
Fixes: b25748fe6126 ("[media] v4l: videobuf2: add read() and write()
emulator")
> ---
> drivers/media/common/videobuf2/videobuf2-core.c | 6 +++---
> include/media/videobuf2-core.h | 4 ++--
> 2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
> index adf668b213c2..8a2b8156e9da 100644
> --- a/drivers/media/common/videobuf2/videobuf2-core.c
> +++ b/drivers/media/common/videobuf2/videobuf2-core.c
> @@ -2990,7 +2990,7 @@ static int __vb2_cleanup_fileio(struct vb2_queue *q)
> * @nonblock: mode selector (1 means blocking calls, 0 means nonblocking)
> * @read: access mode selector (1 means read, 0 means write)
> */
> -static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_t count,
> +static ssize_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_t count,
> loff_t *ppos, int nonblock, int read)
> {
> struct vb2_fileio_data *fileio;
> @@ -3154,14 +3154,14 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
> return ret;
> }
>
> -size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
> +ssize_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
> loff_t *ppos, int nonblocking)
> {
> return __vb2_perform_fileio(q, data, count, ppos, nonblocking, 1);
> }
> EXPORT_SYMBOL_GPL(vb2_read);
>
> -size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
> +ssize_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
> loff_t *ppos, int nonblocking)
> {
> return __vb2_perform_fileio(q, (char __user *) data, count,
> diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
> index 4424d481d7f7..bf20bcb1d366 100644
> --- a/include/media/videobuf2-core.h
> +++ b/include/media/videobuf2-core.h
> @@ -1093,7 +1093,7 @@ __poll_t vb2_core_poll(struct vb2_queue *q, struct file *file,
> * @ppos: file handle position tracking pointer
> * @nonblock: mode selector (1 means blocking calls, 0 means nonblocking)
> */
> -size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
> +ssize_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
> loff_t *ppos, int nonblock);
> /**
> * vb2_write() - implements write() syscall logic.
> @@ -1103,7 +1103,7 @@ size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
> * @ppos: file handle position tracking pointer
> * @nonblock: mode selector (1 means blocking calls, 0 means nonblocking)
> */
> -size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
> +ssize_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
> loff_t *ppos, int nonblock);
>
> /**
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
next prev parent reply other threads:[~2026-03-20 7:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20260320065508eucas1p10be4e6428076c2f2d396eb4474d64935@eucas1p1.samsung.com>
2026-03-20 6:54 ` Zile Xiong
2026-03-20 7:59 ` Marek Szyprowski [this message]
2026-03-20 8:15 ` [PATCH v2] " Zile Xiong
2026-03-20 11:30 ` [PATCH v3] " Zile Xiong
2026-04-01 7:48 ` Zile Xiong
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=7b2a7e76-9025-41b8-8136-7af867d8146d@samsung.com \
--to=m.szyprowski@samsung.com \
--cc=hverkuil@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=tfiga@chromium.org \
--cc=xiongzile99@gmail.com \
/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
all inboxes | Powered by JetHome®