media: nxp: imx8-isi: better handle the m2m usage_count

commit 910efa649076be9c2e1326059830327cf4228cf6 upstream.

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: cf21f328fc ("media: nxp: Add i.MX8 ISI driver")
Cc: stable@vger.kernel.org
Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurentiu Palcu <laurentiu.palcu@oss.nxp.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Link: https://lore.kernel.org/r/20241023085643.978729-1-laurentiu.palcu@oss.nxp.com
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Laurentiu Palcu
2024-10-23 11:56:43 +03:00
committed by Greg Kroah-Hartman
parent 585acb3549
commit ecaf904a55

View File

@@ -43,6 +43,7 @@ struct mxc_isi_m2m_ctx_queue_data {
struct v4l2_pix_format_mplane format; struct v4l2_pix_format_mplane format;
const struct mxc_isi_format_info *info; const struct mxc_isi_format_info *info;
u32 sequence; u32 sequence;
bool streaming;
}; };
struct mxc_isi_m2m_ctx { struct mxc_isi_m2m_ctx {
@@ -486,15 +487,18 @@ static int mxc_isi_m2m_streamon(struct file *file, void *fh,
enum v4l2_buf_type type) enum v4l2_buf_type type)
{ {
struct mxc_isi_m2m_ctx *ctx = to_isi_m2m_ctx(fh); 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 *out_pix = &ctx->queues.out.format;
const struct v4l2_pix_format_mplane *cap_pix = &ctx->queues.cap.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; const struct mxc_isi_format_info *cap_info = ctx->queues.cap.info;
const struct mxc_isi_format_info *out_info = ctx->queues.out.info; const struct mxc_isi_format_info *out_info = ctx->queues.out.info;
struct mxc_isi_m2m *m2m = ctx->m2m; struct mxc_isi_m2m *m2m = ctx->m2m;
bool bypass; bool bypass;
int ret; int ret;
if (q->streaming)
return 0;
mutex_lock(&m2m->lock); mutex_lock(&m2m->lock);
if (m2m->usage_count == INT_MAX) { if (m2m->usage_count == INT_MAX) {
@@ -547,6 +551,8 @@ static int mxc_isi_m2m_streamon(struct file *file, void *fh,
goto unchain; goto unchain;
} }
q->streaming = true;
return 0; return 0;
unchain: unchain:
@@ -569,10 +575,14 @@ static int mxc_isi_m2m_streamoff(struct file *file, void *fh,
enum v4l2_buf_type type) enum v4l2_buf_type type)
{ {
struct mxc_isi_m2m_ctx *ctx = to_isi_m2m_ctx(fh); 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; struct mxc_isi_m2m *m2m = ctx->m2m;
v4l2_m2m_ioctl_streamoff(file, fh, type); v4l2_m2m_ioctl_streamoff(file, fh, type);
if (!q->streaming)
return 0;
mutex_lock(&m2m->lock); mutex_lock(&m2m->lock);
/* /*
@@ -598,6 +608,8 @@ static int mxc_isi_m2m_streamoff(struct file *file, void *fh,
mutex_unlock(&m2m->lock); mutex_unlock(&m2m->lock);
q->streaming = false;
return 0; return 0;
} }