Skip to contentSkip to conversation

media: Fix the last set of coccinelle warnings

PATCH Superseded Ricardo Ribalda 3 participants 14 messages Jun 18, 2024 – Aug 12, 2024

Subsystems (4)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover media: Fix the last set of coccinelle warnings

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

---
Changes in v5: Thanks Vikash
- Remove patches already merged
- Fix typos and remove hfi_resource_ocmem_requirement
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Remove patches already merged
- Combine dvb-frontend/mxl5xx patches and use flex on both (Thanks Hans)
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Do not rename structure fields. (Thanks Bryan)
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- allegro: Replace hard coded 1 with a define. (Thanks Michael)
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Ricardo Ribalda (10):
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/platform/qcom/venus/hfi_cmds.c   |  8 ++--
 drivers/media/platform/qcom/venus/hfi_cmds.h   | 38 +++----------------
 drivers/media/platform/qcom/venus/hfi_helper.h | 52 ++------------------------
 drivers/media/platform/qcom/venus/hfi_parser.c |  2 +-
 4 files changed, 14 insertions(+), 86 deletions(-)

---
base-commit: 24147897507cd3a7d63745d1518a638bf4132238
change-id: 20240507-cocci-flexarray-9a807a8e108e

Best regards,

Signature · 1 line
Ricardo Ribalda <[email protected]>
#1 lore raw

PATCH v5 1/10 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)

---
 drivers/media/platform/qcom/venus/hfi_cmds.h   | 26 ---------------
 drivers/media/platform/qcom/venus/hfi_helper.h | 46 --------------------------
 2 files changed, 72 deletions(-)
drivers/media/platform/qcom/venus/hfi_cmds.h +0 -26
index 20acd412ee7b..41f765eac4d9 100644
@@ -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;
drivers/media/platform/qcom/venus/hfi_helper.h +0 -46

82 lines not on this page · raw message

Signature · 1 line
2.45.2.627.g7a2c4fd464-goog
#2 lore raw

Re: [PATCH v5 01/10] media: venus: Remove unused structs

Quoted 15 lines · Ricardo Ribalda

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)

Quoted 1 line

I realise I'm going against the grain saying this but, I believe these structures - which document host <-> firmware data packets - the ABI - should be retained in the header, even if they are unused, since they are documentary and potentially of future use.

I'd rather fix the WARNING than zap the structure.

---
bod

#3 lore raw

PATCH v5 2/10 media: venus: Use flex array for hfi_session_release_buffer_pkt

In reply to Ricardo Ribalda

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)

---
 drivers/media/platform/qcom/venus/hfi_cmds.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/qcom/venus/hfi_cmds.h +1 -1
index 41f765eac4d9..6dff949c4402 100644
@@ -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 {
Signature · 1 line
2.45.2.627.g7a2c4fd464-goog
#4 lore raw

PATCH v5 3/10 media: venus: Refactor struct hfi_uncompressed_plane_info

In reply to Ricardo Ribalda

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)

---
 drivers/media/platform/qcom/venus/hfi_helper.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/qcom/venus/hfi_helper.h +1 -1
index f61295819cc1..c53e2fb2d42c 100644
@@ -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 {
Signature · 1 line
2.45.2.627.g7a2c4fd464-goog
#5 lore raw

PATCH v5 4/10 media: venus: Refactor struct hfi_session_get_property_pkt

In reply to Ricardo Ribalda

The struct hfi_session_get_property_pkt is always used to fetch 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)

---
 drivers/media/platform/qcom/venus/hfi_cmds.c | 4 ++--
 drivers/media/platform/qcom/venus/hfi_cmds.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/media/platform/qcom/venus/hfi_cmds.c +2 -2
index 3418d2dd9371..75f4a3d3e748 100644
@@ -402,7 +402,7 @@ static int pkt_session_get_property_1x(struct hfi_session_get_property_pkt *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->data = ptype;
 
 	return 0;
 }
@@ -1110,7 +1110,7 @@ pkt_session_get_property_3xx(struct hfi_session_get_property_pkt *pkt,
 
 	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);
drivers/media/platform/qcom/venus/hfi_cmds.h +1 -1
index 6dff949c4402..f5708fdfb197 100644
@@ -191,7 +191,7 @@ struct hfi_session_resume_pkt {
 struct hfi_session_get_property_pkt {
 	struct hfi_session_hdr_pkt shdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data;
 };
 
 struct hfi_session_release_buffer_pkt {
Signature · 1 line
2.45.2.627.g7a2c4fd464-goog
#6 lore raw

PATCH v5 5/10 media: venus: Refactor struct hfi_uncompressed_format_supported

In reply to Ricardo Ribalda

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)

---
 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(-)
drivers/media/platform/qcom/venus/hfi_helper.h +1 -1
index c53e2fb2d42c..6202dcfc467a 100644
@@ -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 {
drivers/media/platform/qcom/venus/hfi_parser.c +1 -1
index c43839539d4d..3df241dc3a11 100644
@@ -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;
Signature · 1 line
2.45.2.627.g7a2c4fd464-goog
#7 lore raw

PATCH v5 6/10 media: venus: Refactor hfi_session_empty_buffer_uncompressed_plane0_pkt

In reply to Ricardo Ribalda

The single element array data[1] is never used. Replace it with 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)

---
 drivers/media/platform/qcom/venus/hfi_cmds.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/qcom/venus/hfi_cmds.h +1 -1
index f5708fdfb197..8768ee052adc 100644
@@ -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 data;
 };
 
 struct hfi_session_fill_buffer_pkt {
Signature · 1 line
2.45.2.627.g7a2c4fd464-goog
#8 lore raw

PATCH v5 7/10 media: venus: Refactor hfi_session_empty_buffer_compressed_pkt

In reply to Ricardo Ribalda

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)

---
 drivers/media/platform/qcom/venus/hfi_cmds.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/qcom/venus/hfi_cmds.h +1 -1
index 8768ee052adc..2c56ae303989 100644
@@ -143,7 +143,7 @@ struct hfi_session_empty_buffer_compressed_pkt {
 	u32 input_tag;
 	u32 packet_buffer;
 	u32 extradata_buffer;
-	u32 data[1];
+	u32 data;
 };
 
 struct hfi_session_empty_buffer_uncompressed_plane0_pkt {
Signature · 1 line
2.45.2.627.g7a2c4fd464-goog
#9 lore raw

PATCH v5 8/10 media: venus: Refactor hfi_sys_get_property_pkt

In reply to Ricardo Ribalda

Replace a single length element array with an element.

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)

---
 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(-)
drivers/media/platform/qcom/venus/hfi_cmds.c +1 -1
index 75f4a3d3e748..0a4de8ca1df5 100644
@@ -156,7 +156,7 @@ void pkt_sys_image_version(struct hfi_sys_get_property_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->data = HFI_PROPERTY_SYS_IMAGE_VERSION;
 }
 
 int pkt_session_init(struct hfi_session_init_pkt *pkt, void *cookie,
drivers/media/platform/qcom/venus/hfi_cmds.h +1 -1
index 2c56ae303989..f91bc9087643 100644
@@ -74,7 +74,7 @@ struct hfi_sys_set_property_pkt {
 struct hfi_sys_get_property_pkt {
 	struct hfi_pkt_hdr hdr;
 	u32 num_properties;
-	u32 data[1];
+	u32 data;
 };
 
 struct hfi_sys_ping_pkt {
Signature · 1 line
2.45.2.627.g7a2c4fd464-goog
#10 lore raw

PATCH v5 9/10 media: venus: Refactor hfi_session_fill_buffer_pkt

In reply to Ricardo Ribalda

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)

---
 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(-)
drivers/media/platform/qcom/venus/hfi_cmds.c +1 -1
index 0a4de8ca1df5..3ae063094e3e 100644
@@ -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->data = out_frame->extradata_size;
 
 	return 0;
 }
drivers/media/platform/qcom/venus/hfi_cmds.h +1 -1
index f91bc9087643..daba45720ddc 100644
@@ -172,7 +172,7 @@ struct hfi_session_fill_buffer_pkt {
 	u32 output_tag;
 	u32 packet_buffer;
 	u32 extradata_buffer;
-	u32 data[1];
+	u32 data;
 };
 
 struct hfi_session_flush_pkt {
Signature · 1 line
2.45.2.627.g7a2c4fd464-goog
#11 lore raw

PATCH v5 10/10 media: venus: Refactor hfi_buffer_alloc_mode_supported

In reply to Ricardo Ribalda

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)

---
 drivers/media/platform/qcom/venus/hfi_helper.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/qcom/venus/hfi_helper.h +1 -1
index 6202dcfc467a..242a3ba94555 100644
@@ -1223,7 +1223,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 {
Signature · 1 line
2.45.2.627.g7a2c4fd464-goog
#12 lore raw
In reply to Ricardo Ribalda
Quoted 9 lines · Ricardo Ribalda

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

---
Changes in v5: Thanks Vikash
- Remove patches already merged
- Fix typos and remove hfi_resource_ocmem_requirement
- Link to v4: https://lore.kernel.org/r/[email protected]

Just for the clarfification: does the driver build without errors if only a part of the patchset is applied? I have the feeling that first patches introduce a build error which is fixed in a later patch. If that's the case, it's a no-go.

Signature · 2 lines
With best wishes
Dmitry
#13 lore raw

Hi

Quoted 12 lines · Dmitry Baryshkov
Quoted 9 lines · Ricardo Ribalda

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

---
Changes in v5: Thanks Vikash
- Remove patches already merged
- Fix typos and remove hfi_resource_ocmem_requirement
- Link to v4: https://lore.kernel.org/r/[email protected]

Quoted 4 lines

Just for the clarfification: does the driver build without errors if only a part of the patchset is applied? I have the feeling that first patches introduce a build error which is fixed in a later patch. If that's the case, it's a no-go.

I believe it should build without errors for every patch: It has passed the bisectability test

https://gitlab.freedesktop.org/linux-media/users/ribalda/-/jobs/62071294

Quoted 4 lines

--
With best wishes
Dmitry

--
Ricardo Ribalda