media: mtk-jpegenc: Fix bug in JPEG encode quality selection
authorFei Shao <fshao@chromium.org>
Fri, 8 Sep 2023 13:28:04 +0000 (21:28 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 20 Nov 2023 10:59:32 +0000 (11:59 +0100)
commit495fd088870c9c5c20133046ff60d96f02bf70e1
tree502e610f6c0a51cd26c7eee10eeee109ea68c4c8
parent746143690eddffff10c6b4b51853eabd350e17fc
media: mtk-jpegenc: Fix bug in JPEG encode quality selection

[ Upstream commit 0aeccc63f3bc4cfd49dc4893da1409402ee6b295 ]

The driver uses the upper-bound approach to decide the target JPEG
encode quality, but there's a logic bug that if the desired quality is
higher than what the driver can support, the driver falls back to using
the worst quality.

Fix the bug by assuming using the best quality in the beginning, and
with trivial refactor to avoid long lines.

Fixes: 45f13a57d813 ("media: platform: Add jpeg enc feature")
Signed-off-by: Fei Shao <fshao@chromium.org>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c