All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amd: Fix the size of a buffer in amdgpu_vcn_idle_work_handler()
@ 2023-09-22 19:27 ` Christophe JAILLET
  0 siblings, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2023-09-22 19:27 UTC (permalink / raw)
  To: Alex Deucher, Christian König, Pan, Xinhui, David Airlie,
	Daniel Vetter, Lijo Lazar, Mario Limonciello
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, amd-gfx, dri-devel

In order to be sure that fw_name is not truncated, this buffer should be
at least 41 bytes long.

Let the compiler compute the correct length by itself.

When building with W=1, this fixes the following warnings:

  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c: In function ‘amdgpu_vcn_early_init’:
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c:95:58: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
     95 |         snprintf(fw_name, sizeof(fw_name), "amdgpu/%s.bin", ucode_prefix);
        |                                                          ^
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c:95:9: note: ‘snprintf’ output between 12 and 41 bytes into a destination of size 40
     95 |         snprintf(fw_name, sizeof(fw_name), "amdgpu/%s.bin", ucode_prefix);
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fixes: 69939009bde7 ("drm/amd: Load VCN microcode during early_init")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
index c93f3a4c0e31..f8cd55a0d1f0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
@@ -88,7 +88,7 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work);
 int amdgpu_vcn_early_init(struct amdgpu_device *adev)
 {
 	char ucode_prefix[30];
-	char fw_name[40];
+	char fw_name[sizeof(ucode_prefix) + sizeof("amdgpu/.bin") - 1];
 	int r;
 
 	amdgpu_ucode_ip_version_decode(adev, UVD_HWIP, ucode_prefix, sizeof(ucode_prefix));
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] drm/amd: Fix the size of a buffer in amdgpu_vcn_idle_work_handler()
@ 2023-09-22 19:27 ` Christophe JAILLET
  0 siblings, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2023-09-22 19:27 UTC (permalink / raw)
  To: Alex Deucher, Christian König, Pan, Xinhui, David Airlie,
	Daniel Vetter, Lijo Lazar, Mario Limonciello
  Cc: Christophe JAILLET, dri-devel, kernel-janitors, linux-kernel, amd-gfx

In order to be sure that fw_name is not truncated, this buffer should be
at least 41 bytes long.

Let the compiler compute the correct length by itself.

When building with W=1, this fixes the following warnings:

  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c: In function ‘amdgpu_vcn_early_init’:
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c:95:58: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
     95 |         snprintf(fw_name, sizeof(fw_name), "amdgpu/%s.bin", ucode_prefix);
        |                                                          ^
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c:95:9: note: ‘snprintf’ output between 12 and 41 bytes into a destination of size 40
     95 |         snprintf(fw_name, sizeof(fw_name), "amdgpu/%s.bin", ucode_prefix);
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fixes: 69939009bde7 ("drm/amd: Load VCN microcode during early_init")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
index c93f3a4c0e31..f8cd55a0d1f0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
@@ -88,7 +88,7 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work);
 int amdgpu_vcn_early_init(struct amdgpu_device *adev)
 {
 	char ucode_prefix[30];
-	char fw_name[40];
+	char fw_name[sizeof(ucode_prefix) + sizeof("amdgpu/.bin") - 1];
 	int r;
 
 	amdgpu_ucode_ip_version_decode(adev, UVD_HWIP, ucode_prefix, sizeof(ucode_prefix));
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/amd: Fix the size of a buffer in amdgpu_vcn_idle_work_handler()
  2023-09-22 19:27 ` Christophe JAILLET
@ 2023-09-25  6:35   ` Christian König
  -1 siblings, 0 replies; 4+ messages in thread
From: Christian König @ 2023-09-25  6:35 UTC (permalink / raw)
  To: Christophe JAILLET, Alex Deucher, Pan, Xinhui, David Airlie,
	Daniel Vetter, Lijo Lazar, Mario Limonciello
  Cc: linux-kernel, kernel-janitors, amd-gfx, dri-devel

Am 22.09.23 um 21:27 schrieb Christophe JAILLET:
> In order to be sure that fw_name is not truncated, this buffer should be
> at least 41 bytes long.
>
> Let the compiler compute the correct length by itself.
>
> When building with W=1, this fixes the following warnings:
>
>    drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c: In function ‘amdgpu_vcn_early_init’:
>    drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c:95:58: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
>       95 |         snprintf(fw_name, sizeof(fw_name), "amdgpu/%s.bin", ucode_prefix);
>          |                                                          ^
>    drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c:95:9: note: ‘snprintf’ output between 12 and 41 bytes into a destination of size 40
>       95 |         snprintf(fw_name, sizeof(fw_name), "amdgpu/%s.bin", ucode_prefix);
>          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Fixes: 69939009bde7 ("drm/amd: Load VCN microcode during early_init")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
> index c93f3a4c0e31..f8cd55a0d1f0 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
> @@ -88,7 +88,7 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work);
>   int amdgpu_vcn_early_init(struct amdgpu_device *adev)
>   {
>   	char ucode_prefix[30];
> -	char fw_name[40];
> +	char fw_name[sizeof(ucode_prefix) + sizeof("amdgpu/.bin") - 1];

When that string constant is used multiple times it should probably be a 
constant.

But I think this patch is superfluous to begin with because the 
ucode_prefix is never fully used.

What we should probably rather to is to define some 
AMDGPU_MAX_UCODE_LENGTH and use that instead.

Regards,
Christian.

>   	int r;
>   
>   	amdgpu_ucode_ip_version_decode(adev, UVD_HWIP, ucode_prefix, sizeof(ucode_prefix));


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/amd: Fix the size of a buffer in amdgpu_vcn_idle_work_handler()
@ 2023-09-25  6:35   ` Christian König
  0 siblings, 0 replies; 4+ messages in thread
From: Christian König @ 2023-09-25  6:35 UTC (permalink / raw)
  To: Christophe JAILLET, Alex Deucher, Pan, Xinhui, David Airlie,
	Daniel Vetter, Lijo Lazar, Mario Limonciello
  Cc: dri-devel, kernel-janitors, linux-kernel, amd-gfx

Am 22.09.23 um 21:27 schrieb Christophe JAILLET:
> In order to be sure that fw_name is not truncated, this buffer should be
> at least 41 bytes long.
>
> Let the compiler compute the correct length by itself.
>
> When building with W=1, this fixes the following warnings:
>
>    drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c: In function ‘amdgpu_vcn_early_init’:
>    drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c:95:58: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
>       95 |         snprintf(fw_name, sizeof(fw_name), "amdgpu/%s.bin", ucode_prefix);
>          |                                                          ^
>    drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c:95:9: note: ‘snprintf’ output between 12 and 41 bytes into a destination of size 40
>       95 |         snprintf(fw_name, sizeof(fw_name), "amdgpu/%s.bin", ucode_prefix);
>          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Fixes: 69939009bde7 ("drm/amd: Load VCN microcode during early_init")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
> index c93f3a4c0e31..f8cd55a0d1f0 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
> @@ -88,7 +88,7 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work);
>   int amdgpu_vcn_early_init(struct amdgpu_device *adev)
>   {
>   	char ucode_prefix[30];
> -	char fw_name[40];
> +	char fw_name[sizeof(ucode_prefix) + sizeof("amdgpu/.bin") - 1];

When that string constant is used multiple times it should probably be a 
constant.

But I think this patch is superfluous to begin with because the 
ucode_prefix is never fully used.

What we should probably rather to is to define some 
AMDGPU_MAX_UCODE_LENGTH and use that instead.

Regards,
Christian.

>   	int r;
>   
>   	amdgpu_ucode_ip_version_decode(adev, UVD_HWIP, ucode_prefix, sizeof(ucode_prefix));


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-25  6:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-22 19:27 [PATCH] drm/amd: Fix the size of a buffer in amdgpu_vcn_idle_work_handler() Christophe JAILLET
2023-09-22 19:27 ` Christophe JAILLET
2023-09-25  6:35 ` Christian König
2023-09-25  6:35   ` Christian König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.