2022-02-15 10:01:37

by CGEL

[permalink] [raw]
Subject: [PATCH] drm/amdkfd: Replace zero-length array with flexible-array member

From: Changcheng Deng <[email protected]>

There is a regular need in the kernel to provide a way to declare having
a dynamically sized set of trailing elements in a structure. Kernel code
should always use "flexible array members" for these cases. The older
style of one-element or zero-length arrays should no longer be used.
Reference:
https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Reported-by: Zeal Robot <[email protected]>
Signed-off-by: Changcheng Deng <[email protected]>
---
drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index e54a52785690..7d39191d13f6 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -1084,7 +1084,7 @@ struct kfd_criu_svm_range_priv_data {
uint64_t start_addr;
uint64_t size;
/* Variable length array of attributes */
- struct kfd_ioctl_svm_attribute attrs[0];
+ struct kfd_ioctl_svm_attribute attrs[];
};

struct kfd_criu_queue_priv_data {
--
2.25.1


2022-02-15 15:38:34

by Christian König

[permalink] [raw]
Subject: Re: [PATCH] drm/amdkfd: Replace zero-length array with flexible-array member



Am 15.02.22 um 10:11 schrieb [email protected]:
> From: Changcheng Deng <[email protected]>
>
> There is a regular need in the kernel to provide a way to declare having
> a dynamically sized set of trailing elements in a structure. Kernel code
> should always use "flexible array members" for these cases. The older
> style of one-element or zero-length arrays should no longer be used.
> Reference:
> https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

I think you should harden the wording here into "must" no longer be used.

We had so many problems with that and certain gcc versions that we
should have this automatically checked somehow.

>
> Reported-by: Zeal Robot <[email protected]>
> Signed-off-by: Changcheng Deng <[email protected]>

Acked-by: Christian König <[email protected]>

> ---
> drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> index e54a52785690..7d39191d13f6 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> @@ -1084,7 +1084,7 @@ struct kfd_criu_svm_range_priv_data {
> uint64_t start_addr;
> uint64_t size;
> /* Variable length array of attributes */
> - struct kfd_ioctl_svm_attribute attrs[0];
> + struct kfd_ioctl_svm_attribute attrs[];
> };
>
> struct kfd_criu_queue_priv_data {

2022-02-16 07:09:16

by Felix Kuehling

[permalink] [raw]
Subject: Re: [PATCH] drm/amdkfd: Replace zero-length array with flexible-array member


On 2022-02-15 04:11, [email protected] wrote:
> From: Changcheng Deng <[email protected]>
>
> There is a regular need in the kernel to provide a way to declare having
> a dynamically sized set of trailing elements in a structure. Kernel code
> should always use "flexible array members" for these cases. The older
> style of one-element or zero-length arrays should no longer be used.
> Reference:
> https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
>
> Reported-by: Zeal Robot <[email protected]>
> Signed-off-by: Changcheng Deng <[email protected]>

Makes sense. I'm applying this patch to amd-staging-drm-next.

I also found a similar issue in include/uapi/linux/kfd_ioctl.h. I'll
send another patch to fix that as well.

Regards,
  Felix


> ---
> drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> index e54a52785690..7d39191d13f6 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> @@ -1084,7 +1084,7 @@ struct kfd_criu_svm_range_priv_data {
> uint64_t start_addr;
> uint64_t size;
> /* Variable length array of attributes */
> - struct kfd_ioctl_svm_attribute attrs[0];
> + struct kfd_ioctl_svm_attribute attrs[];
> };
>
> struct kfd_criu_queue_priv_data {