Skip to contentSkip to conversation

drm/msm: use strscpy instead of strncpy

PATCH Applied Dmitry Baryshkov 2 participants 3 messages Jan 18, 2023 – Jan 26, 2023

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

PATCH 1/1 drm/msm: use strscpy instead of strncpy

Using strncpy can result in non-NULL-terminated destination string. Use strscpy instead. This fixes following warning:

drivers/gpu/drm/msm/msm_fence.c: In function ‘msm_fence_context_alloc’:
drivers/gpu/drm/msm/msm_fence.c:25:9: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation]

   25 |         strncpy(fctx->name, name, sizeof(fctx->name));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fixes f97decac5f4c ("drm/msm: Support multiple ringbuffers")
---
 drivers/gpu/drm/msm/msm_fence.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/msm_fence.c +1 -1
index a47e5837c528..56641408ea74 100644
@@ -22,7 +22,7 @@ msm_fence_context_alloc(struct drm_device *dev, volatile uint32_t *fenceptr,
 		return ERR_PTR(-ENOMEM);
 
 	fctx->dev = dev;
-	strncpy(fctx->name, name, sizeof(fctx->name));
+	strscpy(fctx->name, name, sizeof(fctx->name));
 	fctx->context = dma_fence_context_alloc(1);
 	fctx->index = index++;
 	fctx->fenceptr = fenceptr;
Signature · 1 line
2.39.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Dmitry Baryshkov

Using strncpy can result in non-NULL-terminated destination string. Use strscpy instead. This fixes following warning:

drivers/gpu/drm/msm/msm_fence.c: In function ‘msm_fence_context_alloc’:
drivers/gpu/drm/msm/msm_fence.c:25:9: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation]

    25 |         strncpy(fctx->name, name, sizeof(fctx->name));
       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fixes f97decac5f4c ("drm/msm: Support multiple ringbuffers")
Quoted 17 lines
---
  drivers/gpu/drm/msm/msm_fence.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/msm_fence.c +1 -1
index a47e5837c528..56641408ea74 100644
@@ -22,7 +22,7 @@ msm_fence_context_alloc(struct drm_device *dev, volatile uint32_t *fenceptr,
  		return ERR_PTR(-ENOMEM);
 
  	fctx->dev = dev;
-	strncpy(fctx->name, name, sizeof(fctx->name));
+	strscpy(fctx->name, name, sizeof(fctx->name));
  	fctx->context = dma_fence_context_alloc(1);
  	fctx->index = index++;
  	fctx->fenceptr = fenceptr;
author Applied
#2 lore raw
In reply to Dmitry Baryshkov
Quoted 9 lines · Dmitry Baryshkov

Using strncpy can result in non-NULL-terminated destination string. Use strscpy instead. This fixes following warning:

drivers/gpu/drm/msm/msm_fence.c: In function ‘msm_fence_context_alloc’:
drivers/gpu/drm/msm/msm_fence.c:25:9: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation]

   25 |         strncpy(fctx->name, name, sizeof(fctx->name));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[...]

Applied, thanks!

[1/1] drm/msm: use strscpy instead of strncpy

      https://gitlab.freedesktop.org/lumag/msm/-/commit/d7fd8634f48d

Best regards,

Signature · 1 line
Dmitry Baryshkov <[email protected]>