* [PATCH v3] media: nxp: imx8-isi: better handle the m2m usage_count
@ 2024-10-23 8:56 Laurentiu Palcu
2025-02-06 20:37 ` Laurent Pinchart
0 siblings, 1 reply; 3+ messages in thread
From: Laurentiu Palcu @ 2024-10-23 8:56 UTC (permalink / raw)
To: Laurent Pinchart, Mauro Carvalho Chehab, Shawn Guo, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Dong Aisheng,
Jacopo Mondi, Christian Hemp, Guoniu Zhou
Cc: Laurentiu Palcu, Stefan Riedmueller, linux-media, imx,
linux-arm-kernel, linux-kernel
Currently, if streamon/streamoff calls are imbalanced we can either end up
with a negative ISI m2m usage_count (if streamoff() is called more times
than streamon()) in which case we'll not be able to restart the ISI pipe
next time, or the usage_count never gets to 0 and the pipe is never
switched off.
To avoid that, add a 'streaming' flag to mxc_isi_m2m_ctx_queue_data and use it
in the streamon/streamoff to avoid incrementing/decrementing the usage_count
uselessly, if called multiple times from the same context.
Fixes: cf21f328fcafac ("media: nxp: Add i.MX8 ISI driver")
Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurentiu Palcu <laurentiu.palcu@oss.nxp.com>
---
v3:
* Changed the implementation as suggested by Laurent and add a Suggested-by
tag to reflect that;
v2:
* Changed the way 'usage_count' is incremented/decremented by taking
into account the context the streamon/streamoff functions are called
from;
* Changed the commit message and subject to reflect the changes;
drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c b/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
index 9745d6219a166..dc10e1a9f27c1 100644
--- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
+++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
@@ -43,6 +43,7 @@ struct mxc_isi_m2m_ctx_queue_data {
struct v4l2_pix_format_mplane format;
const struct mxc_isi_format_info *info;
u32 sequence;
+ bool streaming;
};
struct mxc_isi_m2m_ctx {
@@ -486,6 +487,7 @@ static int mxc_isi_m2m_streamon(struct file *file, void *fh,
enum v4l2_buf_type type)
{
struct mxc_isi_m2m_ctx *ctx = to_isi_m2m_ctx(fh);
+ struct mxc_isi_m2m_ctx_queue_data *q = mxc_isi_m2m_ctx_qdata(ctx, type);
const struct v4l2_pix_format_mplane *out_pix = &ctx->queues.out.format;
const struct v4l2_pix_format_mplane *cap_pix = &ctx->queues.cap.format;
const struct mxc_isi_format_info *cap_info = ctx->queues.cap.info;
@@ -495,6 +497,9 @@ static int mxc_isi_m2m_streamon(struct file *file, void *fh,
int ret;
+ if (q->streaming)
+ return 0;
+
mutex_lock(&m2m->lock);
if (m2m->usage_count == INT_MAX) {
@@ -547,6 +552,8 @@ static int mxc_isi_m2m_streamon(struct file *file, void *fh,
goto unchain;
}
+ q->streaming = true;
+
return 0;
unchain:
@@ -569,10 +576,14 @@ static int mxc_isi_m2m_streamoff(struct file *file, void *fh,
enum v4l2_buf_type type)
{
struct mxc_isi_m2m_ctx *ctx = to_isi_m2m_ctx(fh);
+ struct mxc_isi_m2m_ctx_queue_data *q = mxc_isi_m2m_ctx_qdata(ctx, type);
struct mxc_isi_m2m *m2m = ctx->m2m;
v4l2_m2m_ioctl_streamoff(file, fh, type);
+ if (!q->streaming)
+ return 0;
+
mutex_lock(&m2m->lock);
/*
@@ -598,6 +609,8 @@ static int mxc_isi_m2m_streamoff(struct file *file, void *fh,
mutex_unlock(&m2m->lock);
+ q->streaming = false;
+
return 0;
}
--
2.44.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] media: nxp: imx8-isi: better handle the m2m usage_count
2024-10-23 8:56 [PATCH v3] media: nxp: imx8-isi: better handle the m2m usage_count Laurentiu Palcu
@ 2025-02-06 20:37 ` Laurent Pinchart
2025-04-02 6:45 ` Laurentiu Palcu
0 siblings, 1 reply; 3+ messages in thread
From: Laurent Pinchart @ 2025-02-06 20:37 UTC (permalink / raw)
To: Laurentiu Palcu
Cc: Mauro Carvalho Chehab, Shawn Guo, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Dong Aisheng,
Jacopo Mondi, Christian Hemp, Guoniu Zhou, Stefan Riedmueller,
linux-media, imx, linux-arm-kernel, linux-kernel
Hi Laurentiu,
Thank you for the patch.
On Wed, Oct 23, 2024 at 11:56:43AM +0300, Laurentiu Palcu wrote:
> Currently, if streamon/streamoff calls are imbalanced we can either end up
> with a negative ISI m2m usage_count (if streamoff() is called more times
> than streamon()) in which case we'll not be able to restart the ISI pipe
> next time, or the usage_count never gets to 0 and the pipe is never
> switched off.
>
> To avoid that, add a 'streaming' flag to mxc_isi_m2m_ctx_queue_data and use it
> in the streamon/streamoff to avoid incrementing/decrementing the usage_count
> uselessly, if called multiple times from the same context.
>
> Fixes: cf21f328fcafac ("media: nxp: Add i.MX8 ISI driver")
> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Laurentiu Palcu <laurentiu.palcu@oss.nxp.com>
> ---
> v3:
> * Changed the implementation as suggested by Laurent and add a Suggested-by
> tag to reflect that;
>
> v2:
> * Changed the way 'usage_count' is incremented/decremented by taking
> into account the context the streamon/streamoff functions are called
> from;
> * Changed the commit message and subject to reflect the changes;
>
> drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c b/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
> index 9745d6219a166..dc10e1a9f27c1 100644
> --- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
> +++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
> @@ -43,6 +43,7 @@ struct mxc_isi_m2m_ctx_queue_data {
> struct v4l2_pix_format_mplane format;
> const struct mxc_isi_format_info *info;
> u32 sequence;
> + bool streaming;
> };
>
> struct mxc_isi_m2m_ctx {
> @@ -486,6 +487,7 @@ static int mxc_isi_m2m_streamon(struct file *file, void *fh,
> enum v4l2_buf_type type)
> {
> struct mxc_isi_m2m_ctx *ctx = to_isi_m2m_ctx(fh);
> + struct mxc_isi_m2m_ctx_queue_data *q = mxc_isi_m2m_ctx_qdata(ctx, type);
> const struct v4l2_pix_format_mplane *out_pix = &ctx->queues.out.format;
> const struct v4l2_pix_format_mplane *cap_pix = &ctx->queues.cap.format;
> const struct mxc_isi_format_info *cap_info = ctx->queues.cap.info;
> @@ -495,6 +497,9 @@ static int mxc_isi_m2m_streamon(struct file *file, void *fh,
>
While at it I'll drop the blank line here when applying the patch.
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> int ret;
>
> + if (q->streaming)
> + return 0;
> +
> mutex_lock(&m2m->lock);
>
> if (m2m->usage_count == INT_MAX) {
> @@ -547,6 +552,8 @@ static int mxc_isi_m2m_streamon(struct file *file, void *fh,
> goto unchain;
> }
>
> + q->streaming = true;
> +
> return 0;
>
> unchain:
> @@ -569,10 +576,14 @@ static int mxc_isi_m2m_streamoff(struct file *file, void *fh,
> enum v4l2_buf_type type)
> {
> struct mxc_isi_m2m_ctx *ctx = to_isi_m2m_ctx(fh);
> + struct mxc_isi_m2m_ctx_queue_data *q = mxc_isi_m2m_ctx_qdata(ctx, type);
> struct mxc_isi_m2m *m2m = ctx->m2m;
>
> v4l2_m2m_ioctl_streamoff(file, fh, type);
>
> + if (!q->streaming)
> + return 0;
> +
> mutex_lock(&m2m->lock);
>
> /*
> @@ -598,6 +609,8 @@ static int mxc_isi_m2m_streamoff(struct file *file, void *fh,
>
> mutex_unlock(&m2m->lock);
>
> + q->streaming = false;
> +
> return 0;
> }
>
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] media: nxp: imx8-isi: better handle the m2m usage_count
2025-02-06 20:37 ` Laurent Pinchart
@ 2025-04-02 6:45 ` Laurentiu Palcu
0 siblings, 0 replies; 3+ messages in thread
From: Laurentiu Palcu @ 2025-04-02 6:45 UTC (permalink / raw)
To: Laurent Pinchart
Cc: Mauro Carvalho Chehab, Shawn Guo, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Dong Aisheng,
Jacopo Mondi, Christian Hemp, Guoniu Zhou, Stefan Riedmueller,
linux-media, imx, linux-arm-kernel, linux-kernel
Hi Laurent,
I'm really sorry to keep bugging you about this patch but it looks like
this one fell through the cracks again... :/
Thanks,
Laurentiu
On Thu, Feb 06, 2025 at 10:37:49PM +0200, Laurent Pinchart wrote:
> Hi Laurentiu,
>
> Thank you for the patch.
>
> On Wed, Oct 23, 2024 at 11:56:43AM +0300, Laurentiu Palcu wrote:
> > Currently, if streamon/streamoff calls are imbalanced we can either end up
> > with a negative ISI m2m usage_count (if streamoff() is called more times
> > than streamon()) in which case we'll not be able to restart the ISI pipe
> > next time, or the usage_count never gets to 0 and the pipe is never
> > switched off.
> >
> > To avoid that, add a 'streaming' flag to mxc_isi_m2m_ctx_queue_data and use it
> > in the streamon/streamoff to avoid incrementing/decrementing the usage_count
> > uselessly, if called multiple times from the same context.
> >
> > Fixes: cf21f328fcafac ("media: nxp: Add i.MX8 ISI driver")
> > Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > Signed-off-by: Laurentiu Palcu <laurentiu.palcu@oss.nxp.com>
> > ---
> > v3:
> > * Changed the implementation as suggested by Laurent and add a Suggested-by
> > tag to reflect that;
> >
> > v2:
> > * Changed the way 'usage_count' is incremented/decremented by taking
> > into account the context the streamon/streamoff functions are called
> > from;
> > * Changed the commit message and subject to reflect the changes;
> >
> > drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c | 13 +++++++++++++
> > 1 file changed, 13 insertions(+)
> >
> > diff --git a/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c b/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
> > index 9745d6219a166..dc10e1a9f27c1 100644
> > --- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
> > +++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
> > @@ -43,6 +43,7 @@ struct mxc_isi_m2m_ctx_queue_data {
> > struct v4l2_pix_format_mplane format;
> > const struct mxc_isi_format_info *info;
> > u32 sequence;
> > + bool streaming;
> > };
> >
> > struct mxc_isi_m2m_ctx {
> > @@ -486,6 +487,7 @@ static int mxc_isi_m2m_streamon(struct file *file, void *fh,
> > enum v4l2_buf_type type)
> > {
> > struct mxc_isi_m2m_ctx *ctx = to_isi_m2m_ctx(fh);
> > + struct mxc_isi_m2m_ctx_queue_data *q = mxc_isi_m2m_ctx_qdata(ctx, type);
> > const struct v4l2_pix_format_mplane *out_pix = &ctx->queues.out.format;
> > const struct v4l2_pix_format_mplane *cap_pix = &ctx->queues.cap.format;
> > const struct mxc_isi_format_info *cap_info = ctx->queues.cap.info;
> > @@ -495,6 +497,9 @@ static int mxc_isi_m2m_streamon(struct file *file, void *fh,
> >
>
> While at it I'll drop the blank line here when applying the patch.
>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>
> > int ret;
> >
> > + if (q->streaming)
> > + return 0;
> > +
> > mutex_lock(&m2m->lock);
> >
> > if (m2m->usage_count == INT_MAX) {
> > @@ -547,6 +552,8 @@ static int mxc_isi_m2m_streamon(struct file *file, void *fh,
> > goto unchain;
> > }
> >
> > + q->streaming = true;
> > +
> > return 0;
> >
> > unchain:
> > @@ -569,10 +576,14 @@ static int mxc_isi_m2m_streamoff(struct file *file, void *fh,
> > enum v4l2_buf_type type)
> > {
> > struct mxc_isi_m2m_ctx *ctx = to_isi_m2m_ctx(fh);
> > + struct mxc_isi_m2m_ctx_queue_data *q = mxc_isi_m2m_ctx_qdata(ctx, type);
> > struct mxc_isi_m2m *m2m = ctx->m2m;
> >
> > v4l2_m2m_ioctl_streamoff(file, fh, type);
> >
> > + if (!q->streaming)
> > + return 0;
> > +
> > mutex_lock(&m2m->lock);
> >
> > /*
> > @@ -598,6 +609,8 @@ static int mxc_isi_m2m_streamoff(struct file *file, void *fh,
> >
> > mutex_unlock(&m2m->lock);
> >
> > + q->streaming = false;
> > +
> > return 0;
> > }
> >
>
> --
> Regards,
>
> Laurent Pinchart
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-02 6:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-23 8:56 [PATCH v3] media: nxp: imx8-isi: better handle the m2m usage_count Laurentiu Palcu
2025-02-06 20:37 ` Laurent Pinchart
2025-04-02 6:45 ` Laurentiu Palcu
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).