Commit d61b3b41 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

media: vicodec: check for valid format in v4l2_fwht_en/decode

These functions did not return an error if state->info was NULL
or an unsupported pixelformat was selected (should not happen,
but just to be on the safe side).
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent 0113c50f
...@@ -51,8 +51,7 @@ const struct v4l2_fwht_pixfmt_info *v4l2_fwht_get_pixfmt(u32 idx) ...@@ -51,8 +51,7 @@ const struct v4l2_fwht_pixfmt_info *v4l2_fwht_get_pixfmt(u32 idx)
return v4l2_fwht_pixfmts + idx; return v4l2_fwht_pixfmts + idx;
} }
unsigned int v4l2_fwht_encode(struct v4l2_fwht_state *state, int v4l2_fwht_encode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out)
u8 *p_in, u8 *p_out)
{ {
unsigned int size = state->width * state->height; unsigned int size = state->width * state->height;
const struct v4l2_fwht_pixfmt_info *info = state->info; const struct v4l2_fwht_pixfmt_info *info = state->info;
...@@ -62,6 +61,8 @@ unsigned int v4l2_fwht_encode(struct v4l2_fwht_state *state, ...@@ -62,6 +61,8 @@ unsigned int v4l2_fwht_encode(struct v4l2_fwht_state *state,
u32 encoding; u32 encoding;
u32 flags = 0; u32 flags = 0;
if (!info)
return -EINVAL;
rf.width = state->width; rf.width = state->width;
rf.height = state->height; rf.height = state->height;
rf.luma = p_in; rf.luma = p_in;
...@@ -137,6 +138,8 @@ unsigned int v4l2_fwht_encode(struct v4l2_fwht_state *state, ...@@ -137,6 +138,8 @@ unsigned int v4l2_fwht_encode(struct v4l2_fwht_state *state,
rf.cr = rf.cb + 2; rf.cr = rf.cb + 2;
rf.luma++; rf.luma++;
break; break;
default:
return -EINVAL;
} }
cf.width = state->width; cf.width = state->width;
...@@ -180,8 +183,7 @@ unsigned int v4l2_fwht_encode(struct v4l2_fwht_state *state, ...@@ -180,8 +183,7 @@ unsigned int v4l2_fwht_encode(struct v4l2_fwht_state *state,
return cf.size + sizeof(*p_hdr); return cf.size + sizeof(*p_hdr);
} }
int v4l2_fwht_decode(struct v4l2_fwht_state *state, int v4l2_fwht_decode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out)
u8 *p_in, u8 *p_out)
{ {
unsigned int size = state->width * state->height; unsigned int size = state->width * state->height;
unsigned int chroma_size = size; unsigned int chroma_size = size;
...@@ -191,6 +193,9 @@ int v4l2_fwht_decode(struct v4l2_fwht_state *state, ...@@ -191,6 +193,9 @@ int v4l2_fwht_decode(struct v4l2_fwht_state *state,
struct fwht_cframe cf; struct fwht_cframe cf;
u8 *p; u8 *p;
if (!state->info)
return -EINVAL;
p_hdr = (struct fwht_cframe_hdr *)p_in; p_hdr = (struct fwht_cframe_hdr *)p_in;
cf.width = ntohl(p_hdr->width); cf.width = ntohl(p_hdr->width);
cf.height = ntohl(p_hdr->height); cf.height = ntohl(p_hdr->height);
...@@ -320,6 +325,8 @@ int v4l2_fwht_decode(struct v4l2_fwht_state *state, ...@@ -320,6 +325,8 @@ int v4l2_fwht_decode(struct v4l2_fwht_state *state,
*p++ = 0; *p++ = 0;
} }
break; break;
default:
return -EINVAL;
} }
return 0; return 0;
} }
...@@ -41,10 +41,7 @@ struct v4l2_fwht_state { ...@@ -41,10 +41,7 @@ struct v4l2_fwht_state {
const struct v4l2_fwht_pixfmt_info *v4l2_fwht_find_pixfmt(u32 pixelformat); const struct v4l2_fwht_pixfmt_info *v4l2_fwht_find_pixfmt(u32 pixelformat);
const struct v4l2_fwht_pixfmt_info *v4l2_fwht_get_pixfmt(u32 idx); const struct v4l2_fwht_pixfmt_info *v4l2_fwht_get_pixfmt(u32 idx);
unsigned int v4l2_fwht_encode(struct v4l2_fwht_state *state, int v4l2_fwht_encode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out);
u8 *p_in, u8 *p_out); int v4l2_fwht_decode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out);
int v4l2_fwht_decode(struct v4l2_fwht_state *state,
u8 *p_in, u8 *p_out);
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment