Skip to content

Commit

Permalink
media: venus: helpers: Fix ALIGN() of non power of two
Browse files Browse the repository at this point in the history
ALIGN() expects its second argument to be a power of 2, otherwise
incorrect results are produced for some inputs. The output can be
both larger or smaller than what is expected.

For example, ALIGN(304, 192) equals 320 instead of 384, and
ALIGN(65, 192) equals 256 instead of 192.

However, nestling two ALIGN() as is done in this case seem to only
produce results equal to or bigger than the expected result if ALIGN()
had handled non powers of two, and that in turn results in framesizes
that are either the correct size or too large.

Fortunately, since 192 * 4 / 3 equals 256, it turns out that one ALIGN()
is sufficient.

Fixes: ab1eda4 ("media: venus: vdec: handle 10bit bitstreams")
Signed-off-by: Rikard Falkeborn <[email protected]>
Signed-off-by: Stanimir Varbanov <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
rikardfalkeborn authored and mchehab committed Jun 9, 2023
1 parent 751be5c commit 927e78a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/media/platform/qcom/venus/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,8 @@ static u32 get_framesize_raw_yuv420_tp10_ubwc(u32 width, u32 height)
u32 extradata = SZ_16K;
u32 size;

y_stride = ALIGN(ALIGN(width, 192) * 4 / 3, 256);
uv_stride = ALIGN(ALIGN(width, 192) * 4 / 3, 256);
y_stride = ALIGN(width * 4 / 3, 256);
uv_stride = ALIGN(width * 4 / 3, 256);
y_sclines = ALIGN(height, 16);
uv_sclines = ALIGN((height + 1) >> 1, 16);

Expand Down

0 comments on commit 927e78a

Please sign in to comment.