linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpu/drm: fix a -Wstringop-truncation warning
@ 2019-08-23 18:37 Qian Cai
  2019-09-05 14:40 ` Qian Cai
  2019-09-09 13:10 ` Qian Cai
  0 siblings, 2 replies; 3+ messages in thread
From: Qian Cai @ 2019-08-23 18:37 UTC (permalink / raw)
  To: daniel
  Cc: maarten.lankhorst, maxime.ripard, sean, airlied, dri-devel,
	linux-kernel, Qian Cai

In file included from ./include/linux/bitmap.h:9,
                 from ./include/linux/cpumask.h:12,
                 from ./arch/x86/include/asm/cpumask.h:5,
                 from ./arch/x86/include/asm/msr.h:11,
                 from ./arch/x86/include/asm/processor.h:21,
                 from ./arch/x86/include/asm/cpufeature.h:5,
                 from ./arch/x86/include/asm/thread_info.h:53,
                 from ./include/linux/thread_info.h:38,
                 from ./arch/x86/include/asm/preempt.h:7,
                 from ./include/linux/preempt.h:78,
                 from ./include/linux/rcupdate.h:27,
                 from ./include/linux/rculist.h:11,
                 from ./include/linux/pid.h:5,
                 from ./include/linux/sched.h:14,
                 from ./include/linux/uaccess.h:5,
                 from drivers/gpu/drm/drm_property.c:24:
In function 'strncpy',
    inlined from 'drm_property_create' at
drivers/gpu/drm/drm_property.c:130:2:
./include/linux/string.h:305:9: warning: '__builtin_strncpy' specified
bound 32 equals destination size [-Wstringop-truncation]
  return __builtin_strncpy(p, q, size);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix it by using strscpy() which will always return a valid string, and
doesn't unnecessarily force the tail of the destination buffer to be
zeroed.

Signed-off-by: Qian Cai <cai@lca.pw>
---
 drivers/gpu/drm/drm_property.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
index 892ce636ef72..66ec2cc7a559 100644
--- a/drivers/gpu/drm/drm_property.c
+++ b/drivers/gpu/drm/drm_property.c
@@ -127,8 +127,7 @@ struct drm_property *drm_property_create(struct drm_device *dev,
 	property->num_values = num_values;
 	INIT_LIST_HEAD(&property->enum_list);
 
-	strncpy(property->name, name, DRM_PROP_NAME_LEN);
-	property->name[DRM_PROP_NAME_LEN-1] = '\0';
+	strscpy(property->name, name, DRM_PROP_NAME_LEN);
 
 	list_add_tail(&property->head, &dev->mode_config.property_list);
 
-- 
1.8.3.1


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

* Re: [PATCH] gpu/drm: fix a -Wstringop-truncation warning
  2019-08-23 18:37 [PATCH] gpu/drm: fix a -Wstringop-truncation warning Qian Cai
@ 2019-09-05 14:40 ` Qian Cai
  2019-09-09 13:10 ` Qian Cai
  1 sibling, 0 replies; 3+ messages in thread
From: Qian Cai @ 2019-09-05 14:40 UTC (permalink / raw)
  To: daniel
  Cc: maarten.lankhorst, maxime.ripard, sean, airlied, dri-devel, linux-kernel

Ping. Please take a look at this trivial patch.

On Fri, 2019-08-23 at 14:37 -0400, Qian Cai wrote:
> In file included from ./include/linux/bitmap.h:9,
>                  from ./include/linux/cpumask.h:12,
>                  from ./arch/x86/include/asm/cpumask.h:5,
>                  from ./arch/x86/include/asm/msr.h:11,
>                  from ./arch/x86/include/asm/processor.h:21,
>                  from ./arch/x86/include/asm/cpufeature.h:5,
>                  from ./arch/x86/include/asm/thread_info.h:53,
>                  from ./include/linux/thread_info.h:38,
>                  from ./arch/x86/include/asm/preempt.h:7,
>                  from ./include/linux/preempt.h:78,
>                  from ./include/linux/rcupdate.h:27,
>                  from ./include/linux/rculist.h:11,
>                  from ./include/linux/pid.h:5,
>                  from ./include/linux/sched.h:14,
>                  from ./include/linux/uaccess.h:5,
>                  from drivers/gpu/drm/drm_property.c:24:
> In function 'strncpy',
>     inlined from 'drm_property_create' at
> drivers/gpu/drm/drm_property.c:130:2:
> ./include/linux/string.h:305:9: warning: '__builtin_strncpy' specified
> bound 32 equals destination size [-Wstringop-truncation]
>   return __builtin_strncpy(p, q, size);
>          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Fix it by using strscpy() which will always return a valid string, and
> doesn't unnecessarily force the tail of the destination buffer to be
> zeroed.
> 
> Signed-off-by: Qian Cai <cai@lca.pw>
> ---
>  drivers/gpu/drm/drm_property.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
> index 892ce636ef72..66ec2cc7a559 100644
> --- a/drivers/gpu/drm/drm_property.c
> +++ b/drivers/gpu/drm/drm_property.c
> @@ -127,8 +127,7 @@ struct drm_property *drm_property_create(struct drm_device
> *dev,
>  	property->num_values = num_values;
>  	INIT_LIST_HEAD(&property->enum_list);
>  
> -	strncpy(property->name, name, DRM_PROP_NAME_LEN);
> -	property->name[DRM_PROP_NAME_LEN-1] = '\0';
> +	strscpy(property->name, name, DRM_PROP_NAME_LEN);
>  
>  	list_add_tail(&property->head, &dev->mode_config.property_list);
>  

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

* Re: [PATCH] gpu/drm: fix a -Wstringop-truncation warning
  2019-08-23 18:37 [PATCH] gpu/drm: fix a -Wstringop-truncation warning Qian Cai
  2019-09-05 14:40 ` Qian Cai
@ 2019-09-09 13:10 ` Qian Cai
  1 sibling, 0 replies; 3+ messages in thread
From: Qian Cai @ 2019-09-09 13:10 UTC (permalink / raw)
  To: Emil Velikov, daniel
  Cc: maarten.lankhorst, maxime.ripard, sean, airlied, dri-devel, linux-kernel

Emil, this seems has been stalled again from DRM maintainers. Just to see if you
have some "magic" to unsilence it like the last time...

On Fri, 2019-08-23 at 14:37 -0400, Qian Cai wrote:
> In file included from ./include/linux/bitmap.h:9,
>                  from ./include/linux/cpumask.h:12,
>                  from ./arch/x86/include/asm/cpumask.h:5,
>                  from ./arch/x86/include/asm/msr.h:11,
>                  from ./arch/x86/include/asm/processor.h:21,
>                  from ./arch/x86/include/asm/cpufeature.h:5,
>                  from ./arch/x86/include/asm/thread_info.h:53,
>                  from ./include/linux/thread_info.h:38,
>                  from ./arch/x86/include/asm/preempt.h:7,
>                  from ./include/linux/preempt.h:78,
>                  from ./include/linux/rcupdate.h:27,
>                  from ./include/linux/rculist.h:11,
>                  from ./include/linux/pid.h:5,
>                  from ./include/linux/sched.h:14,
>                  from ./include/linux/uaccess.h:5,
>                  from drivers/gpu/drm/drm_property.c:24:
> In function 'strncpy',
>     inlined from 'drm_property_create' at
> drivers/gpu/drm/drm_property.c:130:2:
> ./include/linux/string.h:305:9: warning: '__builtin_strncpy' specified
> bound 32 equals destination size [-Wstringop-truncation]
>   return __builtin_strncpy(p, q, size);
>          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Fix it by using strscpy() which will always return a valid string, and
> doesn't unnecessarily force the tail of the destination buffer to be
> zeroed.
> 
> Signed-off-by: Qian Cai <cai@lca.pw>
> ---
>  drivers/gpu/drm/drm_property.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
> index 892ce636ef72..66ec2cc7a559 100644
> --- a/drivers/gpu/drm/drm_property.c
> +++ b/drivers/gpu/drm/drm_property.c
> @@ -127,8 +127,7 @@ struct drm_property *drm_property_create(struct drm_device *dev,
>  	property->num_values = num_values;
>  	INIT_LIST_HEAD(&property->enum_list);
>  
> -	strncpy(property->name, name, DRM_PROP_NAME_LEN);
> -	property->name[DRM_PROP_NAME_LEN-1] = '\0';
> +	strscpy(property->name, name, DRM_PROP_NAME_LEN);
>  
>  	list_add_tail(&property->head, &dev->mode_config.property_list);
>  

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

end of thread, other threads:[~2019-09-09 13:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-23 18:37 [PATCH] gpu/drm: fix a -Wstringop-truncation warning Qian Cai
2019-09-05 14:40 ` Qian Cai
2019-09-09 13:10 ` Qian Cai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).