Skip to contentSkip to conversation

drm/i915/gt: Replace zero-length array with flexible-array

PATCH New Gustavo A. R. Silva 2 participants 3 messages May 7, 2020 – May 8, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915/gt: Replace zero-length array with flexible-array

The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99:

struct foo {
        int stuff;
        struct boo array[];
};

By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on.

Also, notice that, dynamic memory allocations won't be affected by this change:

"Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1]

sizeof(flexible-array-member) triggers a warning because flexible array members have incomplete type[1]. There are some instances of code in which the sizeof operator is being incorrectly/erroneously applied to zero-length arrays and the result is zero. Such instances may be hiding some bugs. So, this work (flexible-array member conversions) will also help to get completely rid of those sorts of issues.

This issue was found with the help of Coccinelle.

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://github.com/KSPP/linux/issues/21
[3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")

---
 drivers/gpu/drm/i915/display/intel_vbt_defs.h |    4 ++--
 drivers/gpu/drm/i915/gt/intel_lrc.c           |    2 +-
 drivers/gpu/drm/i915/i915_gpu_error.h         |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/display/intel_vbt_defs.h +2 -2
index 05c7cbe32eb4..aef7fe932d1a 100644
@@ -462,7 +462,7 @@ struct bdb_general_definitions {
 	 * number = (block_size - sizeof(bdb_general_definitions))/
 	 *	     defs->child_dev_size;
 	 */
-	u8 devices[0];
+	u8 devices[];
 } __packed;
 
 /*
@@ -839,7 +839,7 @@ struct bdb_mipi_config {
 
 struct bdb_mipi_sequence {
 	u8 version;
-	u8 data[0]; /* up to 6 variable length blocks */
+	u8 data[]; /* up to 6 variable length blocks */
 } __packed;
 
 /*
drivers/gpu/drm/i915/gt/intel_lrc.c +1 -1
index 683014e7bc51..f42c99da2580 100644
@@ -216,7 +216,7 @@ struct virtual_engine {
 
 	/* And finally, which physical engines this virtual engine maps onto. */
 	unsigned int num_siblings;
-	struct intel_engine_cs *siblings[0];
+	struct intel_engine_cs *siblings[];
 };
 
 static struct virtual_engine *to_virtual_engine(struct intel_engine_cs *engine)
drivers/gpu/drm/i915/i915_gpu_error.h +1 -1
index 0d1f6c8ff355..5a6561f7a210 100644
@@ -42,7 +42,7 @@ struct i915_vma_coredump {
 	int num_pages;
 	int page_count;
 	int unused;
-	u32 *pages[0];
+	u32 *pages[];
 };
 
 struct i915_request_coredump {
#1 lore raw

[Intel-gfx] ✓ Fi.CI.BAT: success for drm/i915/gt: Replace zero-length array with flexible-array

== Series Details ==

== Series Details ==

Series: drm/i915/gt: Replace zero-length array with flexible-array
URL : https://patchwork.freedesktop.org/series/77080/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_8453 -> Patchwork_17612
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/index.html

Known issues
------------

Here are the changes found in Patchwork_17612 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@i915_selftest@live@gt_timelines:
- fi-bwr-2160: [PASS][1] -> [INCOMPLETE][2] ([i915#489])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/fi-bwr-2160/igt@i915_selftest@live@gt_timelines.html
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/fi-bwr-2160/igt@i915_selftest@live@gt_timelines.html

[i915#489]: https://gitlab.freedesktop.org/drm/intel/issues/489

Participating hosts (48 -> 41)
------------------------------

Additional (1): fi-kbl-7560u
Missing (8): fi-kbl-soraka fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-apl-guc fi-byt-clapper fi-bdw-samus

Build changes
-------------

* CI: CI-20190529 -> None
* Linux: CI_DRM_8453 -> Patchwork_17612

CI-20190529: 20190529
CI_DRM_8453: bd2e8a4803db758fcbc558acbf5ad89e3a1779b0 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5642: d1ce4abb01c70f7be6e777b6d45442663c4b830e @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_17612: efdf66834e31052f2218abc1bc1dbb87a0278e9b @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

efdf66834e31 drm/i915/gt: Replace zero-length array with flexible-array

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/index.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw

[Intel-gfx] ✓ Fi.CI.IGT: success for drm/i915/gt: Replace zero-length array with flexible-array

In reply to Gustavo A. R. Silva
== Series Details ==

== Series Details ==

Series: drm/i915/gt: Replace zero-length array with flexible-array
URL : https://patchwork.freedesktop.org/series/77080/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_8453_full -> Patchwork_17612_full
====================================================

Summary
-------

**SUCCESS**

No regressions found.

Known issues
------------

Here are the changes found in Patchwork_17612_full that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@i915_pm_dc@dc6-psr:
- shard-skl: [PASS][1] -> [FAIL][2] ([i915#454])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-skl2/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-skl3/igt@[email protected]

* igt@i915_suspend@forcewake:
- shard-kbl: [PASS][3] -> [DMESG-WARN][4] ([i915#180]) +1 similar issue
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-kbl6/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-kbl4/igt@[email protected]

* igt@kms_cursor_crc@pipe-a-cursor-64x64-offscreen:
- shard-kbl: [PASS][5] -> [FAIL][6] ([i915#54] / [i915#93] / [i915#95])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-kbl2/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-kbl3/igt@[email protected]

* igt@kms_hdr@bpc-switch-dpms:
- shard-skl: [PASS][7] -> [FAIL][8] ([i915#1188])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-skl3/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-skl6/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-c-coverage-7efc:
- shard-skl: [PASS][9] -> [FAIL][10] ([fdo#108145] / [i915#265]) +2 similar issues
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-skl9/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-skl7/igt@[email protected]

* igt@kms_psr@psr2_suspend:
- shard-iclb: [PASS][11] -> [SKIP][12] ([fdo#109441]) +2 similar issues
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-iclb2/igt@kms_psr@psr2_suspend.html
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-iclb8/igt@kms_psr@psr2_suspend.html

* igt@kms_vblank@pipe-b-ts-continuation-suspend:
- shard-apl: [PASS][13] -> [DMESG-WARN][14] ([i915#180]) +2 similar issues
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-apl6/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-apl6/igt@[email protected]

#### Possible fixes ####

* igt@gem_exec_suspend@basic-s3:
- shard-skl: [INCOMPLETE][15] ([i915#69]) -> [PASS][16] +1 similar issue
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-skl1/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-skl6/igt@[email protected]

* igt@kms_draw_crc@draw-method-rgb565-mmap-wc-ytiled:
- shard-skl: [FAIL][17] ([i915#52] / [i915#54]) -> [PASS][18]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-skl6/igt@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-skl1/igt@[email protected]

* {igt@kms_flip@2x-flip-vs-expired-vblank-interruptible@ab-hdmi-a1-hdmi-a2}:
- shard-glk: [FAIL][19] ([i915#79]) -> [PASS][20]
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-glk2/igt@kms_flip@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-glk9/igt@kms_flip@[email protected]

* {igt@kms_flip@flip-vs-suspend-interruptible@c-dp1}:
- shard-apl: [DMESG-WARN][21] ([i915#180]) -> [PASS][22] +2 similar issues
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-apl4/igt@kms_flip@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-apl8/igt@kms_flip@[email protected]

* {igt@kms_flip@flip-vs-suspend@b-hdmi-a1}:
- shard-hsw: [INCOMPLETE][23] ([i915#61]) -> [PASS][24]
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-hsw4/igt@kms_flip@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-hsw1/igt@kms_flip@[email protected]

* igt@kms_hdr@bpc-switch-suspend:
- shard-kbl: [DMESG-WARN][25] ([i915#180]) -> [PASS][26] +1 similar issue
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-kbl4/igt@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-kbl2/igt@[email protected]

* igt@kms_psr@psr2_primary_mmap_cpu:
- shard-iclb: [SKIP][27] ([fdo#109441]) -> [PASS][28] +2 similar issues
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-iclb1/igt@kms_psr@psr2_primary_mmap_cpu.html
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-iclb2/igt@kms_psr@psr2_primary_mmap_cpu.html

* igt@kms_setmode@basic:
- shard-hsw: [FAIL][29] ([i915#31]) -> [PASS][30]
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-hsw1/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-hsw5/igt@[email protected]

* {igt@perf@blocking-parameterized}:
- shard-tglb: [FAIL][31] ([i915#1542]) -> [PASS][32]
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-tglb2/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-tglb1/igt@[email protected]

#### Warnings ####

* igt@i915_pm_dc@dc6-psr:
- shard-tglb: [SKIP][33] ([i915#468]) -> [FAIL][34] ([i915#454])
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-tglb2/igt@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-tglb1/igt@[email protected]

* igt@kms_content_protection@atomic:
- shard-apl: [FAIL][35] ([fdo#110321] / [fdo#110336]) -> [TIMEOUT][36] ([i915#1319])
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-apl3/igt@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-apl1/igt@[email protected]

* igt@kms_content_protection@atomic-dpms:
- shard-apl: [TIMEOUT][37] ([i915#1319]) -> [FAIL][38] ([fdo#110321] / [fdo#110336])
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8453/shard-apl6/igt@[email protected]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/shard-apl7/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#108145]: https://bugs.freedesktop.org/show_bug.cgi?id=108145
[fdo#109441]: https://bugs.freedesktop.org/show_bug.cgi?id=109441
[fdo#110321]: https://bugs.freedesktop.org/show_bug.cgi?id=110321
[fdo#110336]: https://bugs.freedesktop.org/show_bug.cgi?id=110336
[i915#1188]: https://gitlab.freedesktop.org/drm/intel/issues/1188
[i915#1319]: https://gitlab.freedesktop.org/drm/intel/issues/1319
[i915#1542]: https://gitlab.freedesktop.org/drm/intel/issues/1542
[i915#180]: https://gitlab.freedesktop.org/drm/intel/issues/180
[i915#265]: https://gitlab.freedesktop.org/drm/intel/issues/265
[i915#31]: https://gitlab.freedesktop.org/drm/intel/issues/31
[i915#454]: https://gitlab.freedesktop.org/drm/intel/issues/454
[i915#468]: https://gitlab.freedesktop.org/drm/intel/issues/468
[i915#52]: https://gitlab.freedesktop.org/drm/intel/issues/52
[i915#54]: https://gitlab.freedesktop.org/drm/intel/issues/54
[i915#61]: https://gitlab.freedesktop.org/drm/intel/issues/61
[i915#69]: https://gitlab.freedesktop.org/drm/intel/issues/69
[i915#79]: https://gitlab.freedesktop.org/drm/intel/issues/79
[i915#93]: https://gitlab.freedesktop.org/drm/intel/issues/93
[i915#95]: https://gitlab.freedesktop.org/drm/intel/issues/95

Participating hosts (11 -> 11)
------------------------------

No changes in participating hosts

Build changes
-------------

* CI: CI-20190529 -> None
* Linux: CI_DRM_8453 -> Patchwork_17612

CI-20190529: 20190529
CI_DRM_8453: bd2e8a4803db758fcbc558acbf5ad89e3a1779b0 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5642: d1ce4abb01c70f7be6e777b6d45442663c4b830e @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_17612: efdf66834e31052f2218abc1bc1dbb87a0278e9b @ git://anongit.freedesktop.org/gfx-ci/linux
piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17612/index.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx