[PATCH 2/3] staging: media: cedrus: factor out the format check

From: Jernej Skrabec

Date: Fri Nov 27 2026 - 01:55:39 EST


cedrus_find_format() and cedrus_enum_fmt() check the capabilities and
the direction of a format in the same way. Move the check into a
helper, so that the VP9 decoder, added later, can exclude formats in
one place.

No functional change.

Signed-off-by: Jernej Skrabec <jernej.skrabec@xxxxxxxxx>
---
.../staging/media/sunxi/cedrus/cedrus_video.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
index 2521315abdb7..a46820a90d87 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
@@ -78,6 +78,17 @@ static struct cedrus_format cedrus_formats[] = {

#define CEDRUS_FORMATS_COUNT ARRAY_SIZE(cedrus_formats)

+static bool cedrus_check_format(struct cedrus_ctx *ctx,
+ const struct cedrus_format *fmt,
+ u32 directions)
+{
+ if (!cedrus_is_capable(ctx, fmt->capabilities) ||
+ !(fmt->directions & directions))
+ return false;
+
+ return true;
+}
+
static struct cedrus_format *cedrus_find_format(struct cedrus_ctx *ctx,
u32 pixelformat, u32 directions)
{
@@ -88,8 +99,7 @@ static struct cedrus_format *cedrus_find_format(struct cedrus_ctx *ctx,
for (i = 0; i < CEDRUS_FORMATS_COUNT; i++) {
fmt = &cedrus_formats[i];

- if (!cedrus_is_capable(ctx, fmt->capabilities) ||
- !(fmt->directions & directions))
+ if (!cedrus_check_format(ctx, fmt, directions))
continue;

if (fmt->pixelformat == pixelformat)
@@ -191,10 +201,7 @@ static int cedrus_enum_fmt(struct file *file, struct v4l2_fmtdesc *f,
index = 0;

for (i = 0; i < CEDRUS_FORMATS_COUNT; i++) {
- if (!cedrus_is_capable(ctx, cedrus_formats[i].capabilities))
- continue;
-
- if (!(cedrus_formats[i].directions & direction))
+ if (!cedrus_check_format(ctx, &cedrus_formats[i], direction))
continue;

if (index == f->index)
--
2.43.0