linux_dsm_epyc7002/drivers/gpu/drm/amd/powerplay
Gustavo A. R. Silva 94f2026bd8 drm/amdgpu/smu10: Replace one-element array and use struct_size() helper
The current codebase makes use of one-element arrays in the following
form:

struct something {
    int length;
    u8 data[1];
};

struct something *instance;

instance = kmalloc(sizeof(*instance) + size, GFP_KERNEL);
instance->length = size;
memcpy(instance->data, source, size);

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. So, replace
the one-element array with a flexible-array member.

Also, make use of the new struct_size() helper to properly calculate the
size of struct smu10_voltage_dependency_table.

This issue was found with the help of Coccinelle and, audited and fixed
_manually_.

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

Acked-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2020-05-21 12:48:43 -04:00
..
hwmgr drm/amdgpu/smu10: Replace one-element array and use struct_size() helper 2020-05-21 12:48:43 -04:00
inc drm/amdgpu: Add cmd to control XGMI link sleep 2020-05-14 17:42:15 -04:00
smumgr drm/amd/powerplay: added mutex protection on msg issuing 2020-04-01 14:44:45 -04:00
amd_powerplay.c drm/amd/powerplay: perform PG ungate prior to CG ungate 2020-05-06 16:51:15 -04:00
amdgpu_smu.c drm/amdgpu: Add cmd to control XGMI link sleep 2020-05-14 17:42:15 -04:00
arcturus_ppt.c drm/amdgpu: resolve ras recovery vs smi race condition 2020-05-21 12:46:51 -04:00
arcturus_ppt.h drm/amd/powerplay: update arcturus_ppt.c/h V3 2019-07-30 23:48:33 -05:00
Makefile drm/amdgpu/powerplay: add smu ip block for renoir (v2) 2019-08-22 17:36:58 -05:00
navi10_ppt.c drm/amdgpu/navi10: fix unsigned comparison with 0 2020-05-06 16:51:39 -04:00
navi10_ppt.h drm/amdgpu/smu: custom pstate profiling clock frequence for navi series asics 2020-01-07 12:01:09 -05:00
renoir_ppt.c drm/amdgpu/powerplay:avoid to show invalid DPM table info 2020-04-22 18:11:49 -04:00
renoir_ppt.h drm/amdgpu/powerplay: using the FCLK DPM table to set the MCLK 2020-04-03 17:20:15 -04:00
smu_internal.h drm/amd/powerplay: correct i2c eeprom init/fini sequence 2020-04-22 18:11:45 -04:00
smu_v11_0.c drm/amd/powerplay: unify the prompts on thermal interrupts 2020-05-21 12:48:42 -04:00
smu_v12_0.c drm/amdgpu: cache smu fw version info 2020-04-22 18:11:46 -04:00
vega20_ppt.c drm/amd/powerplay: properly set the dpm_enabled state 2020-04-22 18:11:45 -04:00
vega20_ppt.h drm/amd/powerplay: simplified od_settings for each asic 2019-06-21 18:59:32 -05:00