Skip to contentSkip to conversation

drm/gma500: Replace deprecated strncpy() with strscpy()

PATCH In review Thorsten Blum 3 participants 3 messages Feb 25, 2025 – Mar 6, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/gma500: Replace deprecated strncpy() with strscpy()

strncpy() is deprecated for NUL-terminated destination buffers. Use strscpy() instead and remove the manual NUL-termination.

Compile-tested only.

---
 drivers/gpu/drm/gma500/cdv_intel_dp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/gma500/cdv_intel_dp.c +1 -2
index cc2ed9b3fd2d..ca7f59ff1fda 100644
@@ -855,8 +855,7 @@ cdv_intel_dp_i2c_init(struct gma_connector *connector,
 
 	memset(&intel_dp->adapter, '\0', sizeof (intel_dp->adapter));
 	intel_dp->adapter.owner = THIS_MODULE;
-	strncpy (intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
-	intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
+	strscpy(intel_dp->adapter.name, name);
 	intel_dp->adapter.algo_data = &intel_dp->algo;
 	intel_dp->adapter.dev.parent = connector->base.kdev;
 
Signature · 1 line
2.48.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Thorsten Blum

strncpy() is deprecated for NUL-terminated destination buffers. Use strscpy() instead and remove the manual NUL-termination.

Compile-tested only.

Yup, the adapter var is already zeroed out, so even if NUL padding is needed, it is already present.

Signature · 1 line
Kees Cook
maintainer
#2 lore raw
In reply to Thorsten Blum
Quoted 9 lines · Thorsten Blum

strncpy() is deprecated for NUL-terminated destination buffers. Use strscpy() instead and remove the manual NUL-termination.

Compile-tested only.

Thanks for the patch.
Applied to drm-misc-next

-Patrik

Quoted 21 lines
---
 drivers/gpu/drm/gma500/cdv_intel_dp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/gma500/cdv_intel_dp.c +1 -3
index cc2ed9b3fd2d..ca7f59ff1fda 100644
@@ -855,8 +855,7 @@ cdv_intel_dp_i2c_init(struct gma_connector *connector,
 
        memset(&intel_dp->adapter, '\0', sizeof (intel_dp->adapter));
        intel_dp->adapter.owner = THIS_MODULE;
-       strncpy (intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
-       intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
+       strscpy(intel_dp->adapter.name, name);
        intel_dp->adapter.algo_data = &intel_dp->algo;
        intel_dp->adapter.dev.parent = connector->base.kdev;
 
--

2.48.1