# RPI CM5 + Picamera2: switch\_config results in Failed to queue buffer 0: Invalid argument ERROR RPISTREAM rpi\_stream.cpp:276 Failed to queue buffer for CFE Image

**URL:** <https://forums.balena.io/t/rpi-cm5-picamera2-switch-config-results-in-failed-to-queue-buffer-0-invalid-argument-error-rpistream-rpi-stream-cpp-276-failed-to-queue-buffer-for-cfe-image/377874>\
**Category:** Product support\
**Created:** [May 5, 2026, 3:07pm UTC](https://forums.balena.io/t/rpi-cm5-picamera2-switch-config-results-in-failed-to-queue-buffer-0-invalid-argument-error-rpistream-rpi-stream-cpp-276-failed-to-queue-buffer-for-cfe-image/377874 "2026-05-05T15:07:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![antoineschmider](https://avatars.discourse-cdn.com/v4/letter/a/5e9695/32.png) [@antoineschmider](https://forums.balena.io/u/antoineschmider)\
**Post date:** [May 5, 2026, 3:07pm UTC](https://forums.balena.io/t/rpi-cm5-picamera2-switch-config-results-in-failed-to-queue-buffer-0-invalid-argument-error-rpistream-rpi-stream-cpp-276-failed-to-queue-buffer-for-cfe-image/377874/1 "2026-05-05T15:07:06Z")

</div>

Hello,

I’m running balenaOS with kernel `6.12.61-v8-16k` on a Raspberry Pi 5 with an IMX477 camera. I need to switch between picamera2 configurations at runtime (to change sensor mode/resolution). On RPi OS `6.6.74+rpt-rpi-v8` this works with a ~0.3s delay. On balenaOS it requires ~8 seconds, and anything shorter produces:

`ERROR V4L2 v4l2_videodevice.cpp:1825 /dev/video12[23:cap]: Failed to queue buffer 0: Invalid argument`

After investigation, the root cause appears to be a kernel driver issue. Running `dmesg` immediately after a config switch shows:

```auto
WARNING: CPU: 2 PID: 88153 at drivers/media/v4l2-core/v4l2-subdev.c:457 call_s_stream+0xe8/0x110 [videodev]
__vb2_queue_cancel+0x38/0x2e0 [videobuf2_common]
vb2_core_streamoff+0x2c/0xe0 [videobuf2_common]

```

This indicates `vb2_queue_cancel` is calling `s_stream(0)` on the IMX477 subdev while buffers are still in flight, leaving the sensor in an unknown state and forcing a full cold I2C reinit (~8s) on every restart.

Comparing the `rp1_cfe` driver between the two systems confirms they are built from different source:

- balenaOS `6.12.61-v8-16k`: `srcversion: 585B4BF4EC144D534980F63`

- RPi OS `6.6.74+rpt-rpi-v8`: `srcversion: 0D2B276CED3198F6A45B339`

The RPi OS kernel is built from the RPi foundation’s `rpi-6.6.y` branch which contains Pi-specific fixes for `rp1_cfe` teardown that were never upstreamed to mainline. BalenaOS’s `6.12.61` appears to be built from vanilla mainline and is missing these patches.

Could balenaOS switch to building from `github.com/raspberrypi/linux` `rpi-6.12.y` branch (which the RPi foundation actively maintains with these fixes) rather than vanilla mainline `6.12.y`?

---

<div class="post-metadata">

**Author:** ![samuel-duffield1](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/samuel-duffield1/32/10378_2.png) [@samuel-duffield1](https://forums.balena.io/u/samuel-duffield1)\
**Post date:** [May 6, 2026, 8:55am UTC](https://forums.balena.io/t/rpi-cm5-picamera2-switch-config-results-in-failed-to-queue-buffer-0-invalid-argument-error-rpistream-rpi-stream-cpp-276-failed-to-queue-buffer-for-cfe-image/377874/3 "2026-05-06T08:55:28Z")

</div>

Hi @antoineschmider

Great question, and it sounds like you’ve done a thorough debug.

I’ve flagged this with the OS engineers, and we’ll get back to you!

---

<div class="post-metadata">

**Author:** ![floion](https://avatars.discourse-cdn.com/v4/letter/f/45deac/32.png) [@floion](https://forums.balena.io/u/floion)\
**Post date:** [May 6, 2026, 9:06am UTC](https://forums.balena.io/t/rpi-cm5-picamera2-switch-config-results-in-failed-to-queue-buffer-0-invalid-argument-error-rpistream-rpi-stream-cpp-276-failed-to-queue-buffer-for-cfe-image/377874/4 "2026-05-06T09:06:57Z")

</div>

Hi,

This is the process we use to update the kernel [balena-raspberrypi/layers/meta-balena-raspberrypi/recipes-kernel/linux/linux-raspberrypi\_6.12.inc at master · balena-os/balena-raspberrypi · GitHub](https://github.com/balena-os/balena-raspberrypi/blob/master/layers/meta-balena-raspberrypi/recipes-kernel/linux/linux-raspberrypi_6.12.inc#L4)

Maybe we just need to update the SRCREV from the rpi-6.12.y branch?

---

<div class="post-metadata">

**Author:** ![floion](https://avatars.discourse-cdn.com/v4/letter/f/45deac/32.png) [@floion](https://forums.balena.io/u/floion)\
**Post date:** [May 6, 2026, 10:12am UTC](https://forums.balena.io/t/rpi-cm5-picamera2-switch-config-results-in-failed-to-queue-buffer-0-invalid-argument-error-rpistream-rpi-stream-cpp-276-failed-to-queue-buffer-for-cfe-image/377874/5 "2026-05-06T10:12:42Z")

</div>

> [@antoineschmider](#):
>
> rpi-6.12.y

Can you point to the commit in the rpi-6.12.y branch that fixes the issues you mentioned?

---

<div class="post-metadata">

**Author:** ![antoineschmider](https://avatars.discourse-cdn.com/v4/letter/a/5e9695/32.png) [@antoineschmider](https://forums.balena.io/u/antoineschmider)\
**Post date:** [May 6, 2026, 11:27am UTC](https://forums.balena.io/t/rpi-cm5-picamera2-switch-config-results-in-failed-to-queue-buffer-0-invalid-argument-error-rpistream-rpi-stream-cpp-276-failed-to-queue-buffer-for-cfe-image/377874/6 "2026-05-06T11:27:55Z")

</div>

> [@floion](#):
>
> Hi,
> 
> This is the process we use to update the kernel [balena-raspberrypi/layers/meta-balena-raspberrypi/recipes-kernel/linux/linux-raspberrypi\_6.12.inc at master · balena-os/balena-raspberrypi · GitHub](https://github.com/balena-os/balena-raspberrypi/blob/master/layers/meta-balena-raspberrypi/recipes-kernel/linux/linux-raspberrypi_6.12.inc#L4)
> 
> Maybe we just need to update the SRCREV from the rpi-6.12.y branch?

Hello,

Thanks for the fast reply.

I think the fix I am looking for is in

`598462fb0279b3615c40430ce9f3616e0a9d44b8`  
`media/platform/raspberypi/rp1_cfe: Candidate fix for #5821`

AuthorDate: `Mon May 19 16:16:20 2025 +0100`  
CommitDate: `Tue Jun 3 12:34:46 2025 +0100`

The commit message says:

To avoid lost frame start in a subsequent session, avoid setting the number of lanes back to 1 or putting CSI-2 Host into reset.

That sounds very close to the issue I’m seeing when switching Picamera2 configurations at runtime: the next camera session appears to start from a bad/unknown CFE/CSI state unless I wait several seconds.

---

<div class="post-metadata">

**Author:** ![floion](https://avatars.discourse-cdn.com/v4/letter/f/45deac/32.png) [@floion](https://forums.balena.io/u/floion)\
**Post date:** [May 22, 2026, 11:19am UTC](https://forums.balena.io/t/rpi-cm5-picamera2-switch-config-results-in-failed-to-queue-buffer-0-invalid-argument-error-rpistream-rpi-stream-cpp-276-failed-to-queue-buffer-for-cfe-image/377874/7 "2026-05-22T11:19:25Z")

</div>

> [@antoineschmider](#):
>
> `598462fb0279b3615c40430ce9f3616e0a9d44b8`

Hi,

I checked on a v6.12.3+rev4 OS release for the RPi5 and I could find the commit you pointed to in the kernel tree we build for this release. Can you confirm the issue is still present on this OS version?
