2024-04-19 09:49:51

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 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 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 min 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 explicit the range of us_per_frame
media: venus: venc: Make explicit the range of us_per_frame
media: dvb-frontends: tda10048: Fix integer overflow
media: dvb-frontends: tda10048: Make explicit the range of z.

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: 836e2548524d2dfcb5acaf3be78f203b6b4bde6f
change-id: 20240415-fix-cocci-2df3ef22a6f7

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



2024-04-19 09:50:00

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 02/26] media: stb0899: Simplify check

chip_id is an unsigned number, it can never be < 0

Fixes cocci check:
drivers/media/dvb-frontends/stb0899_drv.c:1280:8-15: WARNING: Unsigned expression compared with zero: chip_id > 0

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/dvb-frontends/stb0899_drv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/stb0899_drv.c b/drivers/media/dvb-frontends/stb0899_drv.c
index 2f4d8fb400cd..35634f9a8ab5 100644
--- a/drivers/media/dvb-frontends/stb0899_drv.c
+++ b/drivers/media/dvb-frontends/stb0899_drv.c
@@ -1277,7 +1277,7 @@ static int stb0899_get_dev_id(struct stb0899_state *state)
dprintk(state->verbose, FE_ERROR, 1, "Demodulator Core ID=[%s], Version=[%d]", (char *) &demod_str, demod_ver);
CONVERT32(STB0899_READ_S2REG(STB0899_S2FEC, FEC_CORE_ID_REG), (char *)&fec_str);
fec_ver = STB0899_READ_S2REG(STB0899_S2FEC, FEC_VER_ID_REG);
- if (! (chip_id > 0)) {
+ if (!chip_id) {
dprintk(state->verbose, FE_ERROR, 1, "couldn't find a STB 0899");

return -ENODEV;

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:50:33

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 03/26] media: uvcvideo: Refactor iterators

Avoid using the iterators after the list_for_each() constructs.
This patch should be a NOP, but makes cocci, happier:

drivers/media/usb/uvc/uvc_ctrl.c:1861:44-50: ERROR: invalid reference to the index variable of the iterator on line 1850
drivers/media/usb/uvc/uvc_ctrl.c:2195:17-23: ERROR: invalid reference to the index variable of the iterator on line 2179

Reviewed-by: Sergey Senozhatsky <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/usb/uvc/uvc_ctrl.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index e59a463c2761..a4a987913430 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -1850,16 +1850,18 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback,
list_for_each_entry(entity, &chain->entities, chain) {
ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback,
&err_ctrl);
- if (ret < 0)
+ if (ret < 0) {
+ if (ctrls)
+ ctrls->error_idx =
+ uvc_ctrl_find_ctrl_idx(entity, ctrls,
+ err_ctrl);
goto done;
+ }
}

if (!rollback)
uvc_ctrl_send_events(handle, ctrls->controls, ctrls->count);
done:
- if (ret < 0 && ctrls)
- ctrls->error_idx = uvc_ctrl_find_ctrl_idx(entity, ctrls,
- err_ctrl);
mutex_unlock(&chain->ctrl_mutex);
return ret;
}
@@ -2165,7 +2167,7 @@ static int uvc_ctrl_init_xu_ctrl(struct uvc_device *dev,
int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
struct uvc_xu_control_query *xqry)
{
- struct uvc_entity *entity;
+ struct uvc_entity *entity, *iter;
struct uvc_control *ctrl;
unsigned int i;
bool found;
@@ -2175,16 +2177,16 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
int ret;

/* Find the extension unit. */
- found = false;
- list_for_each_entry(entity, &chain->entities, chain) {
- if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT &&
- entity->id == xqry->unit) {
- found = true;
+ entity = NULL;
+ list_for_each_entry(iter, &chain->entities, chain) {
+ if (UVC_ENTITY_TYPE(iter) == UVC_VC_EXTENSION_UNIT &&
+ iter->id == xqry->unit) {
+ entity = iter;
break;
}
}

- if (!found) {
+ if (!entity) {
uvc_dbg(chain->dev, CONTROL, "Extension unit %u not found\n",
xqry->unit);
return -ENOENT;

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:50:46

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 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-19 09:51:14

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 06/26] media: stm32-dcmipp: Remove redundant printk

platform_get_irq() already prints an error message.

Found by cocci:
drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-core.c:444:3-10: line 444 is redundant because platform_get_irq() already prints an error

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-core.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-core.c b/drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-core.c
index bce821eb71ce..4acc3b90d03a 100644
--- a/drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-core.c
+++ b/drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-core.c
@@ -439,11 +439,8 @@ static int dcmipp_probe(struct platform_device *pdev)
"Could not get reset control\n");

irq = platform_get_irq(pdev, 0);
- if (irq <= 0) {
- if (irq != -EPROBE_DEFER)
- dev_err(&pdev->dev, "Could not get irq\n");
- return irq ? irq : -ENXIO;
- }
+ if (irq < 0)
+ return irq;

dcmipp->regs = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
if (IS_ERR(dcmipp->regs)) {

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:51:33

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 07/26] media: staging: sun6i-isp: Remove redundant printk

platform_get_irq() already prints an error for us.

Found by cocci:
drivers/staging/media/sunxi/sun6i-isp/sun6i_isp.c:389:2-9: line 389 is redundant because platform_get_irq() already prints an error

Acked-by: Jernej Skrabec <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/staging/media/sunxi/sun6i-isp/sun6i_isp.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp.c b/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp.c
index 5c0a45394cba..58f8ae92320d 100644
--- a/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp.c
+++ b/drivers/staging/media/sunxi/sun6i-isp/sun6i_isp.c
@@ -386,8 +386,7 @@ static int sun6i_isp_resources_setup(struct sun6i_isp_device *isp_dev,

irq = platform_get_irq(platform_dev, 0);
if (irq < 0) {
- dev_err(dev, "failed to get interrupt\n");
- ret = -ENXIO;
+ ret = irq;
goto error_clock_rate_exclusive;
}


--
2.44.0.769.g3c40516874-goog


2024-04-19 09:51:37

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 05/26] media: go7007: Use min and max macros

It makes the code simpler and cocci happier:

drivers/media/usb/go7007/go7007-fw.c:1292:14-15: WARNING opportunity for max()
drivers/media/usb/go7007/go7007-fw.c:1293:14-15: WARNING opportunity for min()

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/usb/go7007/go7007-fw.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/go7007/go7007-fw.c b/drivers/media/usb/go7007/go7007-fw.c
index 018019ba47d4..86ce593e0c54 100644
--- a/drivers/media/usb/go7007/go7007-fw.c
+++ b/drivers/media/usb/go7007/go7007-fw.c
@@ -1289,8 +1289,8 @@ static int avsync_to_package(struct go7007 *go, __le16 *code, int space)
0xbf99, (u16)((-adjratio) >> 16),
0xbf92, 0,
0xbf93, 0,
- 0xbff4, f1 > f2 ? f1 : f2,
- 0xbff5, f1 < f2 ? f1 : f2,
+ 0xbff4, max(f1, f2),
+ 0xbff5, min(f1, f2),
0xbff6, f1 < f2 ? ratio : ratio + 1,
0xbff7, f1 > f2 ? ratio : ratio + 1,
0xbff8, 0,

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:51:36

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 08/26] media: dvb-frontends: tda18271c2dd: Remove casting during div

do_div() divides 64 bits by 32. We were adding a casting to the divider
to 64 bits, for a number that fits perfectly in 32 bits. Remove it.

Found by cocci:
drivers/media/dvb-frontends/tda18271c2dd.c:355:1-7: WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead.
drivers/media/dvb-frontends/tda18271c2dd.c:331: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/tda18271c2dd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/tda18271c2dd.c b/drivers/media/dvb-frontends/tda18271c2dd.c
index a34834487943..fd928787207e 100644
--- a/drivers/media/dvb-frontends/tda18271c2dd.c
+++ b/drivers/media/dvb-frontends/tda18271c2dd.c
@@ -328,7 +328,7 @@ static int CalcMainPLL(struct tda_state *state, u32 freq)

OscFreq = (u64) freq * (u64) Div;
OscFreq *= (u64) 16384;
- do_div(OscFreq, (u64)16000000);
+ do_div(OscFreq, 16000000);
MainDiv = OscFreq;

state->m_Regs[MPD] = PostDiv & 0x77;
@@ -352,7 +352,7 @@ static int CalcCalPLL(struct tda_state *state, u32 freq)
OscFreq = (u64)freq * (u64)Div;
/* CalDiv = u32( OscFreq * 16384 / 16000000 ); */
OscFreq *= (u64)16384;
- do_div(OscFreq, (u64)16000000);
+ do_div(OscFreq, 16000000);
CalDiv = OscFreq;

state->m_Regs[CPD] = PostDiv;

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:52:49

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 11/26] media: s2255: Use refcount_t instead of atomic_t for num_channels

Use an API that resembles more the actual use of num_channels.

Found by cocci:
drivers/media/usb/s2255/s2255drv.c:2362:5-24: WARNING: atomic_dec_and_test variation before object free at line 2363.
drivers/media/usb/s2255/s2255drv.c:1557:5-24: WARNING: atomic_dec_and_test variation before object free at line 1558.

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/usb/s2255/s2255drv.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index 8e1de1e8bd12..a6e450181fd0 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -247,7 +247,7 @@ struct s2255_vc {
struct s2255_dev {
struct s2255_vc vc[MAX_CHANNELS];
struct v4l2_device v4l2_dev;
- atomic_t num_channels;
+ refcount_t num_channels;
int frames;
struct mutex lock; /* channels[].vdev.lock */
struct mutex cmdlock; /* protects cmdbuf */
@@ -1550,11 +1550,11 @@ static void s2255_video_device_release(struct video_device *vdev)
container_of(vdev, struct s2255_vc, vdev);

dprintk(dev, 4, "%s, chnls: %d\n", __func__,
- atomic_read(&dev->num_channels));
+ refcount_read(&dev->num_channels));

v4l2_ctrl_handler_free(&vc->hdl);

- if (atomic_dec_and_test(&dev->num_channels))
+ if (refcount_dec_and_test(&dev->num_channels))
s2255_destroy(dev);
return;
}
@@ -1659,7 +1659,7 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
"failed to register video device!\n");
break;
}
- atomic_inc(&dev->num_channels);
+ refcount_inc(&dev->num_channels);
v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n",
video_device_node_name(&vc->vdev));

@@ -1667,11 +1667,11 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
pr_info("Sensoray 2255 V4L driver Revision: %s\n",
S2255_VERSION);
/* if no channels registered, return error and probe will fail*/
- if (atomic_read(&dev->num_channels) == 0) {
+ if (refcount_read(&dev->num_channels) == 0) {
v4l2_device_unregister(&dev->v4l2_dev);
return ret;
}
- if (atomic_read(&dev->num_channels) != MAX_CHANNELS)
+ if (refcount_read(&dev->num_channels) != MAX_CHANNELS)
pr_warn("s2255: Not all channels available.\n");
return 0;
}
@@ -2221,7 +2221,7 @@ static int s2255_probe(struct usb_interface *interface,
goto errorFWDATA1;
}

- atomic_set(&dev->num_channels, 0);
+ refcount_set(&dev->num_channels, 0);
dev->pid = id->idProduct;
dev->fw_data = kzalloc(sizeof(struct s2255_fw), GFP_KERNEL);
if (!dev->fw_data)
@@ -2341,12 +2341,12 @@ static void s2255_disconnect(struct usb_interface *interface)
{
struct s2255_dev *dev = to_s2255_dev(usb_get_intfdata(interface));
int i;
- int channels = atomic_read(&dev->num_channels);
+ int channels = refcount_read(&dev->num_channels);
mutex_lock(&dev->lock);
v4l2_device_disconnect(&dev->v4l2_dev);
mutex_unlock(&dev->lock);
/*see comments in the uvc_driver.c usb disconnect function */
- atomic_inc(&dev->num_channels);
+ refcount_inc(&dev->num_channels);
/* unregister each video device. */
for (i = 0; i < channels; i++)
video_unregister_device(&dev->vc[i].vdev);
@@ -2359,7 +2359,7 @@ static void s2255_disconnect(struct usb_interface *interface)
dev->vc[i].vidstatus_ready = 1;
wake_up(&dev->vc[i].wait_vidstatus);
}
- if (atomic_dec_and_test(&dev->num_channels))
+ if (refcount_dec_and_test(&dev->num_channels))
s2255_destroy(dev);
dev_info(&interface->dev, "%s\n", __func__);
}

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:53:06

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 10/26] staging: media: tegra-video: Use swap macro

Makes the code simpler and cocci happier:

drivers/staging/media/tegra-video/tegra20.c:324:44-45: WARNING opportunity for swap()

Reviewed-by: Luca Ceresoli <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/staging/media/tegra-video/tegra20.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/tegra-video/tegra20.c b/drivers/staging/media/tegra-video/tegra20.c
index 630e2ff987a3..7b8f8f810b35 100644
--- a/drivers/staging/media/tegra-video/tegra20.c
+++ b/drivers/staging/media/tegra-video/tegra20.c
@@ -317,13 +317,8 @@ static void tegra20_channel_queue_setup(struct tegra_vi_channel *chan)
chan->addr_offset_v = chan->addr_offset_u + stride * height / 4;

/* For YVU420, we swap the locations of the U and V planes. */
- if (chan->format.pixelformat == V4L2_PIX_FMT_YVU420) {
- unsigned long temp;
-
- temp = chan->addr_offset_u;
- chan->addr_offset_u = chan->addr_offset_v;
- chan->addr_offset_v = temp;
- }
+ if (chan->format.pixelformat == V4L2_PIX_FMT_YVU420)
+ swap(chan->addr_offset_u, chan->addr_offset_v);

chan->start_offset_u = chan->addr_offset_u;
chan->start_offset_v = chan->addr_offset_v;

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:53:10

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 09/26] media: v4l: async: refactor v4l2_async_create_ancillary_links

Return 0 without checking IS_ERR or PTR_ERR if CONFIG_MEDIA_CONTROLLER
is not enabled.

This makes cocci happier:

drivers/media/v4l2-core/v4l2-async.c:331:23-30: ERROR: PTR_ERR applied after initialization to constant on line 319

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/v4l2-core/v4l2-async.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
index 4bb073587817..915a9f3ea93c 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -316,9 +316,10 @@ v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);
static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
struct v4l2_subdev *sd)
{
- struct media_link *link = NULL;
+ struct media_link *link;

-#if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
+ if (!IS_ENABLED(CONFIG_MEDIA_CONTROLLER))
+ return 0;

if (sd->entity.function != MEDIA_ENT_F_LENS &&
sd->entity.function != MEDIA_ENT_F_FLASH)
@@ -326,8 +327,6 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,

link = media_create_ancillary_link(&n->sd->entity, &sd->entity);

-#endif
-
return IS_ERR(link) ? PTR_ERR(link) : 0;
}


--
2.44.0.769.g3c40516874-goog


2024-04-19 09:53:17

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 12/26] media: platform: mtk-mdp3: Use refcount_t for job_count

Use an API that resembles more the actual use of job_count.

Found by cocci:
drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c:527:5-24: WARNING: atomic_dec_and_test variation before object free at line 541.
drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c:578:6-25: WARNING: atomic_dec_and_test variation before object free at line 581.

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c | 10 +++++-----
drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.c | 6 +++---
drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.h | 2 +-
drivers/media/platform/mediatek/mdp3/mtk-mdp3-m2m.c | 6 +++---
4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c
index 1d64bac34b90..ea2ea119dd2a 100644
--- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c
+++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c
@@ -524,7 +524,7 @@ static void mdp_auto_release_work(struct work_struct *work)
mdp_comp_clocks_off(&mdp->pdev->dev, cmd->comps,
cmd->num_comps);

- if (atomic_dec_and_test(&mdp->job_count)) {
+ if (refcount_dec_and_test(&mdp->job_count)) {
if (cmd->mdp_ctx)
mdp_m2m_job_finish(cmd->mdp_ctx);

@@ -575,7 +575,7 @@ static void mdp_handle_cmdq_callback(struct mbox_client *cl, void *mssg)
mdp_comp_clocks_off(&mdp->pdev->dev, cmd->comps,
cmd->num_comps);

- if (atomic_dec_and_test(&mdp->job_count))
+ if (refcount_dec_and_test(&mdp->job_count))
wake_up(&mdp->callback_wq);

mdp_cmdq_pkt_destroy(&cmd->pkt);
@@ -724,9 +724,9 @@ int mdp_cmdq_send(struct mdp_dev *mdp, struct mdp_cmdq_param *param)
int i, ret;
u8 pp_used = __get_pp_num(param->param->type);

- atomic_set(&mdp->job_count, pp_used);
+ refcount_set(&mdp->job_count, pp_used);
if (atomic_read(&mdp->suspended)) {
- atomic_set(&mdp->job_count, 0);
+ refcount_set(&mdp->job_count, 0);
return -ECANCELED;
}

@@ -764,7 +764,7 @@ int mdp_cmdq_send(struct mdp_dev *mdp, struct mdp_cmdq_param *param)
mdp_comp_clocks_off(&mdp->pdev->dev, cmd[i]->comps,
cmd[i]->num_comps);
err_cancel_job:
- atomic_set(&mdp->job_count, 0);
+ refcount_set(&mdp->job_count, 0);

return ret;
}
diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.c
index 5209f531ef8d..c1f3bf98120a 100644
--- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.c
+++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.c
@@ -380,14 +380,14 @@ static int __maybe_unused mdp_suspend(struct device *dev)

atomic_set(&mdp->suspended, 1);

- if (atomic_read(&mdp->job_count)) {
+ if (refcount_read(&mdp->job_count)) {
ret = wait_event_timeout(mdp->callback_wq,
- !atomic_read(&mdp->job_count),
+ !refcount_read(&mdp->job_count),
2 * HZ);
if (ret == 0) {
dev_err(dev,
"%s:flushed cmdq task incomplete, count=%d\n",
- __func__, atomic_read(&mdp->job_count));
+ __func__, refcount_read(&mdp->job_count));
return -EBUSY;
}
}
diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.h b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.h
index 8c09e984fd01..430251f63754 100644
--- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.h
+++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.h
@@ -134,7 +134,7 @@ struct mdp_dev {
/* synchronization protect for m2m device operation */
struct mutex m2m_lock;
atomic_t suspended;
- atomic_t job_count;
+ refcount_t job_count;
};

struct mdp_pipe_info {
diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-m2m.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-m2m.c
index 35a8b059bde5..0e69128a3772 100644
--- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-m2m.c
+++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-m2m.c
@@ -104,14 +104,14 @@ static void mdp_m2m_device_run(void *priv)
task.cb_data = NULL;
task.mdp_ctx = ctx;

- if (atomic_read(&ctx->mdp_dev->job_count)) {
+ if (refcount_read(&ctx->mdp_dev->job_count)) {
ret = wait_event_timeout(ctx->mdp_dev->callback_wq,
- !atomic_read(&ctx->mdp_dev->job_count),
+ !refcount_read(&ctx->mdp_dev->job_count),
2 * HZ);
if (ret == 0) {
dev_err(&ctx->mdp_dev->pdev->dev,
"%d jobs not yet done\n",
- atomic_read(&ctx->mdp_dev->job_count));
+ refcount_read(&ctx->mdp_dev->job_count));
goto worker_end;
}
}

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:53:23

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 13/26] media: common: saa7146: Use min macro

Simplifies the code. Found by cocci:

drivers/media/common/saa7146/saa7146_hlp.c:125:36-37: WARNING opportunity for min()
drivers/media/common/saa7146/saa7146_hlp.c:154:41-42: WARNING opportunity for min()
drivers/media/common/saa7146/saa7146_hlp.c:286:35-36: WARNING opportunity for min()
drivers/media/common/saa7146/saa7146_hlp.c:289:35-36: WARNING opportunity for min()

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/common/saa7146/saa7146_hlp.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/common/saa7146/saa7146_hlp.c b/drivers/media/common/saa7146/saa7146_hlp.c
index 7569d8cdd4d8..fe3348af543e 100644
--- a/drivers/media/common/saa7146/saa7146_hlp.c
+++ b/drivers/media/common/saa7146/saa7146_hlp.c
@@ -122,7 +122,7 @@ static int calculate_h_scale_registers(struct saa7146_dev *dev,
xacm = 0;

/* set horizontal filter parameters (CXY = CXUV) */
- cxy = hps_h_coeff_tab[( (xpsc - 1) < 63 ? (xpsc - 1) : 63 )].hps_coeff;
+ cxy = hps_h_coeff_tab[min(xpsc - 1, 63)].hps_coeff;
cxuv = cxy;

/* calculate and set horizontal fine scale (xsci) */
@@ -151,7 +151,7 @@ static int calculate_h_scale_registers(struct saa7146_dev *dev,
xacm = 0;
/* get best match in the table of attenuations
for horizontal scaling */
- h_atten = hps_h_coeff_tab[( (xpsc - 1) < 63 ? (xpsc - 1) : 63 )].weight_sum;
+ h_atten = hps_h_coeff_tab[min(xpsc - 1, 63)].weight_sum;

for (i = 0; h_attenuation[i] != 0; i++) {
if (h_attenuation[i] >= h_atten)
@@ -283,10 +283,10 @@ static int calculate_v_scale_registers(struct saa7146_dev *dev, enum v4l2_field
}

/* get filter coefficients for cya, cyb from table hps_v_coeff_tab */
- cya_cyb = hps_v_coeff_tab[ (yacl < 63 ? yacl : 63 ) ].hps_coeff;
+ cya_cyb = hps_v_coeff_tab[min(yacl, 63)].hps_coeff;

/* get best match in the table of attenuations for vertical scaling */
- v_atten = hps_v_coeff_tab[ (yacl < 63 ? yacl : 63 ) ].weight_sum;
+ v_atten = hps_v_coeff_tab[min(yacl, 63)].weight_sum;

for (i = 0; v_attenuation[i] != 0; i++) {
if (v_attenuation[i] >= v_atten)

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:53:41

by Ricardo Ribalda

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

Simplifies the code.

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()

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-19 09:53:50

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 15/26] media: netup_unidvb: Use min macro

Simplify the code.

Found by cocci:
drivers/media/pci/netup_unidvb/netup_unidvb_i2c.c:138:26-27: WARNING opportunity for min()

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/pci/netup_unidvb/netup_unidvb_i2c.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/netup_unidvb/netup_unidvb_i2c.c b/drivers/media/pci/netup_unidvb/netup_unidvb_i2c.c
index 46676f2c89c7..1c885d620b75 100644
--- a/drivers/media/pci/netup_unidvb/netup_unidvb_i2c.c
+++ b/drivers/media/pci/netup_unidvb/netup_unidvb_i2c.c
@@ -135,7 +135,7 @@ static void netup_i2c_fifo_tx(struct netup_i2c *i2c)
(readw(&i2c->regs->tx_fifo.stat_ctrl) & 0x3f);
u32 msg_length = i2c->msg->len - i2c->xmit_size;

- msg_length = (msg_length < fifo_space ? msg_length : fifo_space);
+ msg_length = min(msg_length, fifo_space);
while (msg_length--) {
data = i2c->msg->buf[i2c->xmit_size++];
writeb(data, &i2c->regs->tx_fifo.data8);

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:54:17

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 16/26] media: au0828: Use min macro

Simplifies the code.

Found by cocci:
drivers/media/usb/au0828/au0828-video.c:605:11-12: WARNING opportunity for min()

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/usb/au0828/au0828-video.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index fd9fc43d47e0..2ec49ea479d5 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -602,10 +602,7 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
vbi_field_size = dev->vbi_width * dev->vbi_height * 2;
if (dev->vbi_read < vbi_field_size) {
remain = vbi_field_size - dev->vbi_read;
- if (len < remain)
- lencopy = len;
- else
- lencopy = remain;
+ lencopy = umin(len, remain);

if (vbi_buf != NULL)
au0828_copy_vbi(dev, vbi_dma_q, vbi_buf, p,

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:54:48

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 18/26] media: gspca: cpia1: Use min macro

Simplifies the code.

Found by cocci:
drivers/media/usb/gspca/cpia1.c:607:30-31: WARNING opportunity for min()

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/usb/gspca/cpia1.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/gspca/cpia1.c b/drivers/media/usb/gspca/cpia1.c
index 5f5fa851ca64..14aaf36cde6e 100644
--- a/drivers/media/usb/gspca/cpia1.c
+++ b/drivers/media/usb/gspca/cpia1.c
@@ -604,10 +604,8 @@ static int find_over_exposure(int brightness)
MaxAllowableOverExposure = FLICKER_MAX_EXPOSURE - brightness -
FLICKER_BRIGHTNESS_CONSTANT;

- if (MaxAllowableOverExposure < FLICKER_ALLOWABLE_OVER_EXPOSURE)
- OverExposure = MaxAllowableOverExposure;
- else
- OverExposure = FLICKER_ALLOWABLE_OVER_EXPOSURE;
+ OverExposure = min(MaxAllowableOverExposure,
+ FLICKER_ALLOWABLE_OVER_EXPOSURE);

return OverExposure;
}

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:54:49

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 17/26] media: flexcop-usb: Use min macro

Simplifies the code.

Found by cocci:
drivers/media/usb/b2c2/flexcop-usb.c:201:8-9: WARNING opportunity for min()

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/usb/b2c2/flexcop-usb.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/media/usb/b2c2/flexcop-usb.c b/drivers/media/usb/b2c2/flexcop-usb.c
index 790787f0eba8..3ba6a5ed7167 100644
--- a/drivers/media/usb/b2c2/flexcop-usb.c
+++ b/drivers/media/usb/b2c2/flexcop-usb.c
@@ -197,10 +197,7 @@ static int flexcop_usb_memory_req(struct flexcop_usb *fc_usb,
return -EINVAL;
}
for (i = 0; i < len;) {
- pagechunk =
- wMax < bytes_left_to_read_on_page(addr, len) ?
- wMax :
- bytes_left_to_read_on_page(addr, len);
+ pagechunk = min(wMax, bytes_left_to_read_on_page(addr, len));
deb_info("%x\n",
(addr & V8_MEMORY_PAGE_MASK) |
(V8_MEMORY_EXTENDED*extended));

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:56:06

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 22/26] media: tc358746: Use the correct div_ function

fin does not fit in 32 bits in some arches.

Found by cocci:
drivers/media/i2c/tc358746.c:847:2-8: WARNING: do_div() does a 64-by-32 division, please consider using div64_ul instead.

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/i2c/tc358746.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/i2c/tc358746.c b/drivers/media/i2c/tc358746.c
index d676adc4401b..edf79107adc5 100644
--- a/drivers/media/i2c/tc358746.c
+++ b/drivers/media/i2c/tc358746.c
@@ -844,8 +844,7 @@ static unsigned long tc358746_find_pll_settings(struct tc358746 *tc358746,
continue;

tmp = fout * postdiv;
- do_div(tmp, fin);
- mul = tmp;
+ mul = div64_ul(tmp, fin);
if (mul > 511)
continue;


--
2.44.0.769.g3c40516874-goog


2024-04-19 09:56:17

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 21/26] media: i2c: st-mipid02: Use the correct div function

link_freq does not fit in 32 bits.

Found by cocci:
drivers/media/i2c/st-mipid02.c:329:1-7: WARNING: do_div() does a 64-by-32 division, please consider using div64_s64 instead.

Reviewed-by: Benjamin Mugnier <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/i2c/st-mipid02.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
index f250640729ca..93a40bfda1af 100644
--- a/drivers/media/i2c/st-mipid02.c
+++ b/drivers/media/i2c/st-mipid02.c
@@ -326,7 +326,7 @@ static int mipid02_configure_from_rx_speed(struct mipid02_dev *bridge,
}

dev_dbg(&client->dev, "detect link_freq = %lld Hz", link_freq);
- do_div(ui_4, link_freq);
+ ui_4 = div64_s64(ui_4, link_freq);
bridge->r.clk_lane_reg1 |= ui_4 << 2;

return 0;

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:56:25

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 19/26] media: stk1160: Use min macro

Simplifies the code.

Found by cocci:
drivers/media/usb/stk1160/stk1160-video.c:133:12-13: WARNING opportunity for min()
drivers/media/usb/stk1160/stk1160-video.c:176:13-14: WARNING opportunity for min()

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/usb/stk1160/stk1160-video.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/media/usb/stk1160/stk1160-video.c b/drivers/media/usb/stk1160/stk1160-video.c
index 366f0e4a5dc0..0ba0f41fe3f4 100644
--- a/drivers/media/usb/stk1160/stk1160-video.c
+++ b/drivers/media/usb/stk1160/stk1160-video.c
@@ -130,10 +130,7 @@ void stk1160_copy_video(struct stk1160 *dev, u8 *src, int len)
dst += linesdone * bytesperline * 2 + lineoff;

/* Copy the remaining of current line */
- if (remain < (bytesperline - lineoff))
- lencopy = remain;
- else
- lencopy = bytesperline - lineoff;
+ lencopy = min(remain, bytesperline - lineoff);

/*
* Check if we have enough space left in the buffer.
@@ -173,10 +170,7 @@ void stk1160_copy_video(struct stk1160 *dev, u8 *src, int len)
src += lencopy;

/* Copy one line at a time */
- if (remain < bytesperline)
- lencopy = remain;
- else
- lencopy = bytesperline;
+ lencopy = min(remain, bytesperline);

/*
* Check if we have enough space left in the buffer.

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:56:26

by Ricardo Ribalda

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

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.

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-19 09:56:58

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 25/26] media: dvb-frontends: tda10048: Fix integer overflow

state->xtal_hz can be up to 16M, so it can overflow a 32 bit integer
when multiplied by pll_mfactor.

Create a new 64 bit variable to hold the calculations.

Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/dvb-frontends/tda10048.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/media/dvb-frontends/tda10048.c b/drivers/media/dvb-frontends/tda10048.c
index 5d5e4e9e4422..3e725cdcc66b 100644
--- a/drivers/media/dvb-frontends/tda10048.c
+++ b/drivers/media/dvb-frontends/tda10048.c
@@ -410,6 +410,7 @@ static int tda10048_set_if(struct dvb_frontend *fe, u32 bw)
struct tda10048_config *config = &state->config;
int i;
u32 if_freq_khz;
+ u64 sample_freq;

dprintk(1, "%s(bw = %d)\n", __func__, bw);

@@ -451,9 +452,11 @@ static int tda10048_set_if(struct dvb_frontend *fe, u32 bw)
dprintk(1, "- pll_pfactor = %d\n", state->pll_pfactor);

/* Calculate the sample frequency */
- state->sample_freq = state->xtal_hz * (state->pll_mfactor + 45);
- state->sample_freq /= (state->pll_nfactor + 1);
- state->sample_freq /= (state->pll_pfactor + 4);
+ sample_freq = state->xtal_hz;
+ sample_freq *= state->pll_mfactor + 45;
+ do_div(sample_freq, state->pll_nfactor + 1);
+ do_div(sample_freq, state->pll_pfactor + 4);
+ state->sample_freq = sample_freq;
dprintk(1, "- sample_freq = %d\n", state->sample_freq);

/* Update the I/F */

--
2.44.0.769.g3c40516874-goog


2024-04-19 09:57:07

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 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-19 09:59:27

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 24/26] media: venus: venc: Make explicit the range of us_per_frame

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

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.

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/qcom/venus/venc.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c
index 3ec2fb8d9fab..f87e33a34610 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,11 +414,8 @@ static int venc_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 = USEC_PER_SEC / (u32)us_per_frame;
inst->timeperframe = *timeperframe;
- inst->fps = fps;

return 0;
}

--
2.44.0.769.g3c40516874-goog


2024-04-19 10:00:13

by Ricardo Ribalda

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

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-04-19 10:01:47

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH v2 03/26] media: uvcvideo: Refactor iterators

Hi Ricardo,

On Fri, Apr 19, 2024 at 09:47:49AM +0000, Ricardo Ribalda wrote:
> Avoid using the iterators after the list_for_each() constructs.
> This patch should be a NOP, but makes cocci, happier:
>
> drivers/media/usb/uvc/uvc_ctrl.c:1861:44-50: ERROR: invalid reference to the index variable of the iterator on line 1850
> drivers/media/usb/uvc/uvc_ctrl.c:2195:17-23: ERROR: invalid reference to the index variable of the iterator on line 2179
>
> Reviewed-by: Sergey Senozhatsky <[email protected]>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/usb/uvc/uvc_ctrl.c | 24 +++++++++++++-----------
> 1 file changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
> index e59a463c2761..a4a987913430 100644
> --- a/drivers/media/usb/uvc/uvc_ctrl.c
> +++ b/drivers/media/usb/uvc/uvc_ctrl.c
> @@ -1850,16 +1850,18 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback,
> list_for_each_entry(entity, &chain->entities, chain) {

What happened to
https://lore.kernel.org/all/[email protected]/
? :'-(

Reviewed-by: Laurent Pinchart <[email protected]>

> ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback,
> &err_ctrl);
> - if (ret < 0)
> + if (ret < 0) {
> + if (ctrls)
> + ctrls->error_idx =
> + uvc_ctrl_find_ctrl_idx(entity, ctrls,
> + err_ctrl);
> goto done;
> + }
> }
>
> if (!rollback)
> uvc_ctrl_send_events(handle, ctrls->controls, ctrls->count);
> done:
> - if (ret < 0 && ctrls)
> - ctrls->error_idx = uvc_ctrl_find_ctrl_idx(entity, ctrls,
> - err_ctrl);
> mutex_unlock(&chain->ctrl_mutex);
> return ret;
> }
> @@ -2165,7 +2167,7 @@ static int uvc_ctrl_init_xu_ctrl(struct uvc_device *dev,
> int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
> struct uvc_xu_control_query *xqry)
> {
> - struct uvc_entity *entity;
> + struct uvc_entity *entity, *iter;
> struct uvc_control *ctrl;
> unsigned int i;
> bool found;
> @@ -2175,16 +2177,16 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
> int ret;
>
> /* Find the extension unit. */
> - found = false;
> - list_for_each_entry(entity, &chain->entities, chain) {
> - if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT &&
> - entity->id == xqry->unit) {
> - found = true;
> + entity = NULL;
> + list_for_each_entry(iter, &chain->entities, chain) {
> + if (UVC_ENTITY_TYPE(iter) == UVC_VC_EXTENSION_UNIT &&
> + iter->id == xqry->unit) {
> + entity = iter;
> break;
> }
> }
>
> - if (!found) {
> + if (!entity) {
> uvc_dbg(chain->dev, CONTROL, "Extension unit %u not found\n",
> xqry->unit);
> return -ENOENT;

--
Regards,

Laurent Pinchart

2024-04-20 22:47:21

by Bryan O'Donoghue

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

On 19/04/2024 10:48, Ricardo Ribalda wrote:
> 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.
>
> 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;
>

Reviewed-by: Bryan O'Donoghue <[email protected]>

2024-04-20 22:47:57

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 24/26] media: venus: venc: Make explicit the range of us_per_frame

On 19/04/2024 10:48, Ricardo Ribalda wrote:
> Unless the fps is smaller than 0.000232829 fps, this fits in a 32 bit
> number. Make that explicit.
>
> 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.
>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/platform/qcom/venus/venc.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c
> index 3ec2fb8d9fab..f87e33a34610 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,11 +414,8 @@ static int venc_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 = USEC_PER_SEC / (u32)us_per_frame;
> inst->timeperframe = *timeperframe;
> - inst->fps = fps;
>
> return 0;
> }
>

Reviewed-by: Bryan O'Donoghue <[email protected]>

2024-04-20 23:08:15

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 02/26] media: stb0899: Simplify check

On 19/04/2024 10:47, Ricardo Ribalda wrote:
> chip_id is an unsigned number, it can never be < 0
>
> Fixes cocci check:
> drivers/media/dvb-frontends/stb0899_drv.c:1280:8-15: WARNING: Unsigned expression compared with zero: chip_id > 0
>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/dvb-frontends/stb0899_drv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/dvb-frontends/stb0899_drv.c b/drivers/media/dvb-frontends/stb0899_drv.c
> index 2f4d8fb400cd..35634f9a8ab5 100644
> --- a/drivers/media/dvb-frontends/stb0899_drv.c
> +++ b/drivers/media/dvb-frontends/stb0899_drv.c
> @@ -1277,7 +1277,7 @@ static int stb0899_get_dev_id(struct stb0899_state *state)
> dprintk(state->verbose, FE_ERROR, 1, "Demodulator Core ID=[%s], Version=[%d]", (char *) &demod_str, demod_ver);
> CONVERT32(STB0899_READ_S2REG(STB0899_S2FEC, FEC_CORE_ID_REG), (char *)&fec_str);
> fec_ver = STB0899_READ_S2REG(STB0899_S2FEC, FEC_VER_ID_REG);
> - if (! (chip_id > 0)) {
> + if (!chip_id) {
> dprintk(state->verbose, FE_ERROR, 1, "couldn't find a STB 0899");
>
> return -ENODEV;
>

Reviewed-by: Bryan O'Donoghue <[email protected]>

2024-04-20 23:12:10

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 05/26] media: go7007: Use min and max macros

On 19/04/2024 10:47, Ricardo Ribalda wrote:
> It makes the code simpler and cocci happier:
>
> drivers/media/usb/go7007/go7007-fw.c:1292:14-15: WARNING opportunity for max()
> drivers/media/usb/go7007/go7007-fw.c:1293:14-15: WARNING opportunity for min()
>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/usb/go7007/go7007-fw.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/usb/go7007/go7007-fw.c b/drivers/media/usb/go7007/go7007-fw.c
> index 018019ba47d4..86ce593e0c54 100644
> --- a/drivers/media/usb/go7007/go7007-fw.c
> +++ b/drivers/media/usb/go7007/go7007-fw.c
> @@ -1289,8 +1289,8 @@ static int avsync_to_package(struct go7007 *go, __le16 *code, int space)
> 0xbf99, (u16)((-adjratio) >> 16),
> 0xbf92, 0,
> 0xbf93, 0,
> - 0xbff4, f1 > f2 ? f1 : f2,
> - 0xbff5, f1 < f2 ? f1 : f2,
> + 0xbff4, max(f1, f2),
> + 0xbff5, min(f1, f2),
> 0xbff6, f1 < f2 ? ratio : ratio + 1,
> 0xbff7, f1 > f2 ? ratio : ratio + 1,
> 0xbff8, 0,
>

Code is correct, but the commit log could use some expansion.

Suggest:

"Replace ternary inline selection of f1 and f2 min max values with min()
and max() helper functions for the sake of readability and to make
coccinelle happier"

You can take the RB either way though

Reviewed-by: Bryan O'Donoghue <[email protected]>

2024-04-20 23:16:11

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 06/26] media: stm32-dcmipp: Remove redundant printk

On 19/04/2024 10:47, Ricardo Ribalda wrote:
> - if (irq <= 0) {
<snip>
> - return irq ? irq : -ENXIO;
> - }

You're dropping the original intent of the driver author there no ? when
irq == 0 they want to return -ENXIO.

---
bod

2024-04-20 23:23:24

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 09/26] media: v4l: async: refactor v4l2_async_create_ancillary_links

On 19/04/2024 10:47, Ricardo Ribalda wrote:
> Return 0 without checking IS_ERR or PTR_ERR if CONFIG_MEDIA_CONTROLLER
> is not enabled.
>
> This makes cocci happier:
>
> drivers/media/v4l2-core/v4l2-async.c:331:23-30: ERROR: PTR_ERR applied after initialization to constant on line 319
>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/v4l2-core/v4l2-async.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
> index 4bb073587817..915a9f3ea93c 100644
> --- a/drivers/media/v4l2-core/v4l2-async.c
> +++ b/drivers/media/v4l2-core/v4l2-async.c
> @@ -316,9 +316,10 @@ v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);
> static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
> struct v4l2_subdev *sd)
> {
> - struct media_link *link = NULL;
> + struct media_link *link;
>
> -#if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
> + if (!IS_ENABLED(CONFIG_MEDIA_CONTROLLER))
> + return 0;
>
> if (sd->entity.function != MEDIA_ENT_F_LENS &&
> sd->entity.function != MEDIA_ENT_F_FLASH)
> @@ -326,8 +327,6 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
>
> link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
>
> -#endif
> -
> return IS_ERR(link) ? PTR_ERR(link) : 0;
> }
>
>

Reviewed-by: Bryan O'Donoghue <[email protected]>

---
bod

2024-04-21 13:22:04

by Markus Elfring

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

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

Would it be more appropriate to move the word “explicit” to the end
of the summary phrase?

Regards,
Markus

2024-04-21 13:26:51

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH v2 24/26] media: venus: venc: Make explicit the range of us_per_frame

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

Would it be more appropriate to move the word “explicit” to the end
of the summary phrase?

Regards,
Markus

2024-04-21 13:48:35

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2 24/26] media: venus: venc: Make explicit the range of us_per_frame

On Sun, Apr 21, 2024 at 03:25:31PM +0200, Markus Elfring wrote:
> > Unless the fps is smaller than 0.000232829 fps, this fits in a 32 bit number.
> > Make that explicit.
>
> Would it be more appropriate to move the word “explicit” to the end
> of the summary phrase?
>
> Regards,
> Markus
>

Hi,

This is the semi-friendly patch-bot of Greg Kroah-Hartman.

Markus, you seem to have sent a nonsensical or otherwise pointless
review comment to a patch submission on a Linux kernel developer mailing
list. I strongly suggest that you not do this anymore. Please do not
bother developers who are actively working to produce patches and
features with comments that, in the end, are a waste of time.

Patch submitter, please ignore Markus's suggestion; you do not need to
follow it at all. The person/bot/AI that sent it is being ignored by
almost all Linux kernel maintainers for having a persistent pattern of
behavior of producing distracting and pointless commentary, and
inability to adapt to feedback. Please feel free to also ignore emails
from them.

thanks,

greg k-h's patch email bot

2024-04-21 14:08:24

by Markus Elfring

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

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

Would the summary phrase “Make the range of z explicit” be more appropriate?

Regards,
Markus

2024-04-22 06:53:32

by Ricardo Ribalda

[permalink] [raw]
Subject: Re: [PATCH v2 06/26] media: stm32-dcmipp: Remove redundant printk

Hi Bryan

Thanks for your review

On Sun, 21 Apr 2024 at 07:15, Bryan O'Donoghue
<[email protected]> wrote:
>
> On 19/04/2024 10:47, Ricardo Ribalda wrote:
> > - if (irq <= 0) {
> <snip>
> > - return irq ? irq : -ENXIO;
> > - }
>
> You're dropping the original intent of the driver author there no ? when
> irq == 0 they want to return -ENXIO.

platform_get_irq() can never return 0.
https://lore.kernel.org/linux-media/[email protected]/

Let me add that to the commit message.

Thanks!

>
> ---
> bod



--
Ricardo Ribalda

2024-04-24 10:55:43

by Hans Verkuil

[permalink] [raw]
Subject: Re: [PATCH v2 09/26] media: v4l: async: refactor v4l2_async_create_ancillary_links

On 19/04/2024 11:47, Ricardo Ribalda wrote:
> Return 0 without checking IS_ERR or PTR_ERR if CONFIG_MEDIA_CONTROLLER
> is not enabled.
>
> This makes cocci happier:
>
> drivers/media/v4l2-core/v4l2-async.c:331:23-30: ERROR: PTR_ERR applied after initialization to constant on line 319
>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/v4l2-core/v4l2-async.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
> index 4bb073587817..915a9f3ea93c 100644
> --- a/drivers/media/v4l2-core/v4l2-async.c
> +++ b/drivers/media/v4l2-core/v4l2-async.c
> @@ -316,9 +316,10 @@ v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);
> static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
> struct v4l2_subdev *sd)
> {
> - struct media_link *link = NULL;
> + struct media_link *link;
>
> -#if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
> + if (!IS_ENABLED(CONFIG_MEDIA_CONTROLLER))
> + return 0;
>
> if (sd->entity.function != MEDIA_ENT_F_LENS &&
> sd->entity.function != MEDIA_ENT_F_FLASH)
> @@ -326,8 +327,6 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
>
> link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
>
> -#endif
> -
> return IS_ERR(link) ? PTR_ERR(link) : 0;
> }

I think I would prefer:

static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
struct v4l2_subdev *sd)
{
#if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
struct media_link *link;

...

return IS_ERR(link) ? PTR_ERR(link) : 0;
#else
return 0;
#endif
}

Regards,

Hans

2024-04-24 11:05:14

by Hans Verkuil

[permalink] [raw]
Subject: Re: [PATCH v2 16/26] media: au0828: Use min macro

nitpick: subject should say "Use umin macro".

Hans

On 19/04/2024 11:48, Ricardo Ribalda wrote:
> Simplifies the code.
>
> Found by cocci:
> drivers/media/usb/au0828/au0828-video.c:605:11-12: WARNING opportunity for min()
>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/usb/au0828/au0828-video.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
> index fd9fc43d47e0..2ec49ea479d5 100644
> --- a/drivers/media/usb/au0828/au0828-video.c
> +++ b/drivers/media/usb/au0828/au0828-video.c
> @@ -602,10 +602,7 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
> vbi_field_size = dev->vbi_width * dev->vbi_height * 2;
> if (dev->vbi_read < vbi_field_size) {
> remain = vbi_field_size - dev->vbi_read;
> - if (len < remain)
> - lencopy = len;
> - else
> - lencopy = remain;
> + lencopy = umin(len, remain);
>
> if (vbi_buf != NULL)
> au0828_copy_vbi(dev, vbi_dma_q, vbi_buf, p,
>


2024-04-24 11:12:50

by Hans Verkuil

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

On 19/04/2024 11:47, Ricardo Ribalda wrote:
> 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

Other than what others already reported, plus my own two comments, this series
looks good. So likely I can pick up v3 once it is posted.

Regards,

Hans

>
> Signed-off-by: Ricardo Ribalda <[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 min 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 explicit the range of us_per_frame
> media: venus: venc: Make explicit the range of us_per_frame
> media: dvb-frontends: tda10048: Fix integer overflow
> media: dvb-frontends: tda10048: Make explicit the range of z.
>
> 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: 836e2548524d2dfcb5acaf3be78f203b6b4bde6f
> change-id: 20240415-fix-cocci-2df3ef22a6f7
>
> Best regards,


2024-04-24 18:31:08

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH v2 21/26] media: i2c: st-mipid02: Use the correct div function

Hi Ricardo,

On Fri, Apr 19, 2024 at 09:48:07AM +0000, Ricardo Ribalda wrote:
> link_freq does not fit in 32 bits.
>
> Found by cocci:
> drivers/media/i2c/st-mipid02.c:329:1-7: WARNING: do_div() does a 64-by-32 division, please consider using div64_s64 instead.
>
> Reviewed-by: Benjamin Mugnier <[email protected]>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/i2c/st-mipid02.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
> index f250640729ca..93a40bfda1af 100644
> --- a/drivers/media/i2c/st-mipid02.c
> +++ b/drivers/media/i2c/st-mipid02.c
> @@ -326,7 +326,7 @@ static int mipid02_configure_from_rx_speed(struct mipid02_dev *bridge,
> }
>
> dev_dbg(&client->dev, "detect link_freq = %lld Hz", link_freq);
> - do_div(ui_4, link_freq);
> + ui_4 = div64_s64(ui_4, link_freq);

These are positive numbers and ui_4 is unsigned. I'd use div64_u64()
instead. With that,

Reviewed-by: Sakari Ailus <[email protected]>

> bridge->r.clk_lane_reg1 |= ui_4 << 2;
>
> return 0;
>

--
Regards,

Sakari Ailus

2024-04-24 18:48:14

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH v2 09/26] media: v4l: async: refactor v4l2_async_create_ancillary_links

On Wed, Apr 24, 2024 at 06:17:31PM +0000, Sakari Ailus wrote:
> On Wed, Apr 24, 2024 at 12:55:20PM +0200, Hans Verkuil wrote:
> > On 19/04/2024 11:47, Ricardo Ribalda wrote:
> > > Return 0 without checking IS_ERR or PTR_ERR if CONFIG_MEDIA_CONTROLLER
> > > is not enabled.
> > >
> > > This makes cocci happier:
> > >
> > > drivers/media/v4l2-core/v4l2-async.c:331:23-30: ERROR: PTR_ERR applied after initialization to constant on line 319
> > >
> > > Signed-off-by: Ricardo Ribalda <[email protected]>
> > > ---
> > > drivers/media/v4l2-core/v4l2-async.c | 7 +++----
> > > 1 file changed, 3 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
> > > index 4bb073587817..915a9f3ea93c 100644
> > > --- a/drivers/media/v4l2-core/v4l2-async.c
> > > +++ b/drivers/media/v4l2-core/v4l2-async.c
> > > @@ -316,9 +316,10 @@ v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);
> > > static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
> > > struct v4l2_subdev *sd)
> > > {
> > > - struct media_link *link = NULL;
> > > + struct media_link *link;
> > >
> > > -#if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
> > > + if (!IS_ENABLED(CONFIG_MEDIA_CONTROLLER))
> > > + return 0;
> > >
> > > if (sd->entity.function != MEDIA_ENT_F_LENS &&
> > > sd->entity.function != MEDIA_ENT_F_FLASH)
> > > @@ -326,8 +327,6 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
> > >
> > > link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
> > >
> > > -#endif
> > > -
> > > return IS_ERR(link) ? PTR_ERR(link) : 0;
> > > }
> >
> > I think I would prefer:
> >
> > static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
> > struct v4l2_subdev *sd)
> > {
> > #if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
> > struct media_link *link;
> >
> > ...
> >
> > return IS_ERR(link) ? PTR_ERR(link) : 0;
> > #else
> > return 0;
> > #endif
> > }
> >
>
> Me, too.

I actually prefer Ricardo's proposal :-)

--
Regards,

Laurent Pinchart

2024-04-24 22:22:59

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH v2 09/26] media: v4l: async: refactor v4l2_async_create_ancillary_links

Hi Hans,

On Wed, Apr 24, 2024 at 12:55:20PM +0200, Hans Verkuil wrote:
> On 19/04/2024 11:47, Ricardo Ribalda wrote:
> > Return 0 without checking IS_ERR or PTR_ERR if CONFIG_MEDIA_CONTROLLER
> > is not enabled.
> >
> > This makes cocci happier:
> >
> > drivers/media/v4l2-core/v4l2-async.c:331:23-30: ERROR: PTR_ERR applied after initialization to constant on line 319
> >
> > Signed-off-by: Ricardo Ribalda <[email protected]>
> > ---
> > drivers/media/v4l2-core/v4l2-async.c | 7 +++----
> > 1 file changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
> > index 4bb073587817..915a9f3ea93c 100644
> > --- a/drivers/media/v4l2-core/v4l2-async.c
> > +++ b/drivers/media/v4l2-core/v4l2-async.c
> > @@ -316,9 +316,10 @@ v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);
> > static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
> > struct v4l2_subdev *sd)
> > {
> > - struct media_link *link = NULL;
> > + struct media_link *link;
> >
> > -#if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
> > + if (!IS_ENABLED(CONFIG_MEDIA_CONTROLLER))
> > + return 0;
> >
> > if (sd->entity.function != MEDIA_ENT_F_LENS &&
> > sd->entity.function != MEDIA_ENT_F_FLASH)
> > @@ -326,8 +327,6 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
> >
> > link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
> >
> > -#endif
> > -
> > return IS_ERR(link) ? PTR_ERR(link) : 0;
> > }
>
> I think I would prefer:
>
> static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
> struct v4l2_subdev *sd)
> {
> #if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
> struct media_link *link;
>
> ...
>
> return IS_ERR(link) ? PTR_ERR(link) : 0;
> #else
> return 0;
> #endif
> }
>

Me, too.

--
Regards,

Sakari Ailus

2024-04-29 11:05:36

by Ricardo Ribalda

[permalink] [raw]
Subject: Re: [PATCH v2 09/26] media: v4l: async: refactor v4l2_async_create_ancillary_links

Hi Hans

Your proposal is what I sent for v1:
https://lore.kernel.org/linux-media/[email protected]/

I have no strong opinion for any of the two, please feel free to land
whatever version you prefer.


Regards

On Wed, 24 Apr 2024 at 20:46, Laurent Pinchart
<[email protected]> wrote:
>
> On Wed, Apr 24, 2024 at 06:17:31PM +0000, Sakari Ailus wrote:
> > On Wed, Apr 24, 2024 at 12:55:20PM +0200, Hans Verkuil wrote:
> > > On 19/04/2024 11:47, Ricardo Ribalda wrote:
> > > > Return 0 without checking IS_ERR or PTR_ERR if CONFIG_MEDIA_CONTROLLER
> > > > is not enabled.
> > > >
> > > > This makes cocci happier:
> > > >
> > > > drivers/media/v4l2-core/v4l2-async.c:331:23-30: ERROR: PTR_ERR applied after initialization to constant on line 319
> > > >
> > > > Signed-off-by: Ricardo Ribalda <[email protected]>
> > > > ---
> > > > drivers/media/v4l2-core/v4l2-async.c | 7 +++----
> > > > 1 file changed, 3 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
> > > > index 4bb073587817..915a9f3ea93c 100644
> > > > --- a/drivers/media/v4l2-core/v4l2-async.c
> > > > +++ b/drivers/media/v4l2-core/v4l2-async.c
> > > > @@ -316,9 +316,10 @@ v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);
> > > > static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
> > > > struct v4l2_subdev *sd)
> > > > {
> > > > - struct media_link *link = NULL;
> > > > + struct media_link *link;
> > > >
> > > > -#if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
> > > > + if (!IS_ENABLED(CONFIG_MEDIA_CONTROLLER))
> > > > + return 0;
> > > >
> > > > if (sd->entity.function != MEDIA_ENT_F_LENS &&
> > > > sd->entity.function != MEDIA_ENT_F_FLASH)
> > > > @@ -326,8 +327,6 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
> > > >
> > > > link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
> > > >
> > > > -#endif
> > > > -
> > > > return IS_ERR(link) ? PTR_ERR(link) : 0;
> > > > }
> > >
> > > I think I would prefer:
> > >
> > > static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
> > > struct v4l2_subdev *sd)
> > > {
> > > #if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
> > > struct media_link *link;
> > >
> > > ...
> > >
> > > return IS_ERR(link) ? PTR_ERR(link) : 0;
> > > #else
> > > return 0;
> > > #endif
> > > }
> > >
> >
> > Me, too.
>
> I actually prefer Ricardo's proposal :-)
>
> --
> Regards,
>
> Laurent Pinchart



--
Ricardo Ribalda

2024-05-04 08:26:05

by Hans Verkuil

[permalink] [raw]
Subject: Re: [PATCH v2 09/26] media: v4l: async: refactor v4l2_async_create_ancillary_links

On 29/04/2024 12:51, Ricardo Ribalda wrote:
> Hi Hans
>
> Your proposal is what I sent for v1:
> https://lore.kernel.org/linux-media/[email protected]/

I decided to go for the v1. I prefer it, and more importantly, Sakari as
maintainer of this code prefers it as well.

Regards,

Hans

>
> I have no strong opinion for any of the two, please feel free to land
> whatever version you prefer.
>
>
> Regards
>
> On Wed, 24 Apr 2024 at 20:46, Laurent Pinchart
> <[email protected]> wrote:
>>
>> On Wed, Apr 24, 2024 at 06:17:31PM +0000, Sakari Ailus wrote:
>>> On Wed, Apr 24, 2024 at 12:55:20PM +0200, Hans Verkuil wrote:
>>>> On 19/04/2024 11:47, Ricardo Ribalda wrote:
>>>>> Return 0 without checking IS_ERR or PTR_ERR if CONFIG_MEDIA_CONTROLLER
>>>>> is not enabled.
>>>>>
>>>>> This makes cocci happier:
>>>>>
>>>>> drivers/media/v4l2-core/v4l2-async.c:331:23-30: ERROR: PTR_ERR applied after initialization to constant on line 319
>>>>>
>>>>> Signed-off-by: Ricardo Ribalda <[email protected]>
>>>>> ---
>>>>> drivers/media/v4l2-core/v4l2-async.c | 7 +++----
>>>>> 1 file changed, 3 insertions(+), 4 deletions(-)
>>>>>
>>>>> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
>>>>> index 4bb073587817..915a9f3ea93c 100644
>>>>> --- a/drivers/media/v4l2-core/v4l2-async.c
>>>>> +++ b/drivers/media/v4l2-core/v4l2-async.c
>>>>> @@ -316,9 +316,10 @@ v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);
>>>>> static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
>>>>> struct v4l2_subdev *sd)
>>>>> {
>>>>> - struct media_link *link = NULL;
>>>>> + struct media_link *link;
>>>>>
>>>>> -#if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
>>>>> + if (!IS_ENABLED(CONFIG_MEDIA_CONTROLLER))
>>>>> + return 0;
>>>>>
>>>>> if (sd->entity.function != MEDIA_ENT_F_LENS &&
>>>>> sd->entity.function != MEDIA_ENT_F_FLASH)
>>>>> @@ -326,8 +327,6 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
>>>>>
>>>>> link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
>>>>>
>>>>> -#endif
>>>>> -
>>>>> return IS_ERR(link) ? PTR_ERR(link) : 0;
>>>>> }
>>>>
>>>> I think I would prefer:
>>>>
>>>> static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
>>>> struct v4l2_subdev *sd)
>>>> {
>>>> #if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
>>>> struct media_link *link;
>>>>
>>>> ...
>>>>
>>>> return IS_ERR(link) ? PTR_ERR(link) : 0;
>>>> #else
>>>> return 0;
>>>> #endif
>>>> }
>>>>
>>>
>>> Me, too.
>>
>> I actually prefer Ricardo's proposal :-)
>>
>> --
>> Regards,
>>
>> Laurent Pinchart
>
>
>