From: Hans de Goede <hdegoede@redhat.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>,
Andy Shevchenko <andy@kernel.org>
Cc: Hans de Goede <hdegoede@redhat.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
linux-media@vger.kernel.org, linux-staging@lists.linux.dev
Subject: [PATCH 2/5] media: atomisp: Properly stop the ISP stream on sensor streamon errors
Date: Mon, 5 May 2025 23:00:05 +0200 [thread overview]
Message-ID: <20250505210008.152659-3-hdegoede@redhat.com> (raw)
In-Reply-To: <20250505210008.152659-1-hdegoede@redhat.com>
When v4l2_subdev_call(sensor, s_stream, 1) fails atomisp_start_streaming()
was not properly returning the buffer ownership back to the videobuf2-core
code, resulting in:
[ 1318.153447] ------------[ cut here ]------------
[ 1318.153499] WARNING: CPU: 0 PID: 4856 at drivers/media/common/videobuf2/videobuf2-core.c:1803 vb2_start_streaming+0xcb/0x160 [videobuf2_common]
...
[ 1318.154551] Call Trace:
[ 1318.154560] <TASK>
[ 1318.154571] ? __warn.cold+0xb7/0x14a
[ 1318.154591] ? vb2_start_streaming+0xcb/0x160 [videobuf2_common]
[ 1318.154617] ? report_bug+0xe0/0x180
[ 1318.154640] ? handle_bug+0x5e/0xa0
[ 1318.154652] ? exc_invalid_op+0x14/0x70
[ 1318.154665] ? asm_exc_invalid_op+0x16/0x20
[ 1318.154697] ? vb2_start_streaming+0xcb/0x160 [videobuf2_common]
[ 1318.154723] ? vb2_start_streaming+0x70/0x160 [videobuf2_common]
[ 1318.154748] vb2_core_streamon+0xa2/0x100 [videobuf2_common]
The sensor streamon call is the last thing that atomisp_start_streaming()
does and it was failing to undo all of the previous steps in general.
Refactor atomisp_stop_streaming() into an atomisp_stop_stream() helper and
call that on sensor streamon failure to properly clean things up.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
.../staging/media/atomisp/pci/atomisp_ioctl.c | 38 +++++++++++--------
1 file changed, 22 insertions(+), 16 deletions(-)
diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
index 705f104a2147..491af67cc7a8 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
@@ -856,18 +856,15 @@ static void atomisp_dma_burst_len_cfg(struct atomisp_sub_device *asd)
atomisp_css2_hw_store_32(DMA_BURST_SIZE_REG, 0x00);
}
-void atomisp_stop_streaming(struct vb2_queue *vq)
+static void atomisp_stop_stream(struct atomisp_video_pipe *pipe,
+ bool stop_sensor, enum vb2_buffer_state state)
{
- struct atomisp_video_pipe *pipe = vq_to_pipe(vq);
struct atomisp_sub_device *asd = pipe->asd;
struct atomisp_device *isp = asd->isp;
struct pci_dev *pdev = to_pci_dev(isp->dev);
unsigned long flags;
int ret;
- dev_dbg(isp->dev, "Stop stream\n");
-
- mutex_lock(&isp->mutex);
/*
* There is no guarantee that the buffers queued to / owned by the ISP
* will properly be returned to the queue when stopping. Set a flag to
@@ -893,14 +890,16 @@ void atomisp_stop_streaming(struct vb2_queue *vq)
atomisp_css_stop(asd, false);
- atomisp_flush_video_pipe(pipe, VB2_BUF_STATE_ERROR, true);
+ atomisp_flush_video_pipe(pipe, state, true);
atomisp_subdev_cleanup_pending_events(asd);
- ret = v4l2_subdev_call(isp->inputs[asd->input_curr].csi_remote_source,
- video, s_stream, 0);
- if (ret)
- dev_warn(isp->dev, "Stopping sensor stream failed: %d\n", ret);
+ if (stop_sensor) {
+ ret = v4l2_subdev_call(isp->inputs[asd->input_curr].csi_remote_source,
+ video, s_stream, 0);
+ if (ret)
+ dev_warn(isp->dev, "Stopping sensor stream failed: %d\n", ret);
+ }
/* Disable the CSI interface on ANN B0/K0 */
if (isp->media_dev.hw_revision >= ((ATOMISP_HW_REVISION_ISP2401 <<
@@ -927,7 +926,6 @@ void atomisp_stop_streaming(struct vb2_queue *vq)
dev_warn(isp->dev, "Recreating streams failed: %d\n", ret);
media_pipeline_stop(&asd->video_out.vdev.entity.pads[0]);
- mutex_unlock(&isp->mutex);
}
int atomisp_start_streaming(struct vb2_queue *vq, unsigned int count)
@@ -1023,11 +1021,7 @@ int atomisp_start_streaming(struct vb2_queue *vq, unsigned int count)
video, s_stream, 1);
if (ret) {
dev_err(isp->dev, "Starting sensor stream failed: %d\n", ret);
- spin_lock_irqsave(&isp->lock, irqflags);
- asd->streaming = false;
- spin_unlock_irqrestore(&isp->lock, irqflags);
- ret = -EINVAL;
- goto out_unlock;
+ atomisp_stop_stream(pipe, false, VB2_BUF_STATE_QUEUED);
}
out_unlock:
@@ -1035,6 +1029,18 @@ int atomisp_start_streaming(struct vb2_queue *vq, unsigned int count)
return ret;
}
+void atomisp_stop_streaming(struct vb2_queue *vq)
+{
+ struct atomisp_video_pipe *pipe = vq_to_pipe(vq);
+ struct atomisp_device *isp = pipe->asd->isp;
+
+ dev_dbg(isp->dev, "Stop stream\n");
+
+ mutex_lock(&isp->mutex);
+ atomisp_stop_stream(pipe, true, VB2_BUF_STATE_ERROR);
+ mutex_unlock(&isp->mutex);
+}
+
/*
* To get the current value of a control.
* applications initialize the id field of a struct v4l2_control and
--
2.49.0
next prev parent reply other threads:[~2025-05-05 21:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-05 21:00 [PATCH 0/5] media: atomisp: stream start/stop error handling improvements Hans de Goede
2025-05-05 21:00 ` [PATCH 1/5] media: atomisp: Move atomisp_stop_streaming() above atomisp_start_streaming() Hans de Goede
2025-05-05 21:00 ` Hans de Goede [this message]
2025-05-05 21:00 ` [PATCH 3/5] media: atomisp: Stop pipeline on atomisp_css_start() failure Hans de Goede
2025-05-05 21:00 ` [PATCH 4/5] media: atomisp: Always free MIPI / CSI-receiver buffers from ia_css_uninit() Hans de Goede
2025-05-05 21:00 ` [PATCH 5/5] media: atomisp: Fix "stop stream timeout." error Hans de Goede
2025-05-07 6:18 ` [PATCH 0/5] media: atomisp: stream start/stop error handling improvements Andy Shevchenko
2025-07-04 9:35 ` Hans de Goede
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=20250505210008.152659-3-hdegoede@redhat.com \
--to=hdegoede@redhat.com \
--cc=andy@kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.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