2024-05-07 16:27:28

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 00/18] media: Fix the last set of coccinelle warnings

With this set we are done with all the cocci warning/errors.

Signed-off-by: Ricardo Ribalda <[email protected]>
---
Changes in v2:
- Fix build error in ppc for siano
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Ricardo Ribalda (18):
media: allegro: nal-hevc: Refactor nal_hevc_sub_layer_hrd_parameters
media: xilinx: Refactor struct xvip_dma
media: dvb-frontend/mxl5xx: Refactor struct MBIN_FILE_T
media: dvb-frontend/mxl5xx: Use flex array for MBIN_SEGMENT_T
media: pci: cx18: Use flex arrays for struct cx18_scb
media: siano: Refactor struct sms_msg_data
media: siano: Remove unused structures
media: siano: Use flex arrays for sms_firmware
media: venus: Remove unused structs
media: venus: Use flex array for hfi_session_release_buffer_pkt
media: venus: Refactor struct hfi_uncompressed_plane_info
media: venus: Refactor struct hfi_session_get_property_pkt
media: venus: Refactor struct hfi_uncompressed_format_supported
media: venus: Refactor hfi_session_empty_buffer_uncompressed_plane0_pkt
media: venus: Refactor hfi_session_empty_buffer_compressed_pkt
media: venus: Refactor hfi_sys_get_property_pkt
media: venus: Refactor hfi_session_fill_buffer_pkt
media: venus: Refactor hfi_buffer_alloc_mode_supported

drivers/media/common/siano/smscoreapi.c | 10 ++---
drivers/media/common/siano/smscoreapi.h | 18 +--------
drivers/media/common/siano/smsdvb-main.c | 4 +-
drivers/media/common/siano/smsendian.c | 8 ++--
drivers/media/dvb-frontends/mxl5xx.c | 2 +-
drivers/media/dvb-frontends/mxl5xx_defs.h | 4 +-
drivers/media/pci/cx18/cx18-scb.h | 2 +-
drivers/media/platform/allegro-dvt/allegro-core.c | 6 +--
drivers/media/platform/allegro-dvt/nal-hevc.c | 11 ++----
drivers/media/platform/allegro-dvt/nal-hevc.h | 6 +--
drivers/media/platform/qcom/venus/hfi_cmds.c | 16 ++++----
drivers/media/platform/qcom/venus/hfi_cmds.h | 46 +++++------------------
drivers/media/platform/qcom/venus/hfi_helper.h | 45 ++--------------------
drivers/media/platform/qcom/venus/hfi_parser.c | 2 +-
drivers/media/platform/qcom/venus/hfi_venus.c | 2 +-
drivers/media/platform/xilinx/xilinx-dma.c | 4 +-
drivers/media/platform/xilinx/xilinx-dma.h | 2 +-
17 files changed, 53 insertions(+), 135 deletions(-)
---
base-commit: e695668af8523b059127dfa8b261c76e7c9cde10
change-id: 20240507-cocci-flexarray-9a807a8e108e

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



2024-05-07 16:27:46

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 01/18] media: allegro: nal-hevc: Refactor nal_hevc_sub_layer_hrd_parameters

Replace all the single elements arrays with the element itself.

Pahole shows the same padding and alignment for x86 and arm in both
situations.

This fixes this cocci warning:
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)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/allegro-dvt/allegro-core.c | 6 +++---
drivers/media/platform/allegro-dvt/nal-hevc.c | 11 +++--------
drivers/media/platform/allegro-dvt/nal-hevc.h | 6 +++---
3 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/media/platform/allegro-dvt/allegro-core.c b/drivers/media/platform/allegro-dvt/allegro-core.c
index da61f9beb6b4..369bd88cc0ae 100644
--- a/drivers/media/platform/allegro-dvt/allegro-core.c
+++ b/drivers/media/platform/allegro-dvt/allegro-core.c
@@ -1852,14 +1852,14 @@ static ssize_t allegro_hevc_write_sps(struct allegro_channel *channel,
hrd->dpb_output_delay_length_minus1 = 30;

hrd->bit_rate_scale = ffs(channel->bitrate_peak) - 6;
- hrd->vcl_hrd[0].bit_rate_value_minus1[0] =
+ hrd->vcl_hrd[0].bit_rate_value_minus1 =
(channel->bitrate_peak >> (6 + hrd->bit_rate_scale)) - 1;

cpb_size = v4l2_ctrl_g_ctrl(channel->mpeg_video_cpb_size) * 1000;
hrd->cpb_size_scale = ffs(cpb_size) - 4;
- hrd->vcl_hrd[0].cpb_size_value_minus1[0] = (cpb_size >> (4 + hrd->cpb_size_scale)) - 1;
+ hrd->vcl_hrd[0].cpb_size_value_minus1 = (cpb_size >> (4 + hrd->cpb_size_scale)) - 1;

- hrd->vcl_hrd[0].cbr_flag[0] = !v4l2_ctrl_g_ctrl(channel->mpeg_video_frame_rc_enable);
+ hrd->vcl_hrd[0].cbr_flag = !v4l2_ctrl_g_ctrl(channel->mpeg_video_frame_rc_enable);

size = nal_hevc_write_sps(&dev->plat_dev->dev, dest, n, sps);

diff --git a/drivers/media/platform/allegro-dvt/nal-hevc.c b/drivers/media/platform/allegro-dvt/nal-hevc.c
index 9cdf2756e0a3..575089522df5 100644
--- a/drivers/media/platform/allegro-dvt/nal-hevc.c
+++ b/drivers/media/platform/allegro-dvt/nal-hevc.c
@@ -210,14 +210,9 @@ static void nal_hevc_rbsp_vps(struct rbsp *rbsp, struct nal_hevc_vps *vps)
static void nal_hevc_rbsp_sub_layer_hrd_parameters(struct rbsp *rbsp,
struct nal_hevc_sub_layer_hrd_parameters *hrd)
{
- unsigned int i;
- unsigned int cpb_cnt = 1;
-
- for (i = 0; i < cpb_cnt; i++) {
- rbsp_uev(rbsp, &hrd->bit_rate_value_minus1[i]);
- rbsp_uev(rbsp, &hrd->cpb_size_value_minus1[i]);
- rbsp_bit(rbsp, &hrd->cbr_flag[i]);
- }
+ rbsp_uev(rbsp, &hrd->bit_rate_value_minus1);
+ rbsp_uev(rbsp, &hrd->cpb_size_value_minus1);
+ rbsp_bit(rbsp, &hrd->cbr_flag);
}

static void nal_hevc_rbsp_hrd_parameters(struct rbsp *rbsp,
diff --git a/drivers/media/platform/allegro-dvt/nal-hevc.h b/drivers/media/platform/allegro-dvt/nal-hevc.h
index eb46f12aae80..afa7a9d7d654 100644
--- a/drivers/media/platform/allegro-dvt/nal-hevc.h
+++ b/drivers/media/platform/allegro-dvt/nal-hevc.h
@@ -97,9 +97,9 @@ struct nal_hevc_vps {
};

struct nal_hevc_sub_layer_hrd_parameters {
- unsigned int bit_rate_value_minus1[1];
- unsigned int cpb_size_value_minus1[1];
- unsigned int cbr_flag[1];
+ unsigned int bit_rate_value_minus1;
+ unsigned int cpb_size_value_minus1;
+ unsigned int cbr_flag;
};

struct nal_hevc_hrd_parameters {

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 16:28:00

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 02/18] media: xilinx: Refactor struct xvip_dma

Replace a single element array with a single field.

The following cocci warning is fixed:
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)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/xilinx/xilinx-dma.c | 4 ++--
drivers/media/platform/xilinx/xilinx-dma.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index a96de5d388a1..a1687b868a44 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -348,8 +348,8 @@ static void xvip_dma_buffer_queue(struct vb2_buffer *vb)
}

dma->xt.frame_size = 1;
- dma->sgl[0].size = dma->format.width * dma->fmtinfo->bpp;
- dma->sgl[0].icg = dma->format.bytesperline - dma->sgl[0].size;
+ dma->sgl.size = dma->format.width * dma->fmtinfo->bpp;
+ dma->sgl.icg = dma->format.bytesperline - dma->sgl.size;
dma->xt.numf = dma->format.height;

desc = dmaengine_prep_interleaved_dma(dma->dma, &dma->xt, flags);
diff --git a/drivers/media/platform/xilinx/xilinx-dma.h b/drivers/media/platform/xilinx/xilinx-dma.h
index 9c6d4c18d1a9..18f77e1a7b39 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.h
+++ b/drivers/media/platform/xilinx/xilinx-dma.h
@@ -97,7 +97,7 @@ struct xvip_dma {
struct dma_chan *dma;
unsigned int align;
struct dma_interleaved_template xt;
- struct data_chunk sgl[1];
+ struct data_chunk sgl;
};

#define to_xvip_dma(vdev) container_of(vdev, struct xvip_dma, video)

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 16:28:29

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 04/18] media: dvb-frontend/mxl5xx: Use flex array for MBIN_SEGMENT_T

Replace the older style one-element array with a flexible array member.
There does not seem to be any allocation for this struct in the code, so
no more code changes are required.

The following cocci warning is fixed:
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)

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

diff --git a/drivers/media/dvb-frontends/mxl5xx_defs.h b/drivers/media/dvb-frontends/mxl5xx_defs.h
index 3c5d75ed8fea..512ec979f96f 100644
--- a/drivers/media/dvb-frontends/mxl5xx_defs.h
+++ b/drivers/media/dvb-frontends/mxl5xx_defs.h
@@ -179,7 +179,7 @@ struct MBIN_SEGMENT_HEADER_T {

struct MBIN_SEGMENT_T {
struct MBIN_SEGMENT_HEADER_T header;
- u8 data[1];
+ u8 data[];
};

enum MXL_CMD_TYPE_E { MXL_CMD_WRITE = 0, MXL_CMD_READ };

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 16:28:59

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 05/18] media: pci: cx18: Use flex arrays for struct cx18_scb

Replace the old-style single element array with a flexible array.
This structure does not seem to be allocated in the code, so there is no
need to change anything else.

The following cocci warning is fixed:
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)

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

diff --git a/drivers/media/pci/cx18/cx18-scb.h b/drivers/media/pci/cx18/cx18-scb.h
index f7105421dd25..841edc0712ab 100644
--- a/drivers/media/pci/cx18/cx18-scb.h
+++ b/drivers/media/pci/cx18/cx18-scb.h
@@ -258,7 +258,7 @@ struct cx18_scb {
struct cx18_mailbox ppu2epu_mb;

struct cx18_mdl_ack cpu_mdl_ack[CX18_MAX_STREAMS][CX18_MAX_MDL_ACKS];
- struct cx18_mdl_ent cpu_mdl[1];
+ struct cx18_mdl_ent cpu_mdl[];
};

void cx18_init_scb(struct cx18 *cx);

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 16:30:36

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 11/18] media: venus: Refactor struct hfi_uncompressed_plane_info

This field is never used, but if we remove it we would change the size
of the struct and can lead to behavior change. Stay on the safe side by
replacing the single element array with a single element field.

This fixes the following cocci warning:
drivers/media/platform/qcom/venus/hfi_helper.h:1003:43-60: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/qcom/venus/hfi_helper.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/qcom/venus/hfi_helper.h b/drivers/media/platform/qcom/venus/hfi_helper.h
index 7c0edef263ae..eb0a4c64b7ef 100644
--- a/drivers/media/platform/qcom/venus/hfi_helper.h
+++ b/drivers/media/platform/qcom/venus/hfi_helper.h
@@ -1000,7 +1000,7 @@ struct hfi_uncompressed_plane_constraints {
struct hfi_uncompressed_plane_info {
u32 format;
u32 num_planes;
- struct hfi_uncompressed_plane_constraints plane_constraints[1];
+ struct hfi_uncompressed_plane_constraints plane_constraints;
};

struct hfi_uncompressed_format_supported {

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 16:31:14

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 12/18] media: venus: Refactor struct hfi_session_get_property_pkt

The struct hfi_session_get_property_pkt is always used to fectch a
single property. Make that explicit in the code and avoid a single
element array at the end of the struct.

This change fixes the following cocci warning:
drivers/media/platform/qcom/venus/hfi_cmds.h:194:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/qcom/venus/hfi_cmds.c | 8 ++++----
drivers/media/platform/qcom/venus/hfi_cmds.h | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.c b/drivers/media/platform/qcom/venus/hfi_cmds.c
index 3418d2dd9371..520ff8a587e6 100644
--- a/drivers/media/platform/qcom/venus/hfi_cmds.c
+++ b/drivers/media/platform/qcom/venus/hfi_cmds.c
@@ -401,8 +401,8 @@ static int pkt_session_get_property_1x(struct hfi_session_get_property_pkt *pkt,
pkt->shdr.hdr.size = sizeof(*pkt);
pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_GET_PROPERTY;
pkt->shdr.session_id = hash32_ptr(cookie);
- pkt->num_properties = 1;
- pkt->data[0] = ptype;
+ pkt->one = 1;
+ pkt->data = ptype;

return 0;
}
@@ -1106,11 +1106,11 @@ pkt_session_get_property_3xx(struct hfi_session_get_property_pkt *pkt,
pkt->shdr.hdr.size = sizeof(struct hfi_session_get_property_pkt);
pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_GET_PROPERTY;
pkt->shdr.session_id = hash32_ptr(cookie);
- pkt->num_properties = 1;
+ pkt->one = 1;

switch (ptype) {
case HFI_PROPERTY_CONFIG_VDEC_ENTROPY:
- pkt->data[0] = HFI_PROPERTY_CONFIG_VDEC_ENTROPY;
+ pkt->data = HFI_PROPERTY_CONFIG_VDEC_ENTROPY;
break;
default:
ret = pkt_session_get_property_1x(pkt, cookie, ptype);
diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.h b/drivers/media/platform/qcom/venus/hfi_cmds.h
index 6dff949c4402..e1dd0ea2be1a 100644
--- a/drivers/media/platform/qcom/venus/hfi_cmds.h
+++ b/drivers/media/platform/qcom/venus/hfi_cmds.h
@@ -190,8 +190,8 @@ struct hfi_session_resume_pkt {

struct hfi_session_get_property_pkt {
struct hfi_session_hdr_pkt shdr;
- u32 num_properties;
- u32 data[1];
+ u32 one;
+ u32 data;
};

struct hfi_session_release_buffer_pkt {

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 16:31:41

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 13/18] media: venus: Refactor struct hfi_uncompressed_format_supported

plane_info is not a typical array, the data is not contiguous:
pinfo = (void *)pinfo + sizeof(*constr) * num_planes +
2 * sizeof(u32);

Replace the single element array with a single element field.

This fixes the following cocci warning:
drivers/media/platform/qcom/venus/hfi_helper.h:1009:36-46: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/qcom/venus/hfi_helper.h | 2 +-
drivers/media/platform/qcom/venus/hfi_parser.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/hfi_helper.h b/drivers/media/platform/qcom/venus/hfi_helper.h
index eb0a4c64b7ef..dee439ea4d2e 100644
--- a/drivers/media/platform/qcom/venus/hfi_helper.h
+++ b/drivers/media/platform/qcom/venus/hfi_helper.h
@@ -1006,7 +1006,7 @@ struct hfi_uncompressed_plane_info {
struct hfi_uncompressed_format_supported {
u32 buffer_type;
u32 format_entries;
- struct hfi_uncompressed_plane_info plane_info[1];
+ struct hfi_uncompressed_plane_info plane_info;
};

struct hfi_uncompressed_plane_actual {
diff --git a/drivers/media/platform/qcom/venus/hfi_parser.c b/drivers/media/platform/qcom/venus/hfi_parser.c
index c43839539d4d..3df241dc3a11 100644
--- a/drivers/media/platform/qcom/venus/hfi_parser.c
+++ b/drivers/media/platform/qcom/venus/hfi_parser.c
@@ -157,7 +157,7 @@ static void
parse_raw_formats(struct venus_core *core, u32 codecs, u32 domain, void *data)
{
struct hfi_uncompressed_format_supported *fmt = data;
- struct hfi_uncompressed_plane_info *pinfo = fmt->plane_info;
+ struct hfi_uncompressed_plane_info *pinfo = &fmt->plane_info;
struct hfi_uncompressed_plane_constraints *constr;
struct raw_formats rawfmts[MAX_FMT_ENTRIES] = {};
u32 entries = fmt->format_entries;

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 16:33:17

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 18/18] media: venus: Refactor hfi_buffer_alloc_mode_supported

Replace the old style single element array at the end of the struct with
a flex array.

The code does not allocate this structure, so the size change should not
be a problem.

This fixes the following cocci warning:
drivers/media/platform/qcom/venus/hfi_helper.h:1233:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/qcom/venus/hfi_helper.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/qcom/venus/hfi_helper.h b/drivers/media/platform/qcom/venus/hfi_helper.h
index dee439ea4d2e..9545c964a428 100644
--- a/drivers/media/platform/qcom/venus/hfi_helper.h
+++ b/drivers/media/platform/qcom/venus/hfi_helper.h
@@ -1230,7 +1230,7 @@ struct hfi_interlace_format_supported {
struct hfi_buffer_alloc_mode_supported {
u32 buffer_type;
u32 num_entries;
- u32 data[1];
+ u32 data[];
};

struct hfi_metadata_pass_through {

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 16:33:43

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 06/18] media: siano: Refactor struct sms_msg_data

Replace a single element array with a single element field.

The endianness conversion code seems to support multiple elements. To
avoid changing behavior a pointer to the single element has been used.

This is safer than moving to a flex array, because in that case the
structure size changes.

This fixes the following cocci warning:
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)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/common/siano/smscoreapi.c | 10 +++++-----
drivers/media/common/siano/smscoreapi.h | 2 +-
drivers/media/common/siano/smsdvb-main.c | 4 ++--
drivers/media/common/siano/smsendian.c | 8 +++++---
4 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/media/common/siano/smscoreapi.c b/drivers/media/common/siano/smscoreapi.c
index 7ebcb10126c9..b6f1eb5dbbdf 100644
--- a/drivers/media/common/siano/smscoreapi.c
+++ b/drivers/media/common/siano/smscoreapi.c
@@ -839,7 +839,7 @@ static int smscore_configure_board(struct smscore_device_t *coredev)
mtu_msg.x_msg_header.msg_flags = 0;
mtu_msg.x_msg_header.msg_type = MSG_SMS_SET_MAX_TX_MSG_LEN_REQ;
mtu_msg.x_msg_header.msg_length = sizeof(mtu_msg);
- mtu_msg.msg_data[0] = board->mtu;
+ mtu_msg.msg_data = board->mtu;

coredev->sendrequest_handler(coredev->context, &mtu_msg,
sizeof(mtu_msg));
@@ -852,7 +852,7 @@ static int smscore_configure_board(struct smscore_device_t *coredev)
SMS_INIT_MSG(&crys_msg.x_msg_header,
MSG_SMS_NEW_CRYSTAL_REQ,
sizeof(crys_msg));
- crys_msg.msg_data[0] = board->crystal;
+ crys_msg.msg_data = board->crystal;

coredev->sendrequest_handler(coredev->context, &crys_msg,
sizeof(crys_msg));
@@ -1306,7 +1306,7 @@ static int smscore_init_device(struct smscore_device_t *coredev, int mode)
msg = (struct sms_msg_data *)SMS_ALIGN_ADDRESS(buffer);
SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_INIT_DEVICE_REQ,
sizeof(struct sms_msg_data));
- msg->msg_data[0] = mode;
+ msg->msg_data = mode;

rc = smscore_sendrequest_and_wait(coredev, msg,
msg->x_msg_header. msg_length,
@@ -1394,7 +1394,7 @@ int smscore_set_device_mode(struct smscore_device_t *coredev, int mode)

SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_INIT_DEVICE_REQ,
sizeof(struct sms_msg_data));
- msg->msg_data[0] = mode;
+ msg->msg_data = mode;

rc = smscore_sendrequest_and_wait(
coredev, msg, msg->x_msg_header.msg_length,
@@ -1554,7 +1554,7 @@ void smscore_onresponse(struct smscore_device_t *coredev,
struct sms_msg_data *validity = (struct sms_msg_data *) phdr;

pr_debug("MSG_SMS_DATA_VALIDITY_RES, checksum = 0x%x\n",
- validity->msg_data[0]);
+ validity->msg_data);
complete(&coredev->data_validity_done);
break;
}
diff --git a/drivers/media/common/siano/smscoreapi.h b/drivers/media/common/siano/smscoreapi.h
index f8789ee0d554..46dc74ac9318 100644
--- a/drivers/media/common/siano/smscoreapi.h
+++ b/drivers/media/common/siano/smscoreapi.h
@@ -616,7 +616,7 @@ struct sms_msg_hdr {

struct sms_msg_data {
struct sms_msg_hdr x_msg_header;
- u32 msg_data[1];
+ u32 msg_data;
};

struct sms_msg_data2 {
diff --git a/drivers/media/common/siano/smsdvb-main.c b/drivers/media/common/siano/smsdvb-main.c
index d893a0e4672b..44d8fe8b220e 100644
--- a/drivers/media/common/siano/smsdvb-main.c
+++ b/drivers/media/common/siano/smsdvb-main.c
@@ -689,7 +689,7 @@ static int smsdvb_start_feed(struct dvb_demux_feed *feed)
pid_msg.x_msg_header.msg_flags = 0;
pid_msg.x_msg_header.msg_type = MSG_SMS_ADD_PID_FILTER_REQ;
pid_msg.x_msg_header.msg_length = sizeof(pid_msg);
- pid_msg.msg_data[0] = feed->pid;
+ pid_msg.msg_data = feed->pid;

return smsclient_sendrequest(client->smsclient,
&pid_msg, sizeof(pid_msg));
@@ -711,7 +711,7 @@ static int smsdvb_stop_feed(struct dvb_demux_feed *feed)
pid_msg.x_msg_header.msg_flags = 0;
pid_msg.x_msg_header.msg_type = MSG_SMS_REMOVE_PID_FILTER_REQ;
pid_msg.x_msg_header.msg_length = sizeof(pid_msg);
- pid_msg.msg_data[0] = feed->pid;
+ pid_msg.msg_data = feed->pid;

return smsclient_sendrequest(client->smsclient,
&pid_msg, sizeof(pid_msg));
diff --git a/drivers/media/common/siano/smsendian.c b/drivers/media/common/siano/smsendian.c
index a3573814919b..b957970c7d97 100644
--- a/drivers/media/common/siano/smsendian.c
+++ b/drivers/media/common/siano/smsendian.c
@@ -20,11 +20,12 @@ void smsendian_handle_tx_message(void *buffer)
struct sms_msg_data *msg = buffer;
int i;
int msg_words;
+ u32 *msg_data = &msg->msg_data;

switch (msg->x_msg_header.msg_type) {
case MSG_SMS_DATA_DOWNLOAD_REQ:
{
- msg->msg_data[0] = le32_to_cpu((__force __le32)(msg->msg_data[0]));
+ msg->msg_data = le32_to_cpu((__force __le32)(msg->msg_data));
break;
}

@@ -33,7 +34,7 @@ void smsendian_handle_tx_message(void *buffer)
sizeof(struct sms_msg_hdr))/4;

for (i = 0; i < msg_words; i++)
- msg->msg_data[i] = le32_to_cpu((__force __le32)msg->msg_data[i]);
+ msg_data[i] = le32_to_cpu((__force __le32)msg_data[i]);

break;
}
@@ -66,11 +67,12 @@ void smsendian_handle_rx_message(void *buffer)

default:
{
+ u32 *msg_data = &msg->msg_data;
msg_words = (msg->x_msg_header.msg_length -
sizeof(struct sms_msg_hdr))/4;

for (i = 0; i < msg_words; i++)
- msg->msg_data[i] = le32_to_cpu((__force __le32)msg->msg_data[i]);
+ msg_data[i] = le32_to_cpu((__force __le32)msg_data[i]);

break;
}

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 16:33:51

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 07/18] media: siano: Remove unused structures

These structs are not used in the code, remove them.

This fixes the following cocci warning:

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)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/common/siano/smscoreapi.h | 14 --------------
1 file changed, 14 deletions(-)

diff --git a/drivers/media/common/siano/smscoreapi.h b/drivers/media/common/siano/smscoreapi.h
index 46dc74ac9318..bc61bc8b9ea9 100644
--- a/drivers/media/common/siano/smscoreapi.h
+++ b/drivers/media/common/siano/smscoreapi.h
@@ -1042,20 +1042,6 @@ struct sms_srvm_signal_status {
u32 request_id;
};

-struct sms_i2c_req {
- u32 device_address; /* I2c device address */
- u32 write_count; /* number of bytes to write */
- u32 read_count; /* number of bytes to read */
- u8 Data[1];
-};
-
-struct sms_i2c_res {
- u32 status; /* non-zero value in case of failure */
- u32 read_count; /* number of bytes read */
- u8 Data[1];
-};
-
-
struct smscore_config_gpio {
#define SMS_GPIO_DIRECTION_INPUT 0
#define SMS_GPIO_DIRECTION_OUTPUT 1

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 16:34:04

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 08/18] media: siano: Use flex arrays for sms_firmware

Replace old style single array member, with flex array.

The struct is allocated, but it seems like there was an over allocation
error:

fw_buf = kmalloc(ALIGN(fw->size + sizeof(struct sms_firmware),
SMS_ALLOC_ALIGNMENT), GFP_KERNEL | coredev->gfp_buf_flags);

This change fixes this cocci warning:
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)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/common/siano/smscoreapi.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/common/siano/smscoreapi.h b/drivers/media/common/siano/smscoreapi.h
index bc61bc8b9ea9..82d9f8a64d99 100644
--- a/drivers/media/common/siano/smscoreapi.h
+++ b/drivers/media/common/siano/smscoreapi.h
@@ -666,7 +666,7 @@ struct sms_firmware {
u32 check_sum;
u32 length;
u32 start_address;
- u8 payload[1];
+ u8 payload[];
};

/* statistics information returned as response for

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 16:34:40

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 09/18] media: venus: Remove unused structs

This structures are not used, and have a single element array at the end
of them. Remove them.

This fix the following cocci warnings:
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: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: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/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: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)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/qcom/venus/hfi_cmds.h | 26 -----------------
drivers/media/platform/qcom/venus/hfi_helper.h | 39 --------------------------
2 files changed, 65 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.h b/drivers/media/platform/qcom/venus/hfi_cmds.h
index 20acd412ee7b..41f765eac4d9 100644
--- a/drivers/media/platform/qcom/venus/hfi_cmds.h
+++ b/drivers/media/platform/qcom/venus/hfi_cmds.h
@@ -77,14 +77,6 @@ struct hfi_sys_get_property_pkt {
u32 data[1];
};

-struct hfi_sys_set_buffers_pkt {
- struct hfi_pkt_hdr hdr;
- u32 buffer_type;
- u32 buffer_size;
- u32 num_buffers;
- u32 buffer_addr[1];
-};
-
struct hfi_sys_ping_pkt {
struct hfi_pkt_hdr hdr;
u32 client_data;
@@ -171,24 +163,6 @@ struct hfi_session_empty_buffer_uncompressed_plane0_pkt {
u32 data[1];
};

-struct hfi_session_empty_buffer_uncompressed_plane1_pkt {
- u32 flags;
- u32 alloc_len;
- u32 filled_len;
- u32 offset;
- u32 packet_buffer2;
- u32 data[1];
-};
-
-struct hfi_session_empty_buffer_uncompressed_plane2_pkt {
- u32 flags;
- u32 alloc_len;
- u32 filled_len;
- u32 offset;
- u32 packet_buffer3;
- u32 data[1];
-};
-
struct hfi_session_fill_buffer_pkt {
struct hfi_session_hdr_pkt shdr;
u32 stream_id;
diff --git a/drivers/media/platform/qcom/venus/hfi_helper.h b/drivers/media/platform/qcom/venus/hfi_helper.h
index e4c05d62cfc7..7c0edef263ae 100644
--- a/drivers/media/platform/qcom/venus/hfi_helper.h
+++ b/drivers/media/platform/qcom/venus/hfi_helper.h
@@ -759,11 +759,6 @@ struct hfi_multi_stream_3x {
u32 enable;
};

-struct hfi_multi_view_format {
- u32 views;
- u32 view_order[1];
-};
-
#define HFI_MULTI_SLICE_OFF 0x1
#define HFI_MULTI_SLICE_BY_MB_COUNT 0x2
#define HFI_MULTI_SLICE_BY_BYTE_COUNT 0x3
@@ -1036,11 +1031,6 @@ struct hfi_codec_supported {
u32 enc_codecs;
};

-struct hfi_properties_supported {
- u32 num_properties;
- u32 properties[1];
-};
-
struct hfi_max_sessions_supported {
u32 max_sessions;
};
@@ -1083,16 +1073,6 @@ struct hfi_resource_ocmem_requirement {
u32 size;
};

-struct hfi_resource_ocmem_requirement_info {
- u32 num_entries;
- struct hfi_resource_ocmem_requirement requirements[1];
-};
-
-struct hfi_property_sys_image_version_info_type {
- u32 string_size;
- u8 str_image_version[1];
-};
-
struct hfi_codec_mask_supported {
u32 codecs;
u32 video_domains;
@@ -1135,15 +1115,6 @@ struct hfi_index_extradata_config {
u32 index_extra_data_id;
};

-struct hfi_extradata_header {
- u32 size;
- u32 version;
- u32 port_index;
- u32 type;
- u32 data_size;
- u8 data[1];
-};
-
struct hfi_batch_info {
u32 input_batch_count;
u32 output_batch_count;
@@ -1234,11 +1205,6 @@ static inline void hfi_bufreq_set_count_min_host(struct hfi_buffer_requirements
req->count_min = val;
};

-struct hfi_data_payload {
- u32 size;
- u8 data[1];
-};
-
struct hfi_enable_picture {
u32 picture_type;
};
@@ -1267,11 +1233,6 @@ struct hfi_buffer_alloc_mode_supported {
u32 data[1];
};

-struct hfi_mb_error_map {
- u32 error_map_size;
- u8 error_map[1];
-};
-
struct hfi_metadata_pass_through {
int enable;
u32 size;

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 16:58:05

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 15/18] media: venus: Refactor hfi_session_empty_buffer_compressed_pkt

The single element array data[1] is never used. Replace it with a
padding field of the same size.

This fixes the following cocci warning:
drivers/media/platform/qcom/venus/hfi_cmds.h:146:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/qcom/venus/hfi_cmds.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.h b/drivers/media/platform/qcom/venus/hfi_cmds.h
index 15271b3f2b49..02e9a073d0c1 100644
--- a/drivers/media/platform/qcom/venus/hfi_cmds.h
+++ b/drivers/media/platform/qcom/venus/hfi_cmds.h
@@ -143,7 +143,7 @@ struct hfi_session_empty_buffer_compressed_pkt {
u32 input_tag;
u32 packet_buffer;
u32 extradata_buffer;
- u32 data[1];
+ u32 padding;
};

struct hfi_session_empty_buffer_uncompressed_plane0_pkt {

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 16:58:07

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 03/18] media: dvb-frontend/mxl5xx: Refactor struct MBIN_FILE_T

Replace a single element array, with a single element field.

The following cocci warning is fixed:
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)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/dvb-frontends/mxl5xx.c | 2 +-
drivers/media/dvb-frontends/mxl5xx_defs.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/mxl5xx.c b/drivers/media/dvb-frontends/mxl5xx.c
index 91e9c378397c..a15c0438b07a 100644
--- a/drivers/media/dvb-frontends/mxl5xx.c
+++ b/drivers/media/dvb-frontends/mxl5xx.c
@@ -893,7 +893,7 @@ static int do_firmware_download(struct mxl *state, u8 *mbin_buffer_ptr,
status = write_register(state, FW_DL_SIGN_ADDR, 0);
if (status)
return status;
- segment_ptr = (struct MBIN_SEGMENT_T *) (&mbin_ptr->data[0]);
+ segment_ptr = (struct MBIN_SEGMENT_T *)(&mbin_ptr->data);
for (index = 0; index < mbin_ptr->header.num_segments; index++) {
if (segment_ptr->header.id != MBIN_SEGMENT_HEADER_ID) {
dev_err(state->i2cdev, "%s: Invalid segment header ID (%c)\n",
diff --git a/drivers/media/dvb-frontends/mxl5xx_defs.h b/drivers/media/dvb-frontends/mxl5xx_defs.h
index 097271f73740..3c5d75ed8fea 100644
--- a/drivers/media/dvb-frontends/mxl5xx_defs.h
+++ b/drivers/media/dvb-frontends/mxl5xx_defs.h
@@ -168,7 +168,7 @@ struct MBIN_FILE_HEADER_T {

struct MBIN_FILE_T {
struct MBIN_FILE_HEADER_T header;
- u8 data[1];
+ u8 data;
};

struct MBIN_SEGMENT_HEADER_T {

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 16:58:17

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 10/18] media: venus: Use flex array for hfi_session_release_buffer_pkt

Replace the old style single element array with a flex array. We do not
allocate this structure, so the size change should not be an issue.

This fixes the following cocci warning:
drivers/media/platform/qcom/venus/hfi_cmds.h:204:5-16: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/qcom/venus/hfi_cmds.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.h b/drivers/media/platform/qcom/venus/hfi_cmds.h
index 41f765eac4d9..6dff949c4402 100644
--- a/drivers/media/platform/qcom/venus/hfi_cmds.h
+++ b/drivers/media/platform/qcom/venus/hfi_cmds.h
@@ -201,7 +201,7 @@ struct hfi_session_release_buffer_pkt {
u32 extradata_size;
u32 response_req;
u32 num_buffers;
- u32 buffer_info[1];
+ u32 buffer_info[];
};

struct hfi_session_release_resources_pkt {

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 17:01:06

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 17/18] media: venus: Refactor hfi_session_fill_buffer_pkt

The single data array data[1] is only used to save the extradata_size.
Replace it with a single element field.

This fixes the following cocci warning:
drivers/media/platform/qcom/venus/hfi_cmds.h:175:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/qcom/venus/hfi_cmds.c | 2 +-
drivers/media/platform/qcom/venus/hfi_cmds.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.c b/drivers/media/platform/qcom/venus/hfi_cmds.c
index c5123f2e76fe..35423e211ddd 100644
--- a/drivers/media/platform/qcom/venus/hfi_cmds.c
+++ b/drivers/media/platform/qcom/venus/hfi_cmds.c
@@ -331,7 +331,7 @@ int pkt_session_ftb(struct hfi_session_fill_buffer_pkt *pkt, void *cookie,
pkt->alloc_len = out_frame->alloc_len;
pkt->filled_len = out_frame->filled_len;
pkt->offset = out_frame->offset;
- pkt->data[0] = out_frame->extradata_size;
+ pkt->extradata_size = out_frame->extradata_size;

return 0;
}
diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.h b/drivers/media/platform/qcom/venus/hfi_cmds.h
index cd7902743f62..0ccc4102ac3d 100644
--- a/drivers/media/platform/qcom/venus/hfi_cmds.h
+++ b/drivers/media/platform/qcom/venus/hfi_cmds.h
@@ -172,7 +172,7 @@ struct hfi_session_fill_buffer_pkt {
u32 output_tag;
u32 packet_buffer;
u32 extradata_buffer;
- u32 data[1];
+ u32 extradata_size;
};

struct hfi_session_flush_pkt {

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 17:01:52

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 16/18] media: venus: Refactor hfi_sys_get_property_pkt

This struct was only used to get the version from the core. Make that
explicit.

This fixes the following cocci warning:
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)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/qcom/venus/hfi_cmds.c | 6 +++---
drivers/media/platform/qcom/venus/hfi_cmds.h | 8 ++++----
drivers/media/platform/qcom/venus/hfi_venus.c | 2 +-
3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.c b/drivers/media/platform/qcom/venus/hfi_cmds.c
index 520ff8a587e6..c5123f2e76fe 100644
--- a/drivers/media/platform/qcom/venus/hfi_cmds.c
+++ b/drivers/media/platform/qcom/venus/hfi_cmds.c
@@ -151,12 +151,12 @@ int pkt_sys_ssr_cmd(struct hfi_sys_test_ssr_pkt *pkt, u32 trigger_type)
return 0;
}

-void pkt_sys_image_version(struct hfi_sys_get_property_pkt *pkt)
+void pkt_sys_image_version(struct hfi_sys_get_version_pkt *pkt)
{
pkt->hdr.size = sizeof(*pkt);
pkt->hdr.pkt_type = HFI_CMD_SYS_GET_PROPERTY;
- pkt->num_properties = 1;
- pkt->data[0] = HFI_PROPERTY_SYS_IMAGE_VERSION;
+ pkt->one = 1;
+ pkt->version = HFI_PROPERTY_SYS_IMAGE_VERSION;
}

int pkt_session_init(struct hfi_session_init_pkt *pkt, void *cookie,
diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.h b/drivers/media/platform/qcom/venus/hfi_cmds.h
index 02e9a073d0c1..cd7902743f62 100644
--- a/drivers/media/platform/qcom/venus/hfi_cmds.h
+++ b/drivers/media/platform/qcom/venus/hfi_cmds.h
@@ -71,10 +71,10 @@ struct hfi_sys_set_property_pkt {
u32 data[];
};

-struct hfi_sys_get_property_pkt {
+struct hfi_sys_get_version_pkt {
struct hfi_pkt_hdr hdr;
- u32 num_properties;
- u32 data[1];
+ u32 one;
+ u32 version;
};

struct hfi_sys_ping_pkt {
@@ -239,7 +239,7 @@ void pkt_sys_debug_config(struct hfi_sys_set_property_pkt *pkt, u32 mode,
u32 config);
void pkt_sys_coverage_config(struct hfi_sys_set_property_pkt *pkt, u32 mode);
void pkt_sys_ping(struct hfi_sys_ping_pkt *pkt, u32 cookie);
-void pkt_sys_image_version(struct hfi_sys_get_property_pkt *pkt);
+void pkt_sys_image_version(struct hfi_sys_get_version_pkt *pkt);
int pkt_sys_ssr_cmd(struct hfi_sys_test_ssr_pkt *pkt, u32 trigger_type);
int pkt_session_init(struct hfi_session_init_pkt *pkt, void *cookie,
u32 session_type, u32 codec);
diff --git a/drivers/media/platform/qcom/venus/hfi_venus.c b/drivers/media/platform/qcom/venus/hfi_venus.c
index f9437b6412b9..745c2c0c0d55 100644
--- a/drivers/media/platform/qcom/venus/hfi_venus.c
+++ b/drivers/media/platform/qcom/venus/hfi_venus.c
@@ -1142,7 +1142,7 @@ static int venus_core_init(struct venus_core *core)
{
struct venus_hfi_device *hdev = to_hfi_priv(core);
struct device *dev = core->dev;
- struct hfi_sys_get_property_pkt version_pkt;
+ struct hfi_sys_get_version_pkt version_pkt;
struct hfi_sys_init_pkt pkt;
int ret;


--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 17:05:15

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 14/18] media: venus: Refactor hfi_session_empty_buffer_uncompressed_plane0_pkt

The single element array data[1] is never used. Replace it whit a
padding field of the same size.

This fixes the following cocci error:
drivers/media/platform/qcom/venus/hfi_cmds.h:163:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/qcom/venus/hfi_cmds.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.h b/drivers/media/platform/qcom/venus/hfi_cmds.h
index e1dd0ea2be1a..15271b3f2b49 100644
--- a/drivers/media/platform/qcom/venus/hfi_cmds.h
+++ b/drivers/media/platform/qcom/venus/hfi_cmds.h
@@ -160,7 +160,7 @@ struct hfi_session_empty_buffer_uncompressed_plane0_pkt {
u32 input_tag;
u32 packet_buffer;
u32 extradata_buffer;
- u32 data[1];
+ u32 padding;
};

struct hfi_session_fill_buffer_pkt {

--
2.45.0.rc1.225.g2a3ae87e7f-goog


2024-05-07 19:34:36

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH v2 02/18] media: xilinx: Refactor struct xvip_dma

Hi Ricardo,

Thank you for the patch.

On Tue, May 07, 2024 at 04:27:07PM +0000, Ricardo Ribalda wrote:
> Replace a single element array with a single field.
>
> The following cocci warning is fixed:
> 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)

This is a false positive, as I really meant ab array with a single
element, this isn't a VLA. I think the current code is a bit clearer,
but I don't think this patch is such a regression in terms of
readability that I'll argue for the driver to remain the last coccinelle
warning :-)

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

> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/platform/xilinx/xilinx-dma.c | 4 ++--
> drivers/media/platform/xilinx/xilinx-dma.h | 2 +-
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
> index a96de5d388a1..a1687b868a44 100644
> --- a/drivers/media/platform/xilinx/xilinx-dma.c
> +++ b/drivers/media/platform/xilinx/xilinx-dma.c
> @@ -348,8 +348,8 @@ static void xvip_dma_buffer_queue(struct vb2_buffer *vb)
> }
>
> dma->xt.frame_size = 1;
> - dma->sgl[0].size = dma->format.width * dma->fmtinfo->bpp;
> - dma->sgl[0].icg = dma->format.bytesperline - dma->sgl[0].size;
> + dma->sgl.size = dma->format.width * dma->fmtinfo->bpp;
> + dma->sgl.icg = dma->format.bytesperline - dma->sgl.size;
> dma->xt.numf = dma->format.height;
>
> desc = dmaengine_prep_interleaved_dma(dma->dma, &dma->xt, flags);
> diff --git a/drivers/media/platform/xilinx/xilinx-dma.h b/drivers/media/platform/xilinx/xilinx-dma.h
> index 9c6d4c18d1a9..18f77e1a7b39 100644
> --- a/drivers/media/platform/xilinx/xilinx-dma.h
> +++ b/drivers/media/platform/xilinx/xilinx-dma.h
> @@ -97,7 +97,7 @@ struct xvip_dma {
> struct dma_chan *dma;
> unsigned int align;
> struct dma_interleaved_template xt;
> - struct data_chunk sgl[1];
> + struct data_chunk sgl;
> };
>
> #define to_xvip_dma(vdev) container_of(vdev, struct xvip_dma, video)

--
Regards,

Laurent Pinchart

2024-05-08 08:54:17

by Michael Tretter

[permalink] [raw]
Subject: Re: [PATCH v2 01/18] media: allegro: nal-hevc: Refactor nal_hevc_sub_layer_hrd_parameters

On Tue, 07 May 2024 16:27:06 +0000, Ricardo Ribalda wrote:
> Replace all the single elements arrays with the element itself.
>
> Pahole shows the same padding and alignment for x86 and arm in both
> situations.
>
> This fixes this cocci warning:
> 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)

Thanks for the patch.

>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/platform/allegro-dvt/allegro-core.c | 6 +++---
> drivers/media/platform/allegro-dvt/nal-hevc.c | 11 +++--------
> drivers/media/platform/allegro-dvt/nal-hevc.h | 6 +++---
> 3 files changed, 9 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/media/platform/allegro-dvt/allegro-core.c b/drivers/media/platform/allegro-dvt/allegro-core.c
> index da61f9beb6b4..369bd88cc0ae 100644
> --- a/drivers/media/platform/allegro-dvt/allegro-core.c
> +++ b/drivers/media/platform/allegro-dvt/allegro-core.c
> @@ -1852,14 +1852,14 @@ static ssize_t allegro_hevc_write_sps(struct allegro_channel *channel,
> hrd->dpb_output_delay_length_minus1 = 30;
>
> hrd->bit_rate_scale = ffs(channel->bitrate_peak) - 6;
> - hrd->vcl_hrd[0].bit_rate_value_minus1[0] =
> + hrd->vcl_hrd[0].bit_rate_value_minus1 =
> (channel->bitrate_peak >> (6 + hrd->bit_rate_scale)) - 1;
>
> cpb_size = v4l2_ctrl_g_ctrl(channel->mpeg_video_cpb_size) * 1000;
> hrd->cpb_size_scale = ffs(cpb_size) - 4;
> - hrd->vcl_hrd[0].cpb_size_value_minus1[0] = (cpb_size >> (4 + hrd->cpb_size_scale)) - 1;
> + hrd->vcl_hrd[0].cpb_size_value_minus1 = (cpb_size >> (4 + hrd->cpb_size_scale)) - 1;
>
> - hrd->vcl_hrd[0].cbr_flag[0] = !v4l2_ctrl_g_ctrl(channel->mpeg_video_frame_rc_enable);
> + hrd->vcl_hrd[0].cbr_flag = !v4l2_ctrl_g_ctrl(channel->mpeg_video_frame_rc_enable);
>
> size = nal_hevc_write_sps(&dev->plat_dev->dev, dest, n, sps);
>
> diff --git a/drivers/media/platform/allegro-dvt/nal-hevc.c b/drivers/media/platform/allegro-dvt/nal-hevc.c
> index 9cdf2756e0a3..575089522df5 100644
> --- a/drivers/media/platform/allegro-dvt/nal-hevc.c
> +++ b/drivers/media/platform/allegro-dvt/nal-hevc.c
> @@ -210,14 +210,9 @@ static void nal_hevc_rbsp_vps(struct rbsp *rbsp, struct nal_hevc_vps *vps)
> static void nal_hevc_rbsp_sub_layer_hrd_parameters(struct rbsp *rbsp,
> struct nal_hevc_sub_layer_hrd_parameters *hrd)
> {
> - unsigned int i;
> - unsigned int cpb_cnt = 1;
> -
> - for (i = 0; i < cpb_cnt; i++) {
> - rbsp_uev(rbsp, &hrd->bit_rate_value_minus1[i]);
> - rbsp_uev(rbsp, &hrd->cpb_size_value_minus1[i]);
> - rbsp_bit(rbsp, &hrd->cbr_flag[i]);
> - }
> + rbsp_uev(rbsp, &hrd->bit_rate_value_minus1);
> + rbsp_uev(rbsp, &hrd->cpb_size_value_minus1);
> + rbsp_bit(rbsp, &hrd->cbr_flag);
> }
>
> static void nal_hevc_rbsp_hrd_parameters(struct rbsp *rbsp,
> diff --git a/drivers/media/platform/allegro-dvt/nal-hevc.h b/drivers/media/platform/allegro-dvt/nal-hevc.h
> index eb46f12aae80..afa7a9d7d654 100644
> --- a/drivers/media/platform/allegro-dvt/nal-hevc.h
> +++ b/drivers/media/platform/allegro-dvt/nal-hevc.h
> @@ -97,9 +97,9 @@ struct nal_hevc_vps {
> };
>
> struct nal_hevc_sub_layer_hrd_parameters {
> - unsigned int bit_rate_value_minus1[1];
> - unsigned int cpb_size_value_minus1[1];
> - unsigned int cbr_flag[1];
> + unsigned int bit_rate_value_minus1;
> + unsigned int cpb_size_value_minus1;
> + unsigned int cbr_flag;

The struct is modeled after the specification in ITU-T H.265, which
defines the fields as arrays. It's a limitation of the current
implementation that only a single element is supported.

Maybe replacing the hard coded values with a constant would be more
appropriate to document this limitation.

Michael

> };
>
> struct nal_hevc_hrd_parameters {
>
> --
> 2.45.0.rc1.225.g2a3ae87e7f-goog
>
>

2024-05-09 18:50:47

by Ricardo Ribalda

[permalink] [raw]
Subject: Re: [PATCH v2 01/18] media: allegro: nal-hevc: Refactor nal_hevc_sub_layer_hrd_parameters

Hi Michael

On Wed, 8 May 2024 at 10:53, Michael Tretter <[email protected]> wrote:
>
> On Tue, 07 May 2024 16:27:06 +0000, Ricardo Ribalda wrote:
> > Replace all the single elements arrays with the element itself.
> >
> > Pahole shows the same padding and alignment for x86 and arm in both
> > situations.
> >
> > This fixes this cocci warning:
> > 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)
>
> Thanks for the patch.
>
> >
> > Signed-off-by: Ricardo Ribalda <[email protected]>
> > ---
> > drivers/media/platform/allegro-dvt/allegro-core.c | 6 +++---
> > drivers/media/platform/allegro-dvt/nal-hevc.c | 11 +++--------
> > drivers/media/platform/allegro-dvt/nal-hevc.h | 6 +++---
> > 3 files changed, 9 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/media/platform/allegro-dvt/allegro-core.c b/drivers/media/platform/allegro-dvt/allegro-core.c
> > index da61f9beb6b4..369bd88cc0ae 100644
> > --- a/drivers/media/platform/allegro-dvt/allegro-core.c
> > +++ b/drivers/media/platform/allegro-dvt/allegro-core.c
> > @@ -1852,14 +1852,14 @@ static ssize_t allegro_hevc_write_sps(struct allegro_channel *channel,
> > hrd->dpb_output_delay_length_minus1 = 30;
> >
> > hrd->bit_rate_scale = ffs(channel->bitrate_peak) - 6;
> > - hrd->vcl_hrd[0].bit_rate_value_minus1[0] =
> > + hrd->vcl_hrd[0].bit_rate_value_minus1 =
> > (channel->bitrate_peak >> (6 + hrd->bit_rate_scale)) - 1;
> >
> > cpb_size = v4l2_ctrl_g_ctrl(channel->mpeg_video_cpb_size) * 1000;
> > hrd->cpb_size_scale = ffs(cpb_size) - 4;
> > - hrd->vcl_hrd[0].cpb_size_value_minus1[0] = (cpb_size >> (4 + hrd->cpb_size_scale)) - 1;
> > + hrd->vcl_hrd[0].cpb_size_value_minus1 = (cpb_size >> (4 + hrd->cpb_size_scale)) - 1;
> >
> > - hrd->vcl_hrd[0].cbr_flag[0] = !v4l2_ctrl_g_ctrl(channel->mpeg_video_frame_rc_enable);
> > + hrd->vcl_hrd[0].cbr_flag = !v4l2_ctrl_g_ctrl(channel->mpeg_video_frame_rc_enable);
> >
> > size = nal_hevc_write_sps(&dev->plat_dev->dev, dest, n, sps);
> >
> > diff --git a/drivers/media/platform/allegro-dvt/nal-hevc.c b/drivers/media/platform/allegro-dvt/nal-hevc.c
> > index 9cdf2756e0a3..575089522df5 100644
> > --- a/drivers/media/platform/allegro-dvt/nal-hevc.c
> > +++ b/drivers/media/platform/allegro-dvt/nal-hevc.c
> > @@ -210,14 +210,9 @@ static void nal_hevc_rbsp_vps(struct rbsp *rbsp, struct nal_hevc_vps *vps)
> > static void nal_hevc_rbsp_sub_layer_hrd_parameters(struct rbsp *rbsp,
> > struct nal_hevc_sub_layer_hrd_parameters *hrd)
> > {
> > - unsigned int i;
> > - unsigned int cpb_cnt = 1;
> > -
> > - for (i = 0; i < cpb_cnt; i++) {
> > - rbsp_uev(rbsp, &hrd->bit_rate_value_minus1[i]);
> > - rbsp_uev(rbsp, &hrd->cpb_size_value_minus1[i]);
> > - rbsp_bit(rbsp, &hrd->cbr_flag[i]);
> > - }
> > + rbsp_uev(rbsp, &hrd->bit_rate_value_minus1);
> > + rbsp_uev(rbsp, &hrd->cpb_size_value_minus1);
> > + rbsp_bit(rbsp, &hrd->cbr_flag);
> > }
> >
> > static void nal_hevc_rbsp_hrd_parameters(struct rbsp *rbsp,
> > diff --git a/drivers/media/platform/allegro-dvt/nal-hevc.h b/drivers/media/platform/allegro-dvt/nal-hevc.h
> > index eb46f12aae80..afa7a9d7d654 100644
> > --- a/drivers/media/platform/allegro-dvt/nal-hevc.h
> > +++ b/drivers/media/platform/allegro-dvt/nal-hevc.h
> > @@ -97,9 +97,9 @@ struct nal_hevc_vps {
> > };
> >
> > struct nal_hevc_sub_layer_hrd_parameters {
> > - unsigned int bit_rate_value_minus1[1];
> > - unsigned int cpb_size_value_minus1[1];
> > - unsigned int cbr_flag[1];
> > + unsigned int bit_rate_value_minus1;
> > + unsigned int cpb_size_value_minus1;
> > + unsigned int cbr_flag;
>
> The struct is modeled after the specification in ITU-T H.265, which
> defines the fields as arrays. It's a limitation of the current
> implementation that only a single element is supported.
>
> Maybe replacing the hard coded values with a constant would be more
> appropriate to document this limitation.

A define seems to convince coccinelle of our intentions :). I will
upload the fix in v3

diff --git a/drivers/media/platform/allegro-dvt/nal-hevc.h
b/drivers/media/platform/allegro-dvt/nal-hevc.h
index eb46f12aae80..361e2f55c254 100644
--- a/drivers/media/platform/allegro-dvt/nal-hevc.h
+++ b/drivers/media/platform/allegro-dvt/nal-hevc.h
@@ -96,10 +96,11 @@ struct nal_hevc_vps {
unsigned int extension_data_flag;
};

+#define N_HRD_PARAMS 1
struct nal_hevc_sub_layer_hrd_parameters {
- unsigned int bit_rate_value_minus1[1];
- unsigned int cpb_size_value_minus1[1];
- unsigned int cbr_flag[1];
+ unsigned int bit_rate_value_minus1[N_HRD_PARAMS];
+ unsigned int cpb_size_value_minus1[N_HRD_PARAMS];
+ unsigned int cbr_flag[N_HRD_PARAMS];
};

struct nal_hevc_hrd_parameters {


Thanks.


>
> Michael
>
> > };
> >
> > struct nal_hevc_hrd_parameters {
> >
> > --
> > 2.45.0.rc1.225.g2a3ae87e7f-goog
> >
> >



--
Ricardo Ribalda

2024-05-09 23:36:23

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 09/18] media: venus: Remove unused structs

On 07/05/2024 17:27, Ricardo Ribalda wrote:
> This structures are not used, and have a single element array at the end
> of them. Remove them.
>
> This fix the following cocci warnings:
> 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: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: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/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: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)
>
> Signed-off-by: Ricardo Ribalda <[email protected]>

There's nothing inherently wrong with defining a protocol upfront in the
form of a structure for future expansion.

These structures are documentary of the host <-> firmware interface and
are of use when implementing new features.

I think these structures should just have the "[1] -> []" conversion
done and be retained instead.

---
bod


2024-05-09 23:37:40

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 10/18] media: venus: Use flex array for hfi_session_release_buffer_pkt

On 07/05/2024 17:27, Ricardo Ribalda wrote:
> Replace the old style single element array with a flex array. We do not
> allocate this structure, so the size change should not be an issue.
>
> This fixes the following cocci warning:
> drivers/media/platform/qcom/venus/hfi_cmds.h:204:5-16: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/platform/qcom/venus/hfi_cmds.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.h b/drivers/media/platform/qcom/venus/hfi_cmds.h
> index 41f765eac4d9..6dff949c4402 100644
> --- a/drivers/media/platform/qcom/venus/hfi_cmds.h
> +++ b/drivers/media/platform/qcom/venus/hfi_cmds.h
> @@ -201,7 +201,7 @@ struct hfi_session_release_buffer_pkt {
> u32 extradata_size;
> u32 response_req;
> u32 num_buffers;
> - u32 buffer_info[1];
> + u32 buffer_info[];
> };
>
> struct hfi_session_release_resources_pkt {
>
Reviewed-by: Bryan O'Donoghue <[email protected]>

2024-05-09 23:38:29

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 11/18] media: venus: Refactor struct hfi_uncompressed_plane_info

On 07/05/2024 17:27, Ricardo Ribalda wrote:
> This field is never used, but if we remove it we would change the size
> of the struct and can lead to behavior change. Stay on the safe side by
> replacing the single element array with a single element field.
>
> This fixes the following cocci warning:
> drivers/media/platform/qcom/venus/hfi_helper.h:1003:43-60: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/platform/qcom/venus/hfi_helper.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/qcom/venus/hfi_helper.h b/drivers/media/platform/qcom/venus/hfi_helper.h
> index 7c0edef263ae..eb0a4c64b7ef 100644
> --- a/drivers/media/platform/qcom/venus/hfi_helper.h
> +++ b/drivers/media/platform/qcom/venus/hfi_helper.h
> @@ -1000,7 +1000,7 @@ struct hfi_uncompressed_plane_constraints {
> struct hfi_uncompressed_plane_info {
> u32 format;
> u32 num_planes;
> - struct hfi_uncompressed_plane_constraints plane_constraints[1];
> + struct hfi_uncompressed_plane_constraints plane_constraints;
> };
>
> struct hfi_uncompressed_format_supported {
>
Reviewed-by: Bryan O'Donoghue <[email protected]>

2024-05-09 23:43:28

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 12/18] media: venus: Refactor struct hfi_session_get_property_pkt

On 07/05/2024 17:27, Ricardo Ribalda wrote:
> - u32 num_properties;
> - u32 data[1];
> + u32 one;
> + u32 data;

The conversion of `data[1]` to plain `data` is fine but, the conversion
of `num_properties` to `one` doesn't fit the naming convention of this
code which uses `num_something` extensively.

Please retain the name `num_properties` for that reason.

Then add.

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

2024-05-09 23:56:34

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 13/18] media: venus: Refactor struct hfi_uncompressed_format_supported

On 07/05/2024 17:27, Ricardo Ribalda wrote:
> plane_info is not a typical array, the data is not contiguous:
> pinfo = (void *)pinfo + sizeof(*constr) * num_planes +
> 2 * sizeof(u32);
>
> Replace the single element array with a single element field.
>
> This fixes the following cocci warning:
> drivers/media/platform/qcom/venus/hfi_helper.h:1009:36-46: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/platform/qcom/venus/hfi_helper.h | 2 +-
> drivers/media/platform/qcom/venus/hfi_parser.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/platform/qcom/venus/hfi_helper.h b/drivers/media/platform/qcom/venus/hfi_helper.h
> index eb0a4c64b7ef..dee439ea4d2e 100644
> --- a/drivers/media/platform/qcom/venus/hfi_helper.h
> +++ b/drivers/media/platform/qcom/venus/hfi_helper.h
> @@ -1006,7 +1006,7 @@ struct hfi_uncompressed_plane_info {
> struct hfi_uncompressed_format_supported {
> u32 buffer_type;
> u32 format_entries;
> - struct hfi_uncompressed_plane_info plane_info[1];
> + struct hfi_uncompressed_plane_info plane_info;
> };
>
> struct hfi_uncompressed_plane_actual {
> diff --git a/drivers/media/platform/qcom/venus/hfi_parser.c b/drivers/media/platform/qcom/venus/hfi_parser.c
> index c43839539d4d..3df241dc3a11 100644
> --- a/drivers/media/platform/qcom/venus/hfi_parser.c
> +++ b/drivers/media/platform/qcom/venus/hfi_parser.c
> @@ -157,7 +157,7 @@ static void
> parse_raw_formats(struct venus_core *core, u32 codecs, u32 domain, void *data)
> {
> struct hfi_uncompressed_format_supported *fmt = data;
> - struct hfi_uncompressed_plane_info *pinfo = fmt->plane_info;
> + struct hfi_uncompressed_plane_info *pinfo = &fmt->plane_info;
> struct hfi_uncompressed_plane_constraints *constr;
> struct raw_formats rawfmts[MAX_FMT_ENTRIES] = {};
> u32 entries = fmt->format_entries;
>
Reviewed-by: Bryan O'Donoghue <[email protected]>

2024-05-09 23:57:14

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 09/18] media: venus: Remove unused structs

On 10/05/2024 00:35, Bryan O'Donoghue wrote:
> I think these structures should just have the "[1] -> []" conversion
> done and be retained instead.

They won't have the same sizeof() then so ignore that thought.

I still would suggest dropping the `something[1]` in favour of
`something` because these structures document the protocol between host
and firmware and therefore are useful even if unused in the code.

---
bod

2024-05-09 23:58:44

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 14/18] media: venus: Refactor hfi_session_empty_buffer_uncompressed_plane0_pkt

On 07/05/2024 17:27, Ricardo Ribalda wrote:
> The single element array data[1] is never used. Replace it whit a
> padding field of the same size.
>
> This fixes the following cocci error:
> drivers/media/platform/qcom/venus/hfi_cmds.h:163:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/platform/qcom/venus/hfi_cmds.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.h b/drivers/media/platform/qcom/venus/hfi_cmds.h
> index e1dd0ea2be1a..15271b3f2b49 100644
> --- a/drivers/media/platform/qcom/venus/hfi_cmds.h
> +++ b/drivers/media/platform/qcom/venus/hfi_cmds.h
> @@ -160,7 +160,7 @@ struct hfi_session_empty_buffer_uncompressed_plane0_pkt {
> u32 input_tag;
> u32 packet_buffer;
> u32 extradata_buffer;
> - u32 data[1];
> + u32 padding;
> };
>
> struct hfi_session_fill_buffer_pkt {
>

Its not padding - which is what we mean when we want to align something
to a boundary - its data that we don't currently use.

Please retain the namespace and do data[1] -> data.

Once done.

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

2024-05-10 00:05:27

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 16/18] media: venus: Refactor hfi_sys_get_property_pkt

On 07/05/2024 17:27, Ricardo Ribalda wrote:
> -struct hfi_sys_get_property_pkt {
> +struct hfi_sys_get_version_pkt {
> struct hfi_pkt_hdr hdr;
> - u32 num_properties;

Disagree with the structure name change - the structure describes the
packet which in this case is a get property packet. The data field
identifies the packet to the firmware.

If I were to end up reading kernel code and firmware code it is easier
on the programmer to match both ends of the protocol with a common
namespace.

Please retain the name of the packet `hfi_sys_get_property_pkt` and the
existing `num_countsathing` in this driver keeping `num_properites`

---
bod

2024-05-10 00:08:12

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 17/18] media: venus: Refactor hfi_session_fill_buffer_pkt

On 07/05/2024 17:27, Ricardo Ribalda wrote:
> - u32 data[1];
> + u32 extradata_size;

A correct functional change but again please keep the name to `data` not
`extradata_size`

Then add

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

---
bod

2024-05-10 00:10:01

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 18/18] media: venus: Refactor hfi_buffer_alloc_mode_supported

On 07/05/2024 17:27, Ricardo Ribalda wrote:
> Replace the old style single element array at the end of the struct with
> a flex array.
>
> The code does not allocate this structure, so the size change should not
> be a problem.
>
> This fixes the following cocci warning:
> drivers/media/platform/qcom/venus/hfi_helper.h:1233:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/platform/qcom/venus/hfi_helper.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/qcom/venus/hfi_helper.h b/drivers/media/platform/qcom/venus/hfi_helper.h
> index dee439ea4d2e..9545c964a428 100644
> --- a/drivers/media/platform/qcom/venus/hfi_helper.h
> +++ b/drivers/media/platform/qcom/venus/hfi_helper.h
> @@ -1230,7 +1230,7 @@ struct hfi_interlace_format_supported {
> struct hfi_buffer_alloc_mode_supported {
> u32 buffer_type;
> u32 num_entries;
> - u32 data[1];
> + u32 data[];
> };
>
> struct hfi_metadata_pass_through {
>

You have some fairly inconsistent fixes for this class.

Please don't change the sizeof() any structures in your series, because
the structure is unallocated changing the size is potentially insidious IMO.

data[1] -> data is perfectly fine in this case.

---
bod

2024-05-10 00:23:27

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 10/18] media: venus: Use flex array for hfi_session_release_buffer_pkt

On 10/05/2024 00:37, Bryan O'Donoghue wrote:
>> -    u32 buffer_info[1];
>> +    u32 buffer_info[];
>>   };
>>   struct hfi_session_release_resources_pkt {
>>
> Reviewed-by: Bryan O'Donoghue <[email protected]>

Oops no.

Please don't change the size of the structure.

u32 buffer_info;

---
bod

2024-05-10 01:17:04

by Bryan O'Donoghue

[permalink] [raw]
Subject: Re: [PATCH v2 15/18] media: venus: Refactor hfi_session_empty_buffer_compressed_pkt

On 07/05/2024 17:27, Ricardo Ribalda wrote:
> The single element array data[1] is never used. Replace it with a
> padding field of the same size.
>
> This fixes the following cocci warning:
> drivers/media/platform/qcom/venus/hfi_cmds.h:146:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/platform/qcom/venus/hfi_cmds.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.h b/drivers/media/platform/qcom/venus/hfi_cmds.h
> index 15271b3f2b49..02e9a073d0c1 100644
> --- a/drivers/media/platform/qcom/venus/hfi_cmds.h
> +++ b/drivers/media/platform/qcom/venus/hfi_cmds.h
> @@ -143,7 +143,7 @@ struct hfi_session_empty_buffer_compressed_pkt {
> u32 input_tag;
> u32 packet_buffer;
> u32 extradata_buffer;
> - u32 data[1];
> + u32 padding;
> };
>
> struct hfi_session_empty_buffer_uncompressed_plane0_pkt {
>

Same comment as previous patch.

`data` is what we use in this driver's namespace not padding and the
protocol structures enumerate the content of the payload as data not
padding.

u32 data;

Then

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

---
bod

2024-05-22 12:28:50

by Ricardo Ribalda

[permalink] [raw]
Subject: Re: [PATCH v2 09/18] media: venus: Remove unused structs

Hi Bryan

Thanks for your review

On Fri, 10 May 2024 at 01:56, Bryan O'Donoghue
<[email protected]> wrote:
>
> On 10/05/2024 00:35, Bryan O'Donoghue wrote:
> > I think these structures should just have the "[1] -> []" conversion
> > done and be retained instead.
>
> They won't have the same sizeof() then so ignore that thought.
>
> I still would suggest dropping the `something[1]` in favour of
> `something` because these structures document the protocol between host
> and firmware and therefore are useful even if unused in the code.

The structures will be in the git log for the rest of the days. So if
someone has to use them, they can recover them from there.

Right now, they are not used and they are triggering a warning. I
would argue that untested code is broken code.

I'd rather remove the code.


>
> ---
> bod



--
Ricardo Ribalda

2024-05-22 12:55:15

by Ricardo Ribalda

[permalink] [raw]
Subject: Re: [PATCH v2 10/18] media: venus: Use flex array for hfi_session_release_buffer_pkt

Hi Bryan


On Fri, 10 May 2024 at 02:10, Bryan O'Donoghue
<[email protected]> wrote:
>
> On 10/05/2024 00:37, Bryan O'Donoghue wrote:
> >> - u32 buffer_info[1];
> >> + u32 buffer_info[];
> >> };
> >> struct hfi_session_release_resources_pkt {
> >>
> > Reviewed-by: Bryan O'Donoghue <[email protected]>
>
> Oops no.
>
> Please don't change the size of the structure.

In this case buffer_info[] is a real flexible array, so there is not
much we can do.

The driver seems to only uses the structure to address memory. It is
not allocating the structure or doing any calculations based on its
size, so it should be fine (famous last words).

If anyone has access to the hardware it would be great if they tested it :)

>
> u32 buffer_info;
>
> ---
> bod



--
Ricardo Ribalda

2024-05-22 13:04:22

by Ricardo Ribalda

[permalink] [raw]
Subject: Re: [PATCH v2 18/18] media: venus: Refactor hfi_buffer_alloc_mode_supported

Hi Bryan

On Fri, 10 May 2024 at 02:09, Bryan O'Donoghue
<[email protected]> wrote:
>
> On 07/05/2024 17:27, Ricardo Ribalda wrote:
> > Replace the old style single element array at the end of the struct with
> > a flex array.
> >
> > The code does not allocate this structure, so the size change should not
> > be a problem.
> >
> > This fixes the following cocci warning:
> > drivers/media/platform/qcom/venus/hfi_helper.h:1233:5-9: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
> >
> > Signed-off-by: Ricardo Ribalda <[email protected]>
> > ---
> > drivers/media/platform/qcom/venus/hfi_helper.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/media/platform/qcom/venus/hfi_helper.h b/drivers/media/platform/qcom/venus/hfi_helper.h
> > index dee439ea4d2e..9545c964a428 100644
> > --- a/drivers/media/platform/qcom/venus/hfi_helper.h
> > +++ b/drivers/media/platform/qcom/venus/hfi_helper.h
> > @@ -1230,7 +1230,7 @@ struct hfi_interlace_format_supported {
> > struct hfi_buffer_alloc_mode_supported {
> > u32 buffer_type;
> > u32 num_entries;
> > - u32 data[1];
> > + u32 data[];
> > };
> >
> > struct hfi_metadata_pass_through {
> >
>
> You have some fairly inconsistent fixes for this class.
>
> Please don't change the sizeof() any structures in your series, because
> the structure is unallocated changing the size is potentially insidious IMO.

If the array is a flex array we should convert it to a real flex
array. Abusing one element arrays is deprecated.

If the driver only accesses the first element of the array, I have
modified the code from data[1] to data, because, as you say, modifying
the struct size can have dangerous side effects.

But if the driver accesses more fields, then I have reviewed that
there are no allocations, or any calculations based on the structure
side, and convert them to a proper flex array.


Regards!
>
> data[1] -> data is perfectly fine in this case.

If you take a look at parse_alloc_mode() you will see that mode->data
is indeed an array, and it is used by the pointer type.

>
> ---
> bod



--
Ricardo Ribalda