2024-04-29 15:29:55

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v3 00/26] media: Fix coccinelle warning/errors

After this set is applied, these are the only warnings left:
drivers/media/pci/ivtv/ivtv-fileops.c:223:4-10: preceding lock on line 267
drivers/media/pci/ivtv/ivtv-fileops.c:230:3-9: preceding lock on line 267
drivers/media/pci/ivtv/ivtv-fileops.c:236:4-10: preceding lock on line 267
drivers/media/pci/ivtv/ivtv-fileops.c:245:3-9: preceding lock on line 267
drivers/media/pci/ivtv/ivtv-fileops.c:251:3-9: preceding lock on line 267
drivers/media/pci/ivtv/ivtv-fileops.c:257:3-9: preceding lock on line 267
drivers/media/pci/ivtv/ivtv-fileops.c:272:3-9: preceding lock on line 267
drivers/media/pci/ivtv/ivtv-fileops.c:598:4-10: preceding lock on line 627
drivers/media/pci/ivtv/ivtv-fileops.c:598:4-10: preceding lock on line 689
drivers/media/pci/ivtv/ivtv-fileops.c:606:3-9: preceding lock on line 627
drivers/media/pci/ivtv/ivtv-fileops.c:606:3-9: preceding lock on line 689
drivers/media/pci/ivtv/ivtv-fileops.c:648:3-9: preceding lock on line 627
drivers/media/pci/ivtv/ivtv-fileops.c:648:3-9: preceding lock on line 689
drivers/media/pci/ivtv/ivtv-fileops.c:692:4-10: preceding lock on line 689
drivers/media/dvb-core/dvb_frontend.c:2897:1-7: preceding lock on line 2776
drivers/media/dvb-core/dvb_frontend.c:2897:1-7: preceding lock on line 2786
drivers/media/dvb-core/dvb_frontend.c:2897:1-7: preceding lock on line 2809
drivers/media/dvb-frontends/stv090x.c:799:1-7: preceding lock on line 768
drivers/media/usb/go7007/go7007-i2c.c:125:1-7: preceding lock on line 61
drivers/media/rc/imon.c:1167:1-7: preceding lock on line 1153
drivers/media/pci/cx18/cx18-scb.h:261:22-29: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_cmds.h:77:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_cmds.h:85:5-16: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_cmds.h:154:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_cmds.h:171:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_cmds.h:180:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_cmds.h:189:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_cmds.h:201:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_cmds.h:220:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_cmds.h:230:5-16: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_helper.h:764:5-15: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_helper.h:1008:43-60: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_helper.h:1014:36-46: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_helper.h:1041:5-15: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_helper.h:1088:39-51: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_helper.h:1093:5-22: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_helper.h:1144:4-8: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_helper.h:1239:4-8: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_helper.h:1267:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/qcom/venus/hfi_helper.h:1272:4-13: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/common/siano/smscoreapi.h:619:5-13: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/common/siano/smscoreapi.h:669:6-13: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/common/siano/smscoreapi.h:1049:4-8: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/common/siano/smscoreapi.h:1055:4-8: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/dvb-frontends/mxl5xx_defs.h:171:4-8: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/dvb-frontends/mxl5xx_defs.h:182:4-8: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/allegro-dvt/nal-hevc.h:102:14-22: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/media/platform/xilinx/xilinx-dma.h:100:19-22: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
drivers/staging/media/atomisp/pci/atomisp_tpg.h:30:18-22: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)

CI tested:
https://gitlab.freedesktop.org/linux-media/media-staging/-/commit/055b5211c68e721c3a7090be5373cf44859da1a7/pipelines?ref=ribalda%2Ftest-cocci

Signed-off-by: Ricardo Ribalda <[email protected]>
---
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/[email protected]

Changes in v2:
- Remove all the min() retval, and send a patch for cocci: https://lore.kernel.org/lkml/[email protected]/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/[email protected]

---
Ricardo Ribalda (26):
media: pci: mgb4: Refactor struct resources
media: stb0899: Simplify check
media: uvcvideo: Refactor iterators
media: uvcvideo: Use max() macro
media: go7007: Use min and max macros
media: stm32-dcmipp: Remove redundant printk
media: staging: sun6i-isp: Remove redundant printk
media: dvb-frontends: tda18271c2dd: Remove casting during div
media: v4l: async: refactor v4l2_async_create_ancillary_links
staging: media: tegra-video: Use swap macro
media: s2255: Use refcount_t instead of atomic_t for num_channels
media: platform: mtk-mdp3: Use refcount_t for job_count
media: common: saa7146: Use min macro
media: dvb-frontends: drx39xyj: Use min macro
media: netup_unidvb: Use min macro
media: au0828: Use umin macro
media: flexcop-usb: Use min macro
media: gspca: cpia1: Use min macro
media: stk1160: Use min macro
media: tegra-vde: Refactor timeout handling
media: i2c: st-mipid02: Use the correct div function
media: tc358746: Use the correct div_ function
media: venus: vdec: Make the range of us_per_frame explicit
media: venus: venc: Make the range of us_per_frame explicit
media: dvb-frontends: tda10048: Fix integer overflow
media: dvb-frontends: tda10048: Make the range of z explicit.

drivers/media/common/saa7146/saa7146_hlp.c | 8 +++----
drivers/media/dvb-frontends/drx39xyj/drxj.c | 9 +++-----
drivers/media/dvb-frontends/stb0899_drv.c | 2 +-
drivers/media/dvb-frontends/tda10048.c | 13 +++++++----
drivers/media/dvb-frontends/tda18271c2dd.c | 4 ++--
drivers/media/i2c/st-mipid02.c | 2 +-
drivers/media/i2c/tc358746.c | 3 +--
drivers/media/pci/mgb4/mgb4_core.c | 4 ++--
drivers/media/pci/mgb4/mgb4_regs.c | 2 +-
drivers/media/pci/netup_unidvb/netup_unidvb_i2c.c | 2 +-
.../media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c | 10 ++++-----
.../media/platform/mediatek/mdp3/mtk-mdp3-core.c | 6 ++---
.../media/platform/mediatek/mdp3/mtk-mdp3-core.h | 2 +-
.../media/platform/mediatek/mdp3/mtk-mdp3-m2m.c | 6 ++---
drivers/media/platform/nvidia/tegra-vde/h264.c | 6 ++---
drivers/media/platform/qcom/venus/vdec.c | 7 ++----
drivers/media/platform/qcom/venus/venc.c | 7 ++----
.../platform/st/stm32/stm32-dcmipp/dcmipp-core.c | 7 ++----
drivers/media/usb/au0828/au0828-video.c | 5 +----
drivers/media/usb/b2c2/flexcop-usb.c | 5 +----
drivers/media/usb/go7007/go7007-fw.c | 4 ++--
drivers/media/usb/gspca/cpia1.c | 6 ++---
drivers/media/usb/s2255/s2255drv.c | 20 ++++++++---------
drivers/media/usb/stk1160/stk1160-video.c | 10 ++-------
drivers/media/usb/uvc/uvc_ctrl.c | 26 ++++++++++++----------
drivers/media/v4l2-core/v4l2-async.c | 7 +++---
drivers/staging/media/sunxi/sun6i-isp/sun6i_isp.c | 3 +--
drivers/staging/media/tegra-video/tegra20.c | 9 ++------
28 files changed, 84 insertions(+), 111 deletions(-)
---
base-commit: cefc10d0d9164eb2f62e789b69dc658dc851eb58
change-id: 20240415-fix-cocci-2df3ef22a6f7

Best regards,
--
Ricardo Ribalda <[email protected]>



2024-04-29 15:30:48

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v3 04/26] media: uvcvideo: Use max() macro

It makes the code slightly more clear and makes cocci incredibly happy:

drivers/media/usb/uvc/uvc_ctrl.c:839:22-23: WARNING opportunity for max()

Reviewed-by: Sergey Senozhatsky <[email protected]>
Reviewed-by: Kieran Bingham <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/usb/uvc/uvc_ctrl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index a4a987913430..4b685f883e4d 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -836,7 +836,7 @@ static s32 uvc_get_le_value(struct uvc_control_mapping *mapping,
while (1) {
u8 byte = *data & mask;
value |= offset > 0 ? (byte >> offset) : (byte << (-offset));
- bits -= 8 - (offset > 0 ? offset : 0);
+ bits -= 8 - max(offset, 0);
if (bits <= 0)
break;


--
2.44.0.769.g3c40516874-goog


2024-04-29 15:32:55

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v3 14/26] media: dvb-frontends: drx39xyj: Use min macro

Replace ternary assignments with min() to simplify and make the code
more readable.

Found by cocci:
drivers/media/dvb-frontends/drx39xyj/drxj.c:1447:23-24: WARNING opportunity for min()
drivers/media/dvb-frontends/drx39xyj/drxj.c:1662:21-22: WARNING opportunity for min()
drivers/media/dvb-frontends/drx39xyj/drxj.c:1685:24-25: WARNING opportunity for min()

Reviewed-by: Bryan O'Donoghue <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/dvb-frontends/drx39xyj/drxj.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/media/dvb-frontends/drx39xyj/drxj.c b/drivers/media/dvb-frontends/drx39xyj/drxj.c
index 1ef53754bc03..6fcaf07e1b82 100644
--- a/drivers/media/dvb-frontends/drx39xyj/drxj.c
+++ b/drivers/media/dvb-frontends/drx39xyj/drxj.c
@@ -1445,8 +1445,7 @@ static int drxdap_fasi_read_block(struct i2c_device_addr *dev_addr,

/* Read block from I2C **************************************************** */
do {
- u16 todo = (datasize < DRXDAP_MAX_RCHUNKSIZE ?
- datasize : DRXDAP_MAX_RCHUNKSIZE);
+ u16 todo = min(datasize, DRXDAP_MAX_RCHUNKSIZE);

bufx = 0;

@@ -1660,7 +1659,7 @@ static int drxdap_fasi_write_block(struct i2c_device_addr *dev_addr,
Address must be rewritten because HI is reset after data transport and
expects an address.
*/
- todo = (block_size < datasize ? block_size : datasize);
+ todo = min(block_size, datasize);
if (todo == 0) {
u16 overhead_size_i2c_addr = 0;
u16 data_block_size = 0;
@@ -1682,9 +1681,7 @@ static int drxdap_fasi_write_block(struct i2c_device_addr *dev_addr,
first_err = st;
}
bufx = 0;
- todo =
- (data_block_size <
- datasize ? data_block_size : datasize);
+ todo = min(data_block_size, datasize);
}
memcpy(&buf[bufx], data, todo);
/* write (address if can do and) data */

--
2.44.0.769.g3c40516874-goog


2024-04-29 15:34:32

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v3 20/26] media: tegra-vde: Refactor timeout handling

Reorder the branches a bit, so cocci stops complaining about the code.

drivers/media/platform/nvidia/tegra-vde/h264.c:645:20-21: WARNING opportunity for min()

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/nvidia/tegra-vde/h264.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/nvidia/tegra-vde/h264.c b/drivers/media/platform/nvidia/tegra-vde/h264.c
index 204e474d57f7..cfea5572a1b8 100644
--- a/drivers/media/platform/nvidia/tegra-vde/h264.c
+++ b/drivers/media/platform/nvidia/tegra-vde/h264.c
@@ -633,7 +633,9 @@ static int tegra_vde_decode_end(struct tegra_vde *vde)

timeout = wait_for_completion_interruptible_timeout(
&vde->decode_completion, msecs_to_jiffies(1000));
- if (timeout == 0) {
+ if (timeout < 0) {
+ ret = timeout;
+ } else if (timeout == 0) {
bsev_ptr = tegra_vde_readl(vde, vde->bsev, 0x10);
macroblocks_nb = tegra_vde_readl(vde, vde->sxe, 0xC8) & 0x1FFF;
read_bytes = bsev_ptr ? bsev_ptr - vde->bitstream_data_addr : 0;
@@ -642,8 +644,6 @@ static int tegra_vde_decode_end(struct tegra_vde *vde)
read_bytes, macroblocks_nb);

ret = -EIO;
- } else if (timeout < 0) {
- ret = timeout;
} else {
ret = 0;
}

--
2.44.0.769.g3c40516874-goog


2024-04-29 15:35:33

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v3 23/26] media: venus: vdec: Make the range of us_per_frame explicit

Unless the fps is smaller than 0.000232829 fps, this fits in a 32 bit
number. Make that explicit.

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 <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
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 29130a9441e7..2b2874aedb2d 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)
@@ -484,10 +484,7 @@ static int vdec_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
if (!us_per_frame)
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;
inst->timeperframe = *timeperframe;

return 0;

--
2.44.0.769.g3c40516874-goog


2024-04-29 15:36:40

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v3 26/26] media: dvb-frontends: tda10048: Make the range of z explicit.

We do not expect the sample_freq to be over 613MHz.

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 <[email protected]>
---
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.44.0.769.g3c40516874-goog


2024-05-03 10:29:08

by Mauro Carvalho Chehab

[permalink] [raw]
Subject: Re: [PATCH v3 26/26] media: dvb-frontends: tda10048: Make the range of z explicit.

Em Mon, 29 Apr 2024 15:05:05 +0000
Ricardo Ribalda <[email protected]> escreveu:

> We do not expect the sample_freq to be over 613MHz.
>
> 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 <[email protected]>
> ---
> 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 */

Are you sure about that? Some DVB devices have very high frequency
clocks, specially if they're also used for satellite, so I can't
be sure by just looking at the driver's code.

Also, we had already a bunch of regressions with "fixes" like this
that actually broke frontend drivers.

If you're sure, please add a note at the description mentioning
on what part of the datasheet you got it.

Otherwise, let's stick with the current code and address cocci
warning on a different way.

Regards,
Mauro

PS.: I partially applied this patch series. I left a few
patches out of the merge to let other people review/comment
(and/or for me to take a deeper look later on).

Regards,
Mauro

2024-05-03 11:55:26

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH v3 26/26] media: dvb-frontends: tda10048: Make the range of z explicit.

On Fri, May 03, 2024 at 11:27:58AM +0100, Mauro Carvalho Chehab wrote:
> Em Mon, 29 Apr 2024 15:05:05 +0000
> Ricardo Ribalda <[email protected]> escreveu:
>
> > We do not expect the sample_freq to be over 613MHz.
> >
> > 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 <[email protected]>
> > ---
> > 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 */
>
> Are you sure about that? Some DVB devices have very high frequency
> clocks, specially if they're also used for satellite, so I can't
> be sure by just looking at the driver's code.
>
> Also, we had already a bunch of regressions with "fixes" like this
> that actually broke frontend drivers.

This patch preserves the existing behavior. The sample_freq_hz variable
is a u32 so, in the original code, z couldn't have been more than
U32_MAX even though it was declared as a u64.

It's possible that the original code was wrong. We have seen that in
other places in this patchset. Adding a note about the datasheet is
also a good idea.

regards,
dan carpenter


2024-05-03 11:57:44

by Ricardo Ribalda

[permalink] [raw]
Subject: Re: [PATCH v3 26/26] media: dvb-frontends: tda10048: Make the range of z explicit.

I am trying to get the DS, but
https://www.nxp.com/acrobat_download/literature/9397/75015931.pdf is a
dead links now.

Anyone have access to the datasheet?

Thanks!

On Fri, 3 May 2024 at 13:55, Dan Carpenter <[email protected]> wrote:
>
> On Fri, May 03, 2024 at 11:27:58AM +0100, Mauro Carvalho Chehab wrote:
> > Em Mon, 29 Apr 2024 15:05:05 +0000
> > Ricardo Ribalda <[email protected]> escreveu:
> >
> > > We do not expect the sample_freq to be over 613MHz.
> > >
> > > 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 <[email protected]>
> > > ---
> > > 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 */
> >
> > Are you sure about that? Some DVB devices have very high frequency
> > clocks, specially if they're also used for satellite, so I can't
> > be sure by just looking at the driver's code.
> >
> > Also, we had already a bunch of regressions with "fixes" like this
> > that actually broke frontend drivers.
>
> This patch preserves the existing behavior. The sample_freq_hz variable
> is a u32 so, in the original code, z couldn't have been more than
> U32_MAX even though it was declared as a u64.
>
> It's possible that the original code was wrong. We have seen that in
> other places in this patchset. Adding a note about the datasheet is
> also a good idea.
>
> regards,
> dan carpenter
>


--
Ricardo Ribalda

2024-05-03 14:09:09

by Dragan Simic

[permalink] [raw]
Subject: Re: [PATCH v3 26/26] media: dvb-frontends: tda10048: Make the range of z explicit.

Hello Ricardo,

On 2024-05-03 13:56, Ricardo Ribalda wrote:
> I am trying to get the DS, but
> https://www.nxp.com/acrobat_download/literature/9397/75015931.pdf is a
> dead links now.
>
> Anyone have access to the datasheet?

It's kind of available on the link below, but for some strange reason
the download fails after downloading the first 128 KB or so.

https://web.archive.org/web/20080907185532/https://www.nxp.com/acrobat_download/literature/9397/75015931.pdf


> On Fri, 3 May 2024 at 13:55, Dan Carpenter <[email protected]>
> wrote:
>>
>> On Fri, May 03, 2024 at 11:27:58AM +0100, Mauro Carvalho Chehab wrote:
>> > Em Mon, 29 Apr 2024 15:05:05 +0000
>> > Ricardo Ribalda <[email protected]> escreveu:
>> >
>> > > We do not expect the sample_freq to be over 613MHz.
>> > >
>> > > 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 <[email protected]>
>> > > ---
>> > > 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 */
>> >
>> > Are you sure about that? Some DVB devices have very high frequency
>> > clocks, specially if they're also used for satellite, so I can't
>> > be sure by just looking at the driver's code.
>> >
>> > Also, we had already a bunch of regressions with "fixes" like this
>> > that actually broke frontend drivers.
>>
>> This patch preserves the existing behavior. The sample_freq_hz
>> variable
>> is a u32 so, in the original code, z couldn't have been more than
>> U32_MAX even though it was declared as a u64.
>>
>> It's possible that the original code was wrong. We have seen that in
>> other places in this patchset. Adding a note about the datasheet is
>> also a good idea.
>>
>> regards,
>> dan carpenter
>>