* [PATCH v4 0/6] media: Fix coccinelle warning/errors
@ 2025-01-06 13:40 Ricardo Ribalda
2025-01-06 13:40 ` [PATCH v4 1/6] media: dvb-frontends: tda10048: Make the range of z explicit Ricardo Ribalda
` (5 more replies)
0 siblings, 6 replies; 11+ messages in thread
From: Ricardo Ribalda @ 2025-01-06 13:40 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Stanimir Varbanov, Vikash Garodia,
Bryan O'Donoghue, Hans Verkuil, Hans Verkuil
Cc: linux-media, linux-kernel, Stanimir Varbanov, linux-arm-msm,
Ricardo Ribalda
These is the last set of patches to fix all the relevant patchwork
warnings (TM).
To: Stanimir Varbanov <stanimir.k.varbanov@gmail.com>
To: Vikash Garodia <quic_vgarodia@quicinc.com>
To: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
To: Mauro Carvalho Chehab <mchehab@kernel.org>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org
Cc: linux-arm-msm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Changes in v4:
- Remove all merged patches
- Improve commit messages.
- media: Remove timeperframe from inst
- Ignore 0 fps (Thanks Hans)
- Link to v3: https://lore.kernel.org/r/20240429-fix-cocci-v3-0-3c4865f5a4b0@chromium.org
Changes in v3: Thanks Bryan, Dan, Markus, Sakary and Hans
- Improve commit messages.
- Use div64_u64 when possible
- Link to v2: https://lore.kernel.org/r/20240419-fix-cocci-v2-0-2119e692309c@chromium.org
Changes in v2:
- Remove all the min() retval, and send a patch for cocci: https://lore.kernel.org/lkml/20240415-minimax-v1-1-5feb20d66a79@chromium.org/T/#u
- platform_get_irq() cannot return 0, fix that (Thanks Dan).
- Fix stb0800 patch. chip_id can be 0 (Thanks Dan).
- Use runtime (IS_ENABLED), code looks nicer. (Thanks Dan).
- Do not replace do_div for venus (Thanks Dan).
- Do not replace do_div for tda10048 (Thanks Dan).
- Link to v1: https://lore.kernel.org/r/20240415-fix-cocci-v1-0-477afb23728b@chromium.org
---
Ricardo Ribalda (6):
media: dvb-frontends: tda10048: Make the range of z explicit.
media: venus: vdec: Ignore parm smaller than 1fps
media: venus: venc: Ignore parm smaller than 1fps
media: venus: Remove timeperframe from inst
media: venus: venc: Make the range of us_per_frame explicit
media: venus: vdec: Make the range of us_per_frame explicit
drivers/media/dvb-frontends/tda10048.c | 4 +++-
drivers/media/platform/qcom/venus/core.h | 2 --
drivers/media/platform/qcom/venus/vdec.c | 24 +++++++++++-------------
drivers/media/platform/qcom/venus/venc.c | 25 +++++++++++--------------
4 files changed, 25 insertions(+), 30 deletions(-)
---
base-commit: ab2fd4a0ca26f3b4a7764f51ed3326ab89ab3213
change-id: 20240415-fix-cocci-2df3ef22a6f7
Best regards,
--
Ricardo Ribalda <ribalda@chromium.org>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v4 1/6] media: dvb-frontends: tda10048: Make the range of z explicit.
2025-01-06 13:40 [PATCH v4 0/6] media: Fix coccinelle warning/errors Ricardo Ribalda
@ 2025-01-06 13:40 ` Ricardo Ribalda
2025-01-06 13:40 ` [PATCH v4 2/6] media: venus: vdec: Ignore parm smaller than 1fps Ricardo Ribalda
` (4 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Ricardo Ribalda @ 2025-01-06 13:40 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Stanimir Varbanov, Vikash Garodia,
Bryan O'Donoghue, Hans Verkuil, Hans Verkuil
Cc: linux-media, linux-kernel, Stanimir Varbanov, linux-arm-msm,
Ricardo Ribalda
We have not been able to find the relevant datahsheet, but it seems rare
that the device will have a sampling frequency over 613MHz.
Nonetheless, this patch does not introduce any change in behaviour, it
just adds a comment to make explicit the current limit: div by 32 bits.
Found by cocci:
drivers/media/dvb-frontends/tda10048.c:345:1-7: WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead.
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/dvb-frontends/tda10048.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/media/dvb-frontends/tda10048.c b/drivers/media/dvb-frontends/tda10048.c
index 3e725cdcc66b..1886f733dbbf 100644
--- a/drivers/media/dvb-frontends/tda10048.c
+++ b/drivers/media/dvb-frontends/tda10048.c
@@ -328,7 +328,8 @@ static int tda10048_set_wref(struct dvb_frontend *fe, u32 sample_freq_hz,
u32 bw)
{
struct tda10048_state *state = fe->demodulator_priv;
- u64 t, z;
+ u32 z;
+ u64 t;
dprintk(1, "%s()\n", __func__);
@@ -341,6 +342,7 @@ static int tda10048_set_wref(struct dvb_frontend *fe, u32 sample_freq_hz,
/* t *= 2147483648 on 32bit platforms */
t *= (2048 * 1024);
t *= 1024;
+ /* Sample frequency is under 613MHz */
z = 7 * sample_freq_hz;
do_div(t, z);
t += 5;
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v4 2/6] media: venus: vdec: Ignore parm smaller than 1fps
2025-01-06 13:40 [PATCH v4 0/6] media: Fix coccinelle warning/errors Ricardo Ribalda
2025-01-06 13:40 ` [PATCH v4 1/6] media: dvb-frontends: tda10048: Make the range of z explicit Ricardo Ribalda
@ 2025-01-06 13:40 ` Ricardo Ribalda
2025-01-06 14:08 ` Bryan O'Donoghue
2025-01-06 13:40 ` [PATCH v4 3/6] media: venus: venc: " Ricardo Ribalda
` (3 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Ricardo Ribalda @ 2025-01-06 13:40 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Stanimir Varbanov, Vikash Garodia,
Bryan O'Donoghue, Hans Verkuil, Hans Verkuil
Cc: linux-media, linux-kernel, Stanimir Varbanov, linux-arm-msm,
Ricardo Ribalda
The driver uses "whole" fps in all its calculations (e.g. in
load_per_instance()) Return -EINVAL if the user provides a parm that
will result in 0 whole fps.
Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
Closes: https://lore.kernel.org/linux-media/f11653a7-bc49-48cd-9cdb-1659147453e4@xs4all.nl/T/#m91cd962ac942834654f94c92206e2f85ff7d97f0
Fixes: 7472c1c69138 ("[media] media: venus: vdec: add video decoder files")
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/platform/qcom/venus/vdec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
index 98c22b9f9372..25edd77b9cf9 100644
--- a/drivers/media/platform/qcom/venus/vdec.c
+++ b/drivers/media/platform/qcom/venus/vdec.c
@@ -481,7 +481,7 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
us_per_frame = timeperframe->numerator * (u64)USEC_PER_SEC;
do_div(us_per_frame, timeperframe->denominator);
- if (!us_per_frame)
+ if (!us_per_frame || us_per_frame > USEC_PER_SEC)
return -EINVAL;
fps = (u64)USEC_PER_SEC;
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v4 3/6] media: venus: venc: Ignore parm smaller than 1fps
2025-01-06 13:40 [PATCH v4 0/6] media: Fix coccinelle warning/errors Ricardo Ribalda
2025-01-06 13:40 ` [PATCH v4 1/6] media: dvb-frontends: tda10048: Make the range of z explicit Ricardo Ribalda
2025-01-06 13:40 ` [PATCH v4 2/6] media: venus: vdec: Ignore parm smaller than 1fps Ricardo Ribalda
@ 2025-01-06 13:40 ` Ricardo Ribalda
2025-01-06 14:08 ` Bryan O'Donoghue
2025-01-06 13:40 ` [PATCH v4 4/6] media: venus: Remove timeperframe from inst Ricardo Ribalda
` (2 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Ricardo Ribalda @ 2025-01-06 13:40 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Stanimir Varbanov, Vikash Garodia,
Bryan O'Donoghue, Hans Verkuil, Hans Verkuil
Cc: linux-media, linux-kernel, Stanimir Varbanov, linux-arm-msm,
Ricardo Ribalda
The driver uses "whole" fps in all its calculations (e.g. in
load_per_instance()). Return -EINVAL if the user provides a parm that
will result in 0 whole fps.
Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
Closes: https://lore.kernel.org/linux-media/f11653a7-bc49-48cd-9cdb-1659147453e4@xs4all.nl/T/#m91cd962ac942834654f94c92206e2f85ff7d97f0
Fixes: aaaa93eda64b ("[media] media: venus: venc: add video encoder files")
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/platform/qcom/venus/venc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c
index c1c543535aaf..bd967d60c883 100644
--- a/drivers/media/platform/qcom/venus/venc.c
+++ b/drivers/media/platform/qcom/venus/venc.c
@@ -411,7 +411,7 @@ static int venc_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
us_per_frame = timeperframe->numerator * (u64)USEC_PER_SEC;
do_div(us_per_frame, timeperframe->denominator);
- if (!us_per_frame)
+ if (!us_per_frame || us_per_frame > USEC_PER_SEC)
return -EINVAL;
fps = (u64)USEC_PER_SEC;
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v4 4/6] media: venus: Remove timeperframe from inst
2025-01-06 13:40 [PATCH v4 0/6] media: Fix coccinelle warning/errors Ricardo Ribalda
` (2 preceding siblings ...)
2025-01-06 13:40 ` [PATCH v4 3/6] media: venus: venc: " Ricardo Ribalda
@ 2025-01-06 13:40 ` Ricardo Ribalda
2025-01-06 13:40 ` [PATCH v4 5/6] media: venus: venc: Make the range of us_per_frame explicit Ricardo Ribalda
2025-01-06 13:40 ` [PATCH v4 6/6] media: venus: vdec: " Ricardo Ribalda
5 siblings, 0 replies; 11+ messages in thread
From: Ricardo Ribalda @ 2025-01-06 13:40 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Stanimir Varbanov, Vikash Garodia,
Bryan O'Donoghue, Hans Verkuil, Hans Verkuil
Cc: linux-media, linux-kernel, Stanimir Varbanov, linux-arm-msm,
Ricardo Ribalda
The driver only cares about whole fps. We can infer the timeperframe
from the fps field. Remove the redundant field.
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/platform/qcom/venus/core.h | 2 --
drivers/media/platform/qcom/venus/vdec.c | 15 ++++++++-------
drivers/media/platform/qcom/venus/venc.c | 17 +++++++++--------
3 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h
index 44f1c3bc4186..988198280687 100644
--- a/drivers/media/platform/qcom/venus/core.h
+++ b/drivers/media/platform/qcom/venus/core.h
@@ -405,7 +405,6 @@ enum venus_inst_modes {
* @tss: timestamp metadata
* @payloads: cache plane payload to use it for clock/BW scaling
* @fps: holds current FPS
- * @timeperframe: holds current time per frame structure
* @fmt_out: a reference to output format structure
* @fmt_cap: a reference to capture format structure
* @num_input_bufs: holds number of input buffers
@@ -476,7 +475,6 @@ struct venus_inst {
struct venus_ts_metadata tss[VIDEO_MAX_FRAME];
unsigned long payloads[VIDEO_MAX_FRAME];
u64 fps;
- struct v4l2_fract timeperframe;
const struct venus_format *fmt_out;
const struct venus_format *fmt_cap;
unsigned int num_input_bufs;
diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
index 25edd77b9cf9..6b8906ced6bc 100644
--- a/drivers/media/platform/qcom/venus/vdec.c
+++ b/drivers/media/platform/qcom/venus/vdec.c
@@ -471,10 +471,12 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
return -EINVAL;
memset(cap->reserved, 0, sizeof(cap->reserved));
- if (!timeperframe->denominator)
- timeperframe->denominator = inst->timeperframe.denominator;
- if (!timeperframe->numerator)
- timeperframe->numerator = inst->timeperframe.numerator;
+
+ if (!timeperframe->numerator || !timeperframe->denominator) {
+ timeperframe->numerator = 1;
+ timeperframe->denominator = inst->fps;
+ }
+
cap->readbuffers = 0;
cap->extendedmode = 0;
cap->capability = V4L2_CAP_TIMEPERFRAME;
@@ -488,7 +490,8 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
do_div(fps, us_per_frame);
inst->fps = fps;
- inst->timeperframe = *timeperframe;
+ timeperframe->numerator = 1;
+ timeperframe->denominator = inst->fps;
return 0;
}
@@ -1613,8 +1616,6 @@ static void vdec_inst_init(struct venus_inst *inst)
inst->out_width = frame_width_min(inst);
inst->out_height = frame_height_min(inst);
inst->fps = 30;
- inst->timeperframe.numerator = 1;
- inst->timeperframe.denominator = 30;
inst->opb_buftype = HFI_BUFFER_OUTPUT;
}
diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c
index bd967d60c883..8355bd59a5c2 100644
--- a/drivers/media/platform/qcom/venus/venc.c
+++ b/drivers/media/platform/qcom/venus/venc.c
@@ -401,10 +401,10 @@ static int venc_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
memset(out->reserved, 0, sizeof(out->reserved));
- if (!timeperframe->denominator)
- timeperframe->denominator = inst->timeperframe.denominator;
- if (!timeperframe->numerator)
- timeperframe->numerator = inst->timeperframe.numerator;
+ if (!timeperframe->numerator || !timeperframe->denominator) {
+ timeperframe->numerator = 1;
+ timeperframe->denominator = inst->fps;
+ }
out->capability = V4L2_CAP_TIMEPERFRAME;
@@ -417,8 +417,10 @@ static int venc_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
fps = (u64)USEC_PER_SEC;
do_div(fps, us_per_frame);
- inst->timeperframe = *timeperframe;
inst->fps = fps;
+ timeperframe->numerator = 1;
+ timeperframe->denominator = inst->fps;
+
return 0;
}
@@ -432,7 +434,8 @@ static int venc_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
return -EINVAL;
a->parm.output.capability |= V4L2_CAP_TIMEPERFRAME;
- a->parm.output.timeperframe = inst->timeperframe;
+ a->parm.output.timeperframe.numerator = 1;
+ a->parm.output.timeperframe.denominator = inst->fps;
return 0;
}
@@ -1455,8 +1458,6 @@ static void venc_inst_init(struct venus_inst *inst)
inst->out_width = 1280;
inst->out_height = 720;
inst->fps = 15;
- inst->timeperframe.numerator = 1;
- inst->timeperframe.denominator = 15;
inst->hfi_codec = HFI_VIDEO_CODEC_H264;
}
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v4 5/6] media: venus: venc: Make the range of us_per_frame explicit
2025-01-06 13:40 [PATCH v4 0/6] media: Fix coccinelle warning/errors Ricardo Ribalda
` (3 preceding siblings ...)
2025-01-06 13:40 ` [PATCH v4 4/6] media: venus: Remove timeperframe from inst Ricardo Ribalda
@ 2025-01-06 13:40 ` Ricardo Ribalda
2025-01-06 13:40 ` [PATCH v4 6/6] media: venus: vdec: " Ricardo Ribalda
5 siblings, 0 replies; 11+ messages in thread
From: Ricardo Ribalda @ 2025-01-06 13:40 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Stanimir Varbanov, Vikash Garodia,
Bryan O'Donoghue, Hans Verkuil, Hans Verkuil
Cc: linux-media, linux-kernel, Stanimir Varbanov, linux-arm-msm,
Ricardo Ribalda
Fps bigger than 0.000232829 fps, this fits in a 32 bit us_per_frame.
There is no need to do a 64 bit division here.
Also, the driver only works with whole fps.
Found with cocci:
drivers/media/platform/qcom/venus/venc.c:418:1-7: WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead.
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/platform/qcom/venus/venc.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c
index 8355bd59a5c2..5683a04bdc14 100644
--- a/drivers/media/platform/qcom/venus/venc.c
+++ b/drivers/media/platform/qcom/venus/venc.c
@@ -393,7 +393,7 @@ static int venc_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
struct venus_inst *inst = to_inst(file);
struct v4l2_outputparm *out = &a->parm.output;
struct v4l2_fract *timeperframe = &out->timeperframe;
- u64 us_per_frame, fps;
+ u64 us_per_frame;
if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT &&
a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
@@ -414,14 +414,10 @@ static int venc_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
if (!us_per_frame || us_per_frame > USEC_PER_SEC)
return -EINVAL;
- fps = (u64)USEC_PER_SEC;
- do_div(fps, us_per_frame);
-
- inst->fps = fps;
+ inst->fps = USEC_PER_SEC / (u32)us_per_frame;
timeperframe->numerator = 1;
timeperframe->denominator = inst->fps;
-
return 0;
}
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v4 6/6] media: venus: vdec: Make the range of us_per_frame explicit
2025-01-06 13:40 [PATCH v4 0/6] media: Fix coccinelle warning/errors Ricardo Ribalda
` (4 preceding siblings ...)
2025-01-06 13:40 ` [PATCH v4 5/6] media: venus: venc: Make the range of us_per_frame explicit Ricardo Ribalda
@ 2025-01-06 13:40 ` Ricardo Ribalda
2025-01-07 9:35 ` Hans Verkuil
5 siblings, 1 reply; 11+ messages in thread
From: Ricardo Ribalda @ 2025-01-06 13:40 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Stanimir Varbanov, Vikash Garodia,
Bryan O'Donoghue, Hans Verkuil, Hans Verkuil
Cc: linux-media, linux-kernel, Stanimir Varbanov, linux-arm-msm,
Ricardo Ribalda
Fps bigger than 0.000232829 fps, this fits in a 32 bit us_per_frame.
There is no need to do a 64 bit division here.
Also, the driver only works with whole fps.
Found by cocci:
drivers/media/platform/qcom/venus/vdec.c:488:1-7: WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead.
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/platform/qcom/venus/vdec.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
index 6b8906ced6bc..88f6b5a3a4fe 100644
--- a/drivers/media/platform/qcom/venus/vdec.c
+++ b/drivers/media/platform/qcom/venus/vdec.c
@@ -464,7 +464,7 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
struct venus_inst *inst = to_inst(file);
struct v4l2_captureparm *cap = &a->parm.capture;
struct v4l2_fract *timeperframe = &cap->timeperframe;
- u64 us_per_frame, fps;
+ u64 us_per_frame;
if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE &&
a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
@@ -486,10 +486,7 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
if (!us_per_frame || us_per_frame > USEC_PER_SEC)
return -EINVAL;
- fps = (u64)USEC_PER_SEC;
- do_div(fps, us_per_frame);
-
- inst->fps = fps;
+ inst->fps = USEC_PER_SEC / (u32)us_per_frame;
timeperframe->numerator = 1;
timeperframe->denominator = inst->fps;
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v4 2/6] media: venus: vdec: Ignore parm smaller than 1fps
2025-01-06 13:40 ` [PATCH v4 2/6] media: venus: vdec: Ignore parm smaller than 1fps Ricardo Ribalda
@ 2025-01-06 14:08 ` Bryan O'Donoghue
0 siblings, 0 replies; 11+ messages in thread
From: Bryan O'Donoghue @ 2025-01-06 14:08 UTC (permalink / raw)
To: Ricardo Ribalda, Mauro Carvalho Chehab, Stanimir Varbanov,
Vikash Garodia, Hans Verkuil, Hans Verkuil
Cc: linux-media, linux-kernel, Stanimir Varbanov, linux-arm-msm
On 06/01/2025 13:40, Ricardo Ribalda wrote:
> The driver uses "whole" fps in all its calculations (e.g. in
> load_per_instance()) Return -EINVAL if the user provides a parm that
> will result in 0 whole fps.
>
> Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
> Closes: https://lore.kernel.org/linux-media/f11653a7-bc49-48cd-9cdb-1659147453e4@xs4all.nl/T/#m91cd962ac942834654f94c92206e2f85ff7d97f0
> Fixes: 7472c1c69138 ("[media] media: venus: vdec: add video decoder files")
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
> drivers/media/platform/qcom/venus/vdec.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
> index 98c22b9f9372..25edd77b9cf9 100644
> --- a/drivers/media/platform/qcom/venus/vdec.c
> +++ b/drivers/media/platform/qcom/venus/vdec.c
> @@ -481,7 +481,7 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
> us_per_frame = timeperframe->numerator * (u64)USEC_PER_SEC;
> do_div(us_per_frame, timeperframe->denominator);
>
> - if (!us_per_frame)
> + if (!us_per_frame || us_per_frame > USEC_PER_SEC)
> return -EINVAL;
>
> fps = (u64)USEC_PER_SEC;
>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v4 3/6] media: venus: venc: Ignore parm smaller than 1fps
2025-01-06 13:40 ` [PATCH v4 3/6] media: venus: venc: " Ricardo Ribalda
@ 2025-01-06 14:08 ` Bryan O'Donoghue
0 siblings, 0 replies; 11+ messages in thread
From: Bryan O'Donoghue @ 2025-01-06 14:08 UTC (permalink / raw)
To: Ricardo Ribalda, Mauro Carvalho Chehab, Stanimir Varbanov,
Vikash Garodia, Hans Verkuil, Hans Verkuil
Cc: linux-media, linux-kernel, Stanimir Varbanov, linux-arm-msm
On 06/01/2025 13:40, Ricardo Ribalda wrote:
> The driver uses "whole" fps in all its calculations (e.g. in
> load_per_instance()). Return -EINVAL if the user provides a parm that
> will result in 0 whole fps.
>
> Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
> Closes: https://lore.kernel.org/linux-media/f11653a7-bc49-48cd-9cdb-1659147453e4@xs4all.nl/T/#m91cd962ac942834654f94c92206e2f85ff7d97f0
> Fixes: aaaa93eda64b ("[media] media: venus: venc: add video encoder files")
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
> drivers/media/platform/qcom/venus/venc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c
> index c1c543535aaf..bd967d60c883 100644
> --- a/drivers/media/platform/qcom/venus/venc.c
> +++ b/drivers/media/platform/qcom/venus/venc.c
> @@ -411,7 +411,7 @@ static int venc_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
> us_per_frame = timeperframe->numerator * (u64)USEC_PER_SEC;
> do_div(us_per_frame, timeperframe->denominator);
>
> - if (!us_per_frame)
> + if (!us_per_frame || us_per_frame > USEC_PER_SEC)
> return -EINVAL;
>
> fps = (u64)USEC_PER_SEC;
>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v4 6/6] media: venus: vdec: Make the range of us_per_frame explicit
2025-01-06 13:40 ` [PATCH v4 6/6] media: venus: vdec: " Ricardo Ribalda
@ 2025-01-07 9:35 ` Hans Verkuil
2025-01-07 9:54 ` Stanimir Varbanov
0 siblings, 1 reply; 11+ messages in thread
From: Hans Verkuil @ 2025-01-07 9:35 UTC (permalink / raw)
To: Ricardo Ribalda, Mauro Carvalho Chehab, Stanimir Varbanov,
Vikash Garodia, Bryan O'Donoghue, Hans Verkuil
Cc: linux-media, linux-kernel, Stanimir Varbanov, linux-arm-msm
On 06/01/2025 14:40, Ricardo Ribalda wrote:
> Fps bigger than 0.000232829 fps, this fits in a 32 bit us_per_frame.
> There is no need to do a 64 bit division here.
> Also, the driver only works with whole fps.
>
> Found by cocci:
> drivers/media/platform/qcom/venus/vdec.c:488:1-7: WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead.
>
> Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
> drivers/media/platform/qcom/venus/vdec.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
> index 6b8906ced6bc..88f6b5a3a4fe 100644
> --- a/drivers/media/platform/qcom/venus/vdec.c
> +++ b/drivers/media/platform/qcom/venus/vdec.c
> @@ -464,7 +464,7 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
> struct venus_inst *inst = to_inst(file);
> struct v4l2_captureparm *cap = &a->parm.capture;
> struct v4l2_fract *timeperframe = &cap->timeperframe;
> - u64 us_per_frame, fps;
> + u64 us_per_frame;
>
> if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE &&
> a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
> @@ -486,10 +486,7 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
> if (!us_per_frame || us_per_frame > USEC_PER_SEC)
> return -EINVAL;
>
> - fps = (u64)USEC_PER_SEC;
> - do_div(fps, us_per_frame);
> -
> - inst->fps = fps;
> + inst->fps = USEC_PER_SEC / (u32)us_per_frame;
This still allows for an fps value of USEC_PER_SEC if us_per_frame is 1.
Looking at where inst->fps is used I see:
drivers/media/platform/qcom/venus/pm_helpers.c: return mbs * inst->fps;
drivers/media/platform/qcom/venus/venc.c: frate.framerate = inst->fps * (1 << 16);
(mbs is at most 512x512)
So if fps is USEC_PER_SEC those calculations will wrap around.
What is the real maximum fps that the HW can handle?
Stan? Bryan? It would be nice if there is a proper sanity check here.
Regards,
Hans
> timeperframe->numerator = 1;
> timeperframe->denominator = inst->fps;
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v4 6/6] media: venus: vdec: Make the range of us_per_frame explicit
2025-01-07 9:35 ` Hans Verkuil
@ 2025-01-07 9:54 ` Stanimir Varbanov
0 siblings, 0 replies; 11+ messages in thread
From: Stanimir Varbanov @ 2025-01-07 9:54 UTC (permalink / raw)
To: Hans Verkuil, Ricardo Ribalda, Mauro Carvalho Chehab,
Stanimir Varbanov, Vikash Garodia, Bryan O'Donoghue,
Hans Verkuil
Cc: linux-media, linux-kernel, Stanimir Varbanov, linux-arm-msm
On 1/7/25 11:35 AM, Hans Verkuil wrote:
> On 06/01/2025 14:40, Ricardo Ribalda wrote:
>> Fps bigger than 0.000232829 fps, this fits in a 32 bit us_per_frame.
>> There is no need to do a 64 bit division here.
>> Also, the driver only works with whole fps.
>>
>> Found by cocci:
>> drivers/media/platform/qcom/venus/vdec.c:488:1-7: WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead.
>>
>> Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
>> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
>> ---
>> drivers/media/platform/qcom/venus/vdec.c | 7 ++-----
>> 1 file changed, 2 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
>> index 6b8906ced6bc..88f6b5a3a4fe 100644
>> --- a/drivers/media/platform/qcom/venus/vdec.c
>> +++ b/drivers/media/platform/qcom/venus/vdec.c
>> @@ -464,7 +464,7 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
>> struct venus_inst *inst = to_inst(file);
>> struct v4l2_captureparm *cap = &a->parm.capture;
>> struct v4l2_fract *timeperframe = &cap->timeperframe;
>> - u64 us_per_frame, fps;
>> + u64 us_per_frame;
>>
>> if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE &&
>> a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
>> @@ -486,10 +486,7 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
>> if (!us_per_frame || us_per_frame > USEC_PER_SEC)
>> return -EINVAL;
>>
>> - fps = (u64)USEC_PER_SEC;
>> - do_div(fps, us_per_frame);
>> -
>> - inst->fps = fps;
>> + inst->fps = USEC_PER_SEC / (u32)us_per_frame;
>
> This still allows for an fps value of USEC_PER_SEC if us_per_frame is 1.
>
> Looking at where inst->fps is used I see:
>
> drivers/media/platform/qcom/venus/pm_helpers.c: return mbs * inst->fps;
> drivers/media/platform/qcom/venus/venc.c: frate.framerate = inst->fps * (1 << 16);
>
> (mbs is at most 512x512)
>
> So if fps is USEC_PER_SEC those calculations will wrap around.
>
> What is the real maximum fps that the HW can handle?
>
> Stan? Bryan? It would be nice if there is a proper sanity check here.
It depends on the resolution but I think we could limit the maximum to
240 FPS per instance.
~Stan
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-01-07 9:54 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-06 13:40 [PATCH v4 0/6] media: Fix coccinelle warning/errors Ricardo Ribalda
2025-01-06 13:40 ` [PATCH v4 1/6] media: dvb-frontends: tda10048: Make the range of z explicit Ricardo Ribalda
2025-01-06 13:40 ` [PATCH v4 2/6] media: venus: vdec: Ignore parm smaller than 1fps Ricardo Ribalda
2025-01-06 14:08 ` Bryan O'Donoghue
2025-01-06 13:40 ` [PATCH v4 3/6] media: venus: venc: " Ricardo Ribalda
2025-01-06 14:08 ` Bryan O'Donoghue
2025-01-06 13:40 ` [PATCH v4 4/6] media: venus: Remove timeperframe from inst Ricardo Ribalda
2025-01-06 13:40 ` [PATCH v4 5/6] media: venus: venc: Make the range of us_per_frame explicit Ricardo Ribalda
2025-01-06 13:40 ` [PATCH v4 6/6] media: venus: vdec: " Ricardo Ribalda
2025-01-07 9:35 ` Hans Verkuil
2025-01-07 9:54 ` Stanimir Varbanov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®