drm/amdgpu: Replace deprecated strcpy with strscpy
Subsystems (2)
PATCH 1/1 drm/amdgpu: Replace deprecated strcpy with strscpy
strcpy() has been deprecated because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. Replace it with the safer strscpy(). No functional changes.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +3 -3
@@ -97,7 +97,7 @@ int amdgpu_mca_mp0_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mp0" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mp0" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MP0 ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;
@@ -122,7 +122,7 @@ int amdgpu_mca_mp1_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mp1" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mp1" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MP1 ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;
@@ -147,7 +147,7 @@ int amdgpu_mca_mpio_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mpio" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mpio" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MPIO ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;
---
base-commit: 0f23d56f17fdfc7db69d51f64c8b91bbab947aa9
change-id: 20260818-amdgpu-strcpy-0e92d18299c6
Best regards,
Signature · 1 line
Amin Gattout <[email protected]>
Alex Deucher
AppliedApplied. Thanks!
Quoted 50 lines · Amin Gattout
strcpy()has been deprecated because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. Replace it with the saferstrscpy(). No functional changes.Signed-off-by Amin Gattout <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +3
-4@@ -97,7 +97,7 @@ int amdgpu_mca_mp0_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mp0" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mp0" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MP0 ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;@@ -122,7 +122,7 @@ int amdgpu_mca_mp1_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mp1" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mp1" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MP1 ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;@@ -147,7 +147,7 @@ int amdgpu_mca_mpio_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mpio" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mpio" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MPIO ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ; ---base-commit:
0f23d56f17fdfc7db69d51f64c8b91bbab947aa9
change-id: 20260818-amdgpu-strcpy-0e92d18299c6Best regards,
--
Amin Gattout <[email protected]>
Quoted 21 lines · On Tue, 18 Aug 2026 09:01:43 -0400 Alex Deucher <[email protected]> wrote:
Applied. Thanks!
Quoted 18 lines · Amin Gattout
strcpy()has been deprecated because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. Replace it with the saferstrscpy(). No functional changes.Signed-off-by Amin Gattout <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +0
-0@@ -97,7 +97,7 @@ int amdgpu_mca_mp0_ras_sw_init(struct amdgpu_device *adev)return err; }
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c int amdgpu_mca_mp0_ras_sw_init(struct amdgpu_device *adev) · line 100
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +1
-1-strcpy (ras->ras_block.ras_comm.name,"mca.mp0" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mp0" );
I missed this being proposed.
Both strcpy() and strscpy() get converted to the same memcpy() (which might itself get converted to writing a 64bit constant).
But if the string were too long strcpy() would generate a compile error whereas strscpy() just trunctates the string.
Which one is better?
David
Quoted 31 lines
Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +2
-3ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MP0 ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;@@ -122,7 +122,7 @@ int amdgpu_mca_mp1_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mp1" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mp1" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MP1 ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;@@ -147,7 +147,7 @@ int amdgpu_mca_mpio_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mpio" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mpio" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MPIO ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ; ---base-commit:
0f23d56f17fdfc7db69d51f64c8b91bbab947aa9
change-id: 20260818-amdgpu-strcpy-0e92d18299c6Best regards,
--
Amin Gattout <[email protected]>
Quoted 32 lines · David Laight
Quoted 21 lines · On Tue, 18 Aug 2026 09:01:43 -0400 Alex Deucher <[email protected]> wrote:
Applied. Thanks!
Quoted 18 lines · Amin Gattout
strcpy()has been deprecated because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. Replace it with the saferstrscpy(). No functional changes.Signed-off-by Amin Gattout <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +0
-0@@ -97,7 +97,7 @@ int amdgpu_mca_mp0_ras_sw_init(struct amdgpu_device *adev)return err; }Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c int amdgpu_mca_mp0_ras_sw_init(struct amdgpu_device *adev) · line 100
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +1
-1-strcpy (ras->ras_block.ras_comm.name,"mca.mp0" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mp0" );I missed this being proposed.
Bothstrcpy()andstrscpy()get converted to the samememcpy()(which might itself get converted to writing a 64bit constant).
Quoted 4 lines
But if the string were too long
strcpy()would generate a compile error whereasstrscpy()just trunctates the string.Which one is better?
I don't know. I can go either way on this.
Alex
Quoted 35 lines
David
Quoted 31 lines
Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +2
-3ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MP0 ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;@@ -122,7 +122,7 @@ int amdgpu_mca_mp1_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mp1" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mp1" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MP1 ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;@@ -147,7 +147,7 @@ int amdgpu_mca_mpio_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mpio" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mpio" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MPIO ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ; ---base-commit:
0f23d56f17fdfc7db69d51f64c8b91bbab947aa9
change-id: 20260818-amdgpu-strcpy-0e92d18299c6Best regards,
--
Amin Gattout <[email protected]>
You raise a fair point about the compile-time truncation check. My reasoning follows the kernel's own deprecation guidance, which explicitly lists strcpy() as deprecated and names strscpy() as the safe replacement:
https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
Regards.
Amin.
Quoted 80 lines · Alex Deucher
Quoted 32 lines · David Laight
Quoted 21 lines · On Tue, 18 Aug 2026 09:01:43 -0400 Alex Deucher <[email protected]> wrote:
Applied. Thanks!
Quoted 18 lines · Amin Gattout
strcpy()has been deprecated because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. Replace it with the saferstrscpy(). No functional changes.Signed-off-by Amin Gattout <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +0
-0@@ -97,7 +97,7 @@ int amdgpu_mca_mp0_ras_sw_init(struct amdgpu_device *adev)return err; }Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c int amdgpu_mca_mp0_ras_sw_init(struct amdgpu_device *adev) · line 100
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +1
-1-strcpy (ras->ras_block.ras_comm.name,"mca.mp0" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mp0" );I missed this being proposed.
Bothstrcpy()andstrscpy()get converted to the samememcpy()(which might itself get converted to writing a 64bit constant).Quoted 4 lines
But if the string were too long
strcpy()would generate a compile error whereasstrscpy()just trunctates the string.Which one is better?
I don't know. I can go either way on this.
Alex
Quoted 35 lines
David
Quoted 31 lines
Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +2
-3ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MP0 ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;@@ -122,7 +122,7 @@ int amdgpu_mca_mp1_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mp1" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mp1" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MP1 ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;@@ -147,7 +147,7 @@ int amdgpu_mca_mpio_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mpio" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mpio" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MPIO ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ; ---base-commit:
0f23d56f17fdfc7db69d51f64c8b91bbab947aa9
change-id: 20260818-amdgpu-strcpy-0e92d18299c6Best regards,
--
Amin Gattout <[email protected]>
Quoted 7 lines · Amin
You raise a fair point about the compile-time truncation check. My reasoning follows the kernel's own deprecation guidance, which explicitly lists
strcpy()as deprecated and namesstrscpy()as the safe replacement:https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
RIght. My thinking was that strscpy() would be preferred to avoid static checkers from complaining about strcpy().
Alex
Quoted 85 lines
Regards.
Amin.Quoted 80 lines · Alex Deucher
Quoted 32 lines · David Laight
Quoted 21 lines · On Tue, 18 Aug 2026 09:01:43 -0400 Alex Deucher <[email protected]> wrote:
Applied. Thanks!
Quoted 18 lines · Amin Gattout
strcpy()has been deprecated because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. Replace it with the saferstrscpy(). No functional changes.Signed-off-by Amin Gattout <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +0
-0@@ -97,7 +97,7 @@ int amdgpu_mca_mp0_ras_sw_init(struct amdgpu_device *adev)return err; }Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c int amdgpu_mca_mp0_ras_sw_init(struct amdgpu_device *adev) · line 100
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +1
-1-strcpy (ras->ras_block.ras_comm.name,"mca.mp0" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mp0" );I missed this being proposed.
Bothstrcpy()andstrscpy()get converted to the samememcpy()(which might itself get converted to writing a 64bit constant).Quoted 4 lines
But if the string were too long
strcpy()would generate a compile error whereasstrscpy()just trunctates the string.Which one is better?
I don't know. I can go either way on this.
Alex
Quoted 35 lines
David
Quoted 31 lines
Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +2
-3ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MP0 ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;@@ -122,7 +122,7 @@ int amdgpu_mca_mp1_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mp1" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mp1" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MP1 ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;@@ -147,7 +147,7 @@ int amdgpu_mca_mpio_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mpio" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mpio" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MPIO ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ; ---base-commit:
0f23d56f17fdfc7db69d51f64c8b91bbab947aa9
change-id: 20260818-amdgpu-strcpy-0e92d18299c6Best regards,
--
Amin Gattout <[email protected]>
Quoted 11 lines · On Tue, 18 Aug 2026 13:56:06 -0400 Alex Deucher <[email protected]> wrote:
Quoted 7 lines · Amin
You raise a fair point about the compile-time truncation check. My reasoning follows the kernel's own deprecation guidance, which explicitly lists
strcpy()as deprecated and namesstrscpy()as the safe replacement:https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
RIght. My thinking was that
strscpy()would be preferred to avoid static checkers from complaining aboutstrcpy().
Personally I think the guidance (and checkpatch) should be changed. It is pretty easy to change the header files to only allow safe strcpy().
If nothing else that reduces pointless churn that just makes more work for the maintainers.
There are plenty of strcpy() and strlcat() calls that are 'not obviously correctly bounded' (and probably some strscpy() ones as well) which are better targets for patches than the ones that are trivially valid.
David
Quoted 2 lines
Alex
Christian König
maintainerQuoted 16 lines · Amin Gattout
[Sie erhalten nicht häufig E-Mails von [email protected]. Weitere Informationen, warum dies wichtig ist, finden Sie unter https://aka.ms/LearnAboutSenderIdentification ]
strcpy()has been deprecated because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. Replace it with the saferstrscpy(). No functional changes.Signed-off-by Amin Gattout <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c int amdgpu_mca_mp0_ras_sw_init(struct amdgpu_device *adev) · line 100
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +1
-1@@ -97,7 +97,7 @@ int amdgpu_mca_mp0_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mp0" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mp0" );
Well taking a step back. Why do we use strcpy() here in the first place?
As far as I can see ras->ras_block.ras_comm.name could just we a "const char *", doesn't it?
Regards,
Christian.
Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +2
-3ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MP0 ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;@@ -122,7 +122,7 @@ int amdgpu_mca_mp1_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mp1" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mp1" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MP1 ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ;@@ -147,7 +147,7 @@ int amdgpu_mca_mpio_ras_sw_init(struct amdgpu_device *adev)return err; } -strcpy (ras->ras_block.ras_comm.name,"mca.mpio" ); +strscpy (ras->ras_block.ras_comm.name,"mca.mpio" ); ras->ras_block.ras_comm.block =AMDGPU_RAS_BLOCK__MCA ; ras->ras_block.ras_comm.sub_block_index =AMDGPU_RAS_MCA_BLOCK__MPIO ; ras->ras_block.ras_comm.type =AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE ; ---base-commit:
0f23d56f17fdfc7db69d51f64c8b91bbab947aa9
change-id: 20260818-amdgpu-strcpy-0e92d18299c6Best regards,
--
Amin Gattout <[email protected]>