Skip to contentSkip to conversation

media: bcm2835-unicam: Fix pipeline wrong validation for unpacked formats

PATCH In review Eugen Hristev 5 participants 6 messages May 20 – Jul 16

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: bcm2835-unicam: Fix pipeline wrong validation for unpacked formats

The commit
08f9794d9b79 ("media: bcm2835-unicam: Fix RGB format / mbus code association") introduced a check to see whether the format requested is the same as the fourcc in the format list.

However, this breaks the case when userspace requested an unpacked fourcc, e.g. RG10.

Unicam can work with or without unpacking pixels, e.g. pRAA or RG10, depending on what userspace requests.
In the unpacking case, a dedicated register is being set.

If the userspace requests pRAA, this works, because the check validates the pipeline:

v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=pRAA \
--stream-mmap --stream-count=1 --stream-to=frame.raw

but, with
v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 \
--stream-mmap --stream-count=1 --stream-to=frame.raw

unicam complains at validation level:

image: format mismatch: 0x300f <=> RG10 little-endian (0x30314752)

This should work, because MEDIA_BUS_FMT_SRGGB10_1X10 can be packed into either RG10 or pRAA depending on the packing register.

To fix this, modified the condition check to also allow in the case when requested format (fmt->pixelformat) is equal to fmtinfo->unpacked_fourcc.

Fixes 08f9794d9b79 ("media: bcm2835-unicam: Fix RGB format / mbus code association")
---
 drivers/media/platform/broadcom/bcm2835-unicam.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/broadcom/bcm2835-unicam.c +2 -1
index 8d28ba0b59a3..cc7627e9a51a 100644
@@ -2158,7 +2158,8 @@ static int unicam_video_link_validate(struct media_link *link)
 		 * In order to allow the applications using the old behaviour to
 		 * run, let's accept the old combination, but warn about it.
 		 */
-		if (fmtinfo->fourcc != fmt->pixelformat) {
+		if (fmt->pixelformat != fmtinfo->fourcc &&
+		    fmt->pixelformat != fmtinfo->unpacked_fourcc) {
 			if ((fmt->pixelformat == V4L2_PIX_FMT_BGR24 &&
 			     format->code == MEDIA_BUS_FMT_BGR888_1X24) ||
 			    (fmt->pixelformat == V4L2_PIX_FMT_RGB24 &&

---
base-commit: e98d21c170b01ddef366f023bbfcf6b31509fa83
change-id: 20260520-bcmpi-2c4850314e21

Best regards,

Signature · 1 line
Eugen Hristev <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw

Hi Eugen

Thanks for the patch.

Quoted 27 lines · Eugen Hristev' via kernel-list

The commit
08f9794d9b79 ("media: bcm2835-unicam: Fix RGB format / mbus code association") introduced a check to see whether the format requested is the same as the fourcc in the format list.

However, this breaks the case when userspace requested an unpacked fourcc, e.g. RG10.

Unicam can work with or without unpacking pixels, e.g. pRAA or RG10, depending on what userspace requests.
In the unpacking case, a dedicated register is being set.

If the userspace requests pRAA, this works, because the check validates the pipeline:

v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=pRAA \
--stream-mmap --stream-count=1 --stream-to=frame.raw

but, with
v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 \
--stream-mmap --stream-count=1 --stream-to=frame.raw

unicam complains at validation level:

image: format mismatch: 0x300f <=> RG10 little-endian (0x30314752)

Quoted 8 lines

This should work, because MEDIA_BUS_FMT_SRGGB10_1X10 can be packed into either RG10 or pRAA depending on the packing register.

To fix this, modified the condition check to also allow in the case when requested format (fmt->pixelformat) is equal to fmtinfo->unpacked_fourcc.

Fixes 08f9794d9b79 ("media: bcm2835-unicam: Fix RGB format / mbus code association")
Quoted 27 lines
---
 drivers/media/platform/broadcom/bcm2835-unicam.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/broadcom/bcm2835-unicam.c +2 -2
index 8d28ba0b59a3..cc7627e9a51a 100644
@@ -2158,7 +2158,8 @@ static int unicam_video_link_validate(struct media_link *link)
                 * In order to allow the applications using the old behaviour to
                 * run, let's accept the old combination, but warn about it.
                 */
-               if (fmtinfo->fourcc != fmt->pixelformat) {
+               if (fmt->pixelformat != fmtinfo->fourcc &&
+                   fmt->pixelformat != fmtinfo->unpacked_fourcc) {
                        if ((fmt->pixelformat == V4L2_PIX_FMT_BGR24 &&
                             format->code == MEDIA_BUS_FMT_BGR888_1X24) ||
                            (fmt->pixelformat == V4L2_PIX_FMT_RGB24 &&
 
---

base-commit: e98d21c170b01ddef366f023bbfcf6b31509fa83
change-id: 20260520-bcmpi-2c4850314e21

Best regards,
--
Eugen Hristev <[email protected]>

Reviewed-by on v1 1/1
#2 lore raw
In reply to Eugen Hristev

Hi Eugen,

Quoting Eugen Hristev (2026-05-20 21:07:00)

Quoted 44 lines

The commit
08f9794d9b79 ("media: bcm2835-unicam: Fix RGB format / mbus code association") introduced a check to see whether the format requested is the same as the fourcc in the format list.

However, this breaks the case when userspace requested an unpacked fourcc, e.g. RG10.

Unicam can work with or without unpacking pixels, e.g. pRAA or RG10, depending on what userspace requests.
In the unpacking case, a dedicated register is being set.

If the userspace requests pRAA, this works, because the check validates the pipeline:

v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=pRAA \
--stream-mmap --stream-count=1 --stream-to=frame.raw

but, with
v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 \
--stream-mmap --stream-count=1 --stream-to=frame.raw

unicam complains at validation level:

image: format mismatch: 0x300f <=> RG10 little-endian (0x30314752)

This should work, because MEDIA_BUS_FMT_SRGGB10_1X10 can be packed into either RG10 or pRAA depending on the packing register.

To fix this, modified the condition check to also allow in the case when requested format (fmt->pixelformat) is equal to fmtinfo->unpacked_fourcc.

Fixes 08f9794d9b79 ("media: bcm2835-unicam: Fix RGB format / mbus code association")
---
 drivers/media/platform/broadcom/bcm2835-unicam.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/broadcom/bcm2835-unicam.c +0 -0
index 8d28ba0b59a3..cc7627e9a51a 100644

drivers/media/platform/broadcom/bcm2835-unicam.c static int unicam_video_link_validate(struct media_link *link) · line 2165

Quoted 9 lines
drivers/media/platform/broadcom/bcm2835-unicam.c +2 -1
@@ -2158,7 +2158,8 @@ static int unicam_video_link_validate(struct media_link *link)
                 * In order to allow the applications using the old behaviour to
                 * run, let's accept the old combination, but warn about it.
                 */
-               if (fmtinfo->fourcc != fmt->pixelformat) {
+               if (fmt->pixelformat != fmtinfo->fourcc &&
+                   fmt->pixelformat != fmtinfo->unpacked_fourcc) {
                        if ((fmt->pixelformat == V4L2_PIX_FMT_BGR24 &&
                             format->code == MEDIA_BUS_FMT_BGR888_1X24) ||
                            (fmt->pixelformat == V4L2_PIX_FMT_RGB24 &&

Thanks,
Jai

Quoted 9 lines

---
base-commit: e98d21c170b01ddef366f023bbfcf6b31509fa83
change-id: 20260520-bcmpi-2c4850314e21

Best regards,

Signature · 1 line
Eugen Hristev <[email protected]>
#3 lore raw
Quoted 50 lines · Jai Luthra

Hi Eugen,

Quoting Eugen Hristev (2026-05-20 21:07:00)

Quoted 47 lines

The commit
08f9794d9b79 ("media: bcm2835-unicam: Fix RGB format / mbus code association") introduced a check to see whether the format requested is the same as the fourcc in the format list.

However, this breaks the case when userspace requested an unpacked fourcc, e.g. RG10.

Unicam can work with or without unpacking pixels, e.g. pRAA or RG10, depending on what userspace requests.
In the unpacking case, a dedicated register is being set.

If the userspace requests pRAA, this works, because the check validates the pipeline:

v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=pRAA \
--stream-mmap --stream-count=1 --stream-to=frame.raw

but, with
v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 \
--stream-mmap --stream-count=1 --stream-to=frame.raw

unicam complains at validation level:

image: format mismatch: 0x300f <=> RG10 little-endian (0x30314752)

This should work, because MEDIA_BUS_FMT_SRGGB10_1X10 can be packed into either RG10 or pRAA depending on the packing register.

To fix this, modified the condition check to also allow in the case when requested format (fmt->pixelformat) is equal to fmtinfo->unpacked_fourcc.

Fixes 08f9794d9b79 ("media: bcm2835-unicam: Fix RGB format / mbus code association")
---
 drivers/media/platform/broadcom/bcm2835-unicam.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/broadcom/bcm2835-unicam.c +0 -1
index 8d28ba0b59a3..cc7627e9a51a 100644
@@ -2158,7 +2158,8 @@ static int unicam_video_link_validate(struct media_link *link)
                 * In order to allow the applications using the old behaviour to
                 * run, let's accept the old combination, but warn about it.
                 */
-               if (fmtinfo->fourcc != fmt->pixelformat) {
Quoted 9 lines

drivers/media/platform/broadcom/bcm2835-unicam.c static int unicam_video_link_validate(struct media_link *link) · line 2165

Quoted 6 lines
drivers/media/platform/broadcom/bcm2835-unicam.c +2 -0
+               if (fmt->pixelformat != fmtinfo->fourcc &&
+                   fmt->pixelformat != fmtinfo->unpacked_fourcc) {
                        if ((fmt->pixelformat == V4L2_PIX_FMT_BGR24 &&
                             format->code == MEDIA_BUS_FMT_BGR888_1X24) ||
                            (fmt->pixelformat == V4L2_PIX_FMT_RGB24 &&

Hi Sakari,

I saw you taking some of the patches on unicam, this one is the most important as all unpacked formats are basically broken for a very long time (months) and the patch is pending for quite some time.

This should also go in stable as some older versions also affected.

Thanks,
Eugen

Quoted 12 lines

Thanks,
Jai

Quoted 9 lines

---
base-commit: e98d21c170b01ddef366f023bbfcf6b31509fa83
change-id: 20260520-bcmpi-2c4850314e21

Best regards,

Signature · 1 line
Eugen Hristev <[email protected]>
#4 lore raw
Quoted 59 lines · Eugen Hristev
Quoted 48 lines · Jai Luthra

Quoting Eugen Hristev (2026-05-20 21:07:00)

Quoted 47 lines

The commit
08f9794d9b79 ("media: bcm2835-unicam: Fix RGB format / mbus code association") introduced a check to see whether the format requested is the same as the fourcc in the format list.

However, this breaks the case when userspace requested an unpacked fourcc, e.g. RG10.

Unicam can work with or without unpacking pixels, e.g. pRAA or RG10, depending on what userspace requests.
In the unpacking case, a dedicated register is being set.

If the userspace requests pRAA, this works, because the check validates the pipeline:

v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=pRAA \
--stream-mmap --stream-count=1 --stream-to=frame.raw

but, with
v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 \
--stream-mmap --stream-count=1 --stream-to=frame.raw

unicam complains at validation level:

image: format mismatch: 0x300f <=> RG10 little-endian (0x30314752)

This should work, because MEDIA_BUS_FMT_SRGGB10_1X10 can be packed into either RG10 or pRAA depending on the packing register.

To fix this, modified the condition check to also allow in the case when requested format (fmt->pixelformat) is equal to fmtinfo->unpacked_fourcc.

Fixes 08f9794d9b79 ("media: bcm2835-unicam: Fix RGB format / mbus code association")
---
 drivers/media/platform/broadcom/bcm2835-unicam.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/broadcom/bcm2835-unicam.c +0 -1
index 8d28ba0b59a3..cc7627e9a51a 100644
@@ -2158,7 +2158,8 @@ static int unicam_video_link_validate(struct media_link *link)
                 * In order to allow the applications using the old behaviour to
                 * run, let's accept the old combination, but warn about it.
                 */
-               if (fmtinfo->fourcc != fmt->pixelformat) {
Quoted 9 lines

drivers/media/platform/broadcom/bcm2835-unicam.c static int unicam_video_link_validate(struct media_link *link) · line 2165

Quoted 6 lines
drivers/media/platform/broadcom/bcm2835-unicam.c +2 -0
+               if (fmt->pixelformat != fmtinfo->fourcc &&
+                   fmt->pixelformat != fmtinfo->unpacked_fourcc) {
                        if ((fmt->pixelformat == V4L2_PIX_FMT_BGR24 &&
                             format->code == MEDIA_BUS_FMT_BGR888_1X24) ||
                            (fmt->pixelformat == V4L2_PIX_FMT_RGB24 &&
Quoted 7 lines

Hi Sakari,

I saw you taking some of the patches on unicam, this one is the most important as all unpacked formats are basically broken for a very long time (months) and the patch is pending for quite some time.

This should also go in stable as some older versions also affected.

The commit message should include

after the Fixes: tag. Sakari can likely add that when applying.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

---
base-commit: e98d21c170b01ddef366f023bbfcf6b31509fa83
change-id: 20260520-bcmpi-2c4850314e21

Signature · 3 lines
Regards,

Laurent Pinchart
#5 lore raw
Quoted 66 lines · Laurent Pinchart
Quoted 65 lines · Eugen Hristev
Quoted 48 lines · Jai Luthra

Quoting Eugen Hristev (2026-05-20 21:07:00)

Quoted 47 lines

The commit
08f9794d9b79 ("media: bcm2835-unicam: Fix RGB format / mbus code association") introduced a check to see whether the format requested is the same as the fourcc in the format list.

However, this breaks the case when userspace requested an unpacked fourcc, e.g. RG10.

Unicam can work with or without unpacking pixels, e.g. pRAA or RG10, depending on what userspace requests.
In the unpacking case, a dedicated register is being set.

If the userspace requests pRAA, this works, because the check validates the pipeline:

v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=pRAA \
--stream-mmap --stream-count=1 --stream-to=frame.raw

but, with
v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 \
--stream-mmap --stream-count=1 --stream-to=frame.raw

unicam complains at validation level:

image: format mismatch: 0x300f <=> RG10 little-endian (0x30314752)

This should work, because MEDIA_BUS_FMT_SRGGB10_1X10 can be packed into either RG10 or pRAA depending on the packing register.

To fix this, modified the condition check to also allow in the case when requested format (fmt->pixelformat) is equal to fmtinfo->unpacked_fourcc.

Fixes 08f9794d9b79 ("media: bcm2835-unicam: Fix RGB format / mbus code association")
---
 drivers/media/platform/broadcom/bcm2835-unicam.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/broadcom/bcm2835-unicam.c +0 -1
index 8d28ba0b59a3..cc7627e9a51a 100644
@@ -2158,7 +2158,8 @@ static int unicam_video_link_validate(struct media_link *link)
                 * In order to allow the applications using the old behaviour to
                 * run, let's accept the old combination, but warn about it.
                 */
-               if (fmtinfo->fourcc != fmt->pixelformat) {
Quoted 9 lines

drivers/media/platform/broadcom/bcm2835-unicam.c static int unicam_video_link_validate(struct media_link *link) · line 2165

Quoted 6 lines
drivers/media/platform/broadcom/bcm2835-unicam.c +2 -0
+               if (fmt->pixelformat != fmtinfo->fourcc &&
+                   fmt->pixelformat != fmtinfo->unpacked_fourcc) {
                        if ((fmt->pixelformat == V4L2_PIX_FMT_BGR24 &&
                             format->code == MEDIA_BUS_FMT_BGR888_1X24) ||
                            (fmt->pixelformat == V4L2_PIX_FMT_RGB24 &&

Hi Sakari,

I saw you taking some of the patches on unicam, this one is the most important as all unpacked formats are basically broken for a very long time (months) and the patch is pending for quite some time.

Quoted 7 lines
Quoted 1 line

This should also go in stable as some older versions also affected.

The commit message should include

after the Fixes: tag. Sakari can likely add that when applying.

Yes. I expect to pick the patch later this week.

Signature · 1 line
Sakari Ailus