[PATCH] drm/amdgpu: Replace deprecated strcpy with strscpy

Amin Gattout posted 1 patch 1 month, 1 week ago
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] drm/amdgpu: Replace deprecated strcpy with strscpy
Posted by Amin Gattout 1 month, 1 week ago
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.

Signed-off-by: Amin Gattout <amin.gattout@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
index cc6d1a4e4c3a..1caa393c44d5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
@@ -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,
--  
Amin Gattout <amin.gattout@gmail.com>
Re: [PATCH] drm/amdgpu: Replace deprecated strcpy with strscpy
Posted by Christian König 1 month ago

On 8/18/26 12:32, Amin Gattout wrote:
> [Sie erhalten nicht häufig E-Mails von amin.gattout@gmail.com. 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 safer strscpy().  No functional changes.
> 
> Signed-off-by: Amin Gattout <amin.gattout@gmail.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> index cc6d1a4e4c3a..1caa393c44d5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> @@ -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.

>         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,
> --
> Amin Gattout <amin.gattout@gmail.com>
> 

Re: [PATCH] drm/amdgpu: Replace deprecated strcpy with strscpy
Posted by Alex Deucher 1 month, 1 week ago
Applied.  Thanks!

On Tue, Aug 18, 2026 at 7:10 AM Amin Gattout <amin.gattout@gmail.com> wrote:
>
> 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.
>
> Signed-off-by: Amin Gattout <amin.gattout@gmail.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> index cc6d1a4e4c3a..1caa393c44d5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> @@ -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,
> --
> Amin Gattout <amin.gattout@gmail.com>
>
Re: [PATCH] drm/amdgpu: Replace deprecated strcpy with strscpy
Posted by David Laight 1 month, 1 week ago
On Tue, 18 Aug 2026 09:01:43 -0400
Alex Deucher <alexdeucher@gmail.com> wrote:

> Applied.  Thanks!
> 
> On Tue, Aug 18, 2026 at 7:10 AM Amin Gattout <amin.gattout@gmail.com> wrote:
> >
> > 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.
> >
> > Signed-off-by: Amin Gattout <amin.gattout@gmail.com>
> > ---
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> > index cc6d1a4e4c3a..1caa393c44d5 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> > @@ -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");

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

> >         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,
> > --
> > Amin Gattout <amin.gattout@gmail.com>
> >  
> 
Re: [PATCH] drm/amdgpu: Replace deprecated strcpy with strscpy
Posted by Alex Deucher 1 month, 1 week ago
On Tue, Aug 18, 2026 at 10:21 AM David Laight
<david.laight.linux@gmail.com> wrote:
>
> On Tue, 18 Aug 2026 09:01:43 -0400
> Alex Deucher <alexdeucher@gmail.com> wrote:
>
> > Applied.  Thanks!
> >
> > On Tue, Aug 18, 2026 at 7:10 AM Amin Gattout <amin.gattout@gmail.com> wrote:
> > >
> > > 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.
> > >
> > > Signed-off-by: Amin Gattout <amin.gattout@gmail.com>
> > > ---
> > >  drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++---
> > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> > > index cc6d1a4e4c3a..1caa393c44d5 100644
> > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> > > @@ -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");
>
> 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?

I don't know.  I can go either way on this.

Alex


>
>         David
>
> > >         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,
> > > --
> > > Amin Gattout <amin.gattout@gmail.com>
> > >
> >
>
Re: [PATCH] drm/amdgpu: Replace deprecated strcpy with strscpy
Posted by Amin 1 month, 1 week ago
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.

Le mar. 18 août 2026 à 19:39, Alex Deucher <alexdeucher@gmail.com> a écrit :
>
> On Tue, Aug 18, 2026 at 10:21 AM David Laight
> <david.laight.linux@gmail.com> wrote:
> >
> > On Tue, 18 Aug 2026 09:01:43 -0400
> > Alex Deucher <alexdeucher@gmail.com> wrote:
> >
> > > Applied.  Thanks!
> > >
> > > On Tue, Aug 18, 2026 at 7:10 AM Amin Gattout <amin.gattout@gmail.com> wrote:
> > > >
> > > > 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.
> > > >
> > > > Signed-off-by: Amin Gattout <amin.gattout@gmail.com>
> > > > ---
> > > >  drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++---
> > > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> > > > index cc6d1a4e4c3a..1caa393c44d5 100644
> > > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> > > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> > > > @@ -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");
> >
> > 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?
>
> I don't know.  I can go either way on this.
>
> Alex
>
>
> >
> >         David
> >
> > > >         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,
> > > > --
> > > > Amin Gattout <amin.gattout@gmail.com>
> > > >
> > >
> >
Re: [PATCH] drm/amdgpu: Replace deprecated strcpy with strscpy
Posted by Alex Deucher 1 month, 1 week ago
On Tue, Aug 18, 2026 at 1:51 PM Amin <amin.gattout@gmail.com> wrote:
>
> 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

RIght.  My thinking was that strscpy() would be preferred to avoid
static checkers from complaining about strcpy().

Alex

>
> Regards.
> Amin.
>
> Le mar. 18 août 2026 à 19:39, Alex Deucher <alexdeucher@gmail.com> a écrit :
> >
> > On Tue, Aug 18, 2026 at 10:21 AM David Laight
> > <david.laight.linux@gmail.com> wrote:
> > >
> > > On Tue, 18 Aug 2026 09:01:43 -0400
> > > Alex Deucher <alexdeucher@gmail.com> wrote:
> > >
> > > > Applied.  Thanks!
> > > >
> > > > On Tue, Aug 18, 2026 at 7:10 AM Amin Gattout <amin.gattout@gmail.com> wrote:
> > > > >
> > > > > 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.
> > > > >
> > > > > Signed-off-by: Amin Gattout <amin.gattout@gmail.com>
> > > > > ---
> > > > >  drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c | 6 +++---
> > > > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > > > >
> > > > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> > > > > index cc6d1a4e4c3a..1caa393c44d5 100644
> > > > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> > > > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c
> > > > > @@ -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");
> > >
> > > 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?
> >
> > I don't know.  I can go either way on this.
> >
> > Alex
> >
> >
> > >
> > >         David
> > >
> > > > >         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,
> > > > > --
> > > > > Amin Gattout <amin.gattout@gmail.com>
> > > > >
> > > >
> > >
Re: [PATCH] drm/amdgpu: Replace deprecated strcpy with strscpy
Posted by David Laight 1 month, 1 week ago
On Tue, 18 Aug 2026 13:56:06 -0400
Alex Deucher <alexdeucher@gmail.com> wrote:

> On Tue, Aug 18, 2026 at 1:51 PM Amin <amin.gattout@gmail.com> wrote:
> >
> > 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  
> 
> RIght.  My thinking was that strscpy() would be preferred to avoid
> static checkers from complaining about strcpy().

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 

> 
> Alex