linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] video: fbdev: via: check the return value of kstrdup()
@ 2022-02-21 10:37 xkernel.wang
  2022-02-22  8:01 ` Helge Deller
  0 siblings, 1 reply; 2+ messages in thread
From: xkernel.wang @ 2022-02-21 10:37 UTC (permalink / raw)
  To: FlorianSchandinat; +Cc: linux-fbdev, dri-devel, linux-kernel, Xiaoke Wang

From: Xiaoke Wang <xkernel.wang@foxmail.com>

kstrdup() is a memory allocation function which can return NULL when
some internal memory errors happen. It is better to check the return
value of it to catch the error in time during the setup of viafb.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
 drivers/video/fbdev/via/viafbdev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/video/fbdev/via/viafbdev.c b/drivers/video/fbdev/via/viafbdev.c
index 22deb34..2d67c92 100644
--- a/drivers/video/fbdev/via/viafbdev.c
+++ b/drivers/video/fbdev/via/viafbdev.c
@@ -1939,8 +1939,12 @@ static int __init viafb_setup(void)
 
 		if (!strncmp(this_opt, "viafb_mode1=", 12)) {
 			viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
+			if (!viafb_mode1)
+				return -ENOMEM;
 		} else if (!strncmp(this_opt, "viafb_mode=", 11)) {
 			viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
+			if (!viafb_mode)
+				return -ENOMEM;
 		} else if (!strncmp(this_opt, "viafb_bpp1=", 11)) {
 			if (kstrtouint(this_opt + 11, 0, &viafb_bpp1) < 0)
 				return -EINVAL;
@@ -1969,6 +1973,8 @@ static int __init viafb_setup(void)
 				return -EINVAL;
 		} else if (!strncmp(this_opt, "viafb_active_dev=", 17)) {
 			viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
+			if (!viafb_active_dev)
+				return -ENOMEM;
 		} else if (!strncmp(this_opt,
 			"viafb_display_hardware_layout=", 30)) {
 			if (kstrtoint(this_opt + 30, 0,
@@ -1995,8 +2001,12 @@ static int __init viafb_setup(void)
 				return -EINVAL;
 		} else if (!strncmp(this_opt, "viafb_lcd_port=", 15)) {
 			viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
+			if (!viafb_lcd_port)
+				return -ENOMEM;
 		} else if (!strncmp(this_opt, "viafb_dvi_port=", 15)) {
 			viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
+			if (!viafb_dvi_port)
+				return -ENOMEM;
 		}
 	}
 	return 0;
-- 

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

* Re: [PATCH] video: fbdev: via: check the return value of kstrdup()
  2022-02-21 10:37 [PATCH] video: fbdev: via: check the return value of kstrdup() xkernel.wang
@ 2022-02-22  8:01 ` Helge Deller
  0 siblings, 0 replies; 2+ messages in thread
From: Helge Deller @ 2022-02-22  8:01 UTC (permalink / raw)
  To: xkernel.wang, FlorianSchandinat; +Cc: linux-fbdev, dri-devel, linux-kernel

On 2/21/22 11:37, xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
>
> kstrdup() is a memory allocation function which can return NULL when
> some internal memory errors happen. It is better to check the return
> value of it to catch the error in time during the setup of viafb.
>
> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>

applied to fbdev for-next tree.
Thanks!
Helge

> ---
>  drivers/video/fbdev/via/viafbdev.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/drivers/video/fbdev/via/viafbdev.c b/drivers/video/fbdev/via/viafbdev.c
> index 22deb34..2d67c92 100644
> --- a/drivers/video/fbdev/via/viafbdev.c
> +++ b/drivers/video/fbdev/via/viafbdev.c
> @@ -1939,8 +1939,12 @@ static int __init viafb_setup(void)
>
>  		if (!strncmp(this_opt, "viafb_mode1=", 12)) {
>  			viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
> +			if (!viafb_mode1)
> +				return -ENOMEM;
>  		} else if (!strncmp(this_opt, "viafb_mode=", 11)) {
>  			viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
> +			if (!viafb_mode)
> +				return -ENOMEM;
>  		} else if (!strncmp(this_opt, "viafb_bpp1=", 11)) {
>  			if (kstrtouint(this_opt + 11, 0, &viafb_bpp1) < 0)
>  				return -EINVAL;
> @@ -1969,6 +1973,8 @@ static int __init viafb_setup(void)
>  				return -EINVAL;
>  		} else if (!strncmp(this_opt, "viafb_active_dev=", 17)) {
>  			viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
> +			if (!viafb_active_dev)
> +				return -ENOMEM;
>  		} else if (!strncmp(this_opt,
>  			"viafb_display_hardware_layout=", 30)) {
>  			if (kstrtoint(this_opt + 30, 0,
> @@ -1995,8 +2001,12 @@ static int __init viafb_setup(void)
>  				return -EINVAL;
>  		} else if (!strncmp(this_opt, "viafb_lcd_port=", 15)) {
>  			viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
> +			if (!viafb_lcd_port)
> +				return -ENOMEM;
>  		} else if (!strncmp(this_opt, "viafb_dvi_port=", 15)) {
>  			viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
> +			if (!viafb_dvi_port)
> +				return -ENOMEM;
>  		}
>  	}
>  	return 0;


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

end of thread, other threads:[~2022-02-22  8:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-21 10:37 [PATCH] video: fbdev: via: check the return value of kstrdup() xkernel.wang
2022-02-22  8:01 ` 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).