linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next] fbdev: omap: use strscpy() to instead of strncpy()
@ 2022-12-28  1:40 yang.yang29
  2022-12-28  7:58 ` Helge Deller
  0 siblings, 1 reply; 2+ messages in thread
From: yang.yang29 @ 2022-12-28  1:40 UTC (permalink / raw)
  To: deller
  Cc: tony, b.zolnierkie, arnd, yuzhe, jiapeng.chong, guozhengkui,
	linux-fbdev, linux-omap, dri-devel, linux-kernel, xu.panda,
	yang.yang29

From: Xu Panda <xu.panda@zte.com.cn>

The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL-terminated strings.

Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
---
 drivers/video/fbdev/omap/omapfb_main.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/video/fbdev/omap/omapfb_main.c b/drivers/video/fbdev/omap/omapfb_main.c
index 17cda5765683..1f3df2055ff0 100644
--- a/drivers/video/fbdev/omap/omapfb_main.c
+++ b/drivers/video/fbdev/omap/omapfb_main.c
@@ -1447,7 +1447,7 @@ static int fbinfo_init(struct omapfb_device *fbdev, struct fb_info *info)
 	info->fbops = &omapfb_ops;
 	info->flags = FBINFO_FLAG_DEFAULT;

-	strncpy(fix->id, MODULE_NAME, sizeof(fix->id));
+	strscpy(fix->id, MODULE_NAME, sizeof(fix->id));

 	info->pseudo_palette = fbdev->pseudo_palette;

@@ -1573,8 +1573,7 @@ static int omapfb_find_ctrl(struct omapfb_device *fbdev)

 	fbdev->ctrl = NULL;

-	strncpy(name, conf->lcd.ctrl_name, sizeof(name) - 1);
-	name[sizeof(name) - 1] = '\0';
+	strscpy(name, conf->lcd.ctrl_name, sizeof(name));

 	if (strcmp(name, "internal") == 0) {
 		fbdev->ctrl = fbdev->int_ctrl;
-- 
2.15.2

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

* Re: [PATCH linux-next] fbdev: omap: use strscpy() to instead of strncpy()
  2022-12-28  1:40 [PATCH linux-next] fbdev: omap: use strscpy() to instead of strncpy() yang.yang29
@ 2022-12-28  7:58 ` Helge Deller
  0 siblings, 0 replies; 2+ messages in thread
From: Helge Deller @ 2022-12-28  7:58 UTC (permalink / raw)
  To: yang.yang29
  Cc: tony, b.zolnierkie, arnd, yuzhe, jiapeng.chong, guozhengkui,
	linux-fbdev, linux-omap, dri-devel, linux-kernel, xu.panda

On 12/28/22 02:40, yang.yang29@zte.com.cn wrote:
> From: Xu Panda <xu.panda@zte.com.cn>
>
> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL-terminated strings.
>
> Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
> Signed-off-by: Yang Yang <yang.yang29@zte.com>
> ---
>   drivers/video/fbdev/omap/omapfb_main.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)

applied.
Thanks!
Helge

>
> diff --git a/drivers/video/fbdev/omap/omapfb_main.c b/drivers/video/fbdev/omap/omapfb_main.c
> index 17cda5765683..1f3df2055ff0 100644
> --- a/drivers/video/fbdev/omap/omapfb_main.c
> +++ b/drivers/video/fbdev/omap/omapfb_main.c
> @@ -1447,7 +1447,7 @@ static int fbinfo_init(struct omapfb_device *fbdev, struct fb_info *info)
>   	info->fbops = &omapfb_ops;
>   	info->flags = FBINFO_FLAG_DEFAULT;
>
> -	strncpy(fix->id, MODULE_NAME, sizeof(fix->id));
> +	strscpy(fix->id, MODULE_NAME, sizeof(fix->id));
>
>   	info->pseudo_palette = fbdev->pseudo_palette;
>
> @@ -1573,8 +1573,7 @@ static int omapfb_find_ctrl(struct omapfb_device *fbdev)
>
>   	fbdev->ctrl = NULL;
>
> -	strncpy(name, conf->lcd.ctrl_name, sizeof(name) - 1);
> -	name[sizeof(name) - 1] = '\0';
> +	strscpy(name, conf->lcd.ctrl_name, sizeof(name));
>
>   	if (strcmp(name, "internal") == 0) {
>   		fbdev->ctrl = fbdev->int_ctrl;


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

end of thread, other threads:[~2022-12-28  7:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-28  1:40 [PATCH linux-next] fbdev: omap: use strscpy() to instead of strncpy() yang.yang29
2022-12-28  7:58 ` Helge Deller

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).