venc_calc_bpframes() computes half = (gop_size - 1) >> 1, then starts b = p = half and runs for (; b <= gop_size - 1; b++, p--) { if (b % p) ... p decreases by one per iteration while b increases. For small GOP sizes p reaches 0 before the loop bound is hit, so b % p becomes b % 0 and the kernel raises a divide error. This happens for gop_size 1..6 (e.g. gop 3 with conseq_b >= 2: b=1,p=1 passes, then b=2,p=0 -> 2 % 0). Both V4L2_CID_MPEG_VIDEO_GOP_SIZE (0..65535) and V4L2_CID_MPEG_VIDEO_B_FRAMES (0..4) are user controls, so userspace can trigger it through the V4L2 control API. Stop the loop once p reaches 0; no valid B/P split can have p == 0, and the existing !found path then rejects the configuration. Fixes: 8fc58186bb41 ("media: venus: venc: set correctly GOP size and number of B-frames") Cc: stable@vger.kernel.org Reviewed-by: Bryan O'Donoghue Signed-off-by: Shirong Zhao --- drivers/media/platform/qcom/venus/venc_ctrls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/platform/qcom/venus/venc_ctrls.c b/drivers/media/platform/qcom/venus/venc_ctrls.c index 4d36c44..14ab805 100644 --- a/drivers/media/platform/qcom/venus/venc_ctrls.c +++ b/drivers/media/platform/qcom/venus/venc_ctrls.c @@ -40,7 +40,7 @@ static int venc_calc_bpframes(u32 gop_size, u32 conseq_b, u32 *bf, u32 *pf) b = p = half; - for (; b <= gop_size - 1; b++, p--) { + for (; b <= gop_size - 1 && p; b++, p--) { if (b % p) continue; -- 2.53.0