dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fbdev/nvidiafb: Correct const string length in nvidiafb_setup()
@ 2025-04-07 11:55 Zijun Hu
  2025-04-24 22:18 ` Helge Deller
  2025-04-25  8:55 ` Jani Nikula
  0 siblings, 2 replies; 4+ messages in thread
From: Zijun Hu @ 2025-04-07 11:55 UTC (permalink / raw)
  To: Antonino Daplas, Helge Deller
  Cc: Zijun Hu, linux-fbdev, dri-devel, linux-kernel, Zijun Hu

From: Zijun Hu <quic_zijuhu@quicinc.com>

The actual length of const string "noaccel" is 7, but the strncmp()
branch in nvidiafb_setup() wrongly hard codes it as 6.

Fix by using actual length 7 as argument of the strncmp().

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/video/fbdev/nvidia/nvidia.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
index 8900f181f1952acd2acc16a6ab49a5a42ec056ac..cfaf9454014d8161bedc3598fb68855e04ea9408 100644
--- a/drivers/video/fbdev/nvidia/nvidia.c
+++ b/drivers/video/fbdev/nvidia/nvidia.c
@@ -1484,7 +1484,7 @@ static int nvidiafb_setup(char *options)
 			flatpanel = 1;
 		} else if (!strncmp(this_opt, "hwcur", 5)) {
 			hwcur = 1;
-		} else if (!strncmp(this_opt, "noaccel", 6)) {
+		} else if (!strncmp(this_opt, "noaccel", 7)) {
 			noaccel = 1;
 		} else if (!strncmp(this_opt, "noscale", 7)) {
 			noscale = 1;

---
base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
change-id: 20250407-fix_nvidia-a9d72c98a808

Best regards,
-- 
Zijun Hu <quic_zijuhu@quicinc.com>


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

* Re: [PATCH] fbdev/nvidiafb: Correct const string length in nvidiafb_setup()
  2025-04-07 11:55 [PATCH] fbdev/nvidiafb: Correct const string length in nvidiafb_setup() Zijun Hu
@ 2025-04-24 22:18 ` Helge Deller
  2025-04-25  8:55 ` Jani Nikula
  1 sibling, 0 replies; 4+ messages in thread
From: Helge Deller @ 2025-04-24 22:18 UTC (permalink / raw)
  To: Zijun Hu, Antonino Daplas; +Cc: linux-fbdev, dri-devel, linux-kernel, Zijun Hu

On 4/7/25 13:55, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> The actual length of const string "noaccel" is 7, but the strncmp()
> branch in nvidiafb_setup() wrongly hard codes it as 6.
> 
> Fix by using actual length 7 as argument of the strncmp().
> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
>   drivers/video/fbdev/nvidia/nvidia.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

applied.

Thanks!
Helge

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

* Re: [PATCH] fbdev/nvidiafb: Correct const string length in nvidiafb_setup()
  2025-04-07 11:55 [PATCH] fbdev/nvidiafb: Correct const string length in nvidiafb_setup() Zijun Hu
  2025-04-24 22:18 ` Helge Deller
@ 2025-04-25  8:55 ` Jani Nikula
  2025-04-25 11:21   ` Zijun Hu
  1 sibling, 1 reply; 4+ messages in thread
From: Jani Nikula @ 2025-04-25  8:55 UTC (permalink / raw)
  To: Zijun Hu, Antonino Daplas, Helge Deller
  Cc: Zijun Hu, linux-fbdev, dri-devel, linux-kernel, Zijun Hu

On Mon, 07 Apr 2025, Zijun Hu <zijun_hu@icloud.com> wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
>
> The actual length of const string "noaccel" is 7, but the strncmp()
> branch in nvidiafb_setup() wrongly hard codes it as 6.
>
> Fix by using actual length 7 as argument of the strncmp().
>
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
>  drivers/video/fbdev/nvidia/nvidia.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
> index 8900f181f1952acd2acc16a6ab49a5a42ec056ac..cfaf9454014d8161bedc3598fb68855e04ea9408 100644
> --- a/drivers/video/fbdev/nvidia/nvidia.c
> +++ b/drivers/video/fbdev/nvidia/nvidia.c
> @@ -1484,7 +1484,7 @@ static int nvidiafb_setup(char *options)
>  			flatpanel = 1;
>  		} else if (!strncmp(this_opt, "hwcur", 5)) {
>  			hwcur = 1;
> -		} else if (!strncmp(this_opt, "noaccel", 6)) {
> +		} else if (!strncmp(this_opt, "noaccel", 7)) {
>  			noaccel = 1;
>  		} else if (!strncmp(this_opt, "noscale", 7)) {
>  			noscale = 1;

A further cleanup could be to replace all of the strncmp's with
str_has_prefix(this_opt, "...") to avoid this class of errors
altogether. It also returns the length of the prefix on match, and that
can be used to drop more magic numbers.

BR,
Jani.

>
> ---
> base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
> change-id: 20250407-fix_nvidia-a9d72c98a808
>
> Best regards,

-- 
Jani Nikula, Intel

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

* Re: [PATCH] fbdev/nvidiafb: Correct const string length in nvidiafb_setup()
  2025-04-25  8:55 ` Jani Nikula
@ 2025-04-25 11:21   ` Zijun Hu
  0 siblings, 0 replies; 4+ messages in thread
From: Zijun Hu @ 2025-04-25 11:21 UTC (permalink / raw)
  To: Jani Nikula, Antonino Daplas, Helge Deller
  Cc: linux-fbdev, dri-devel, linux-kernel, Zijun Hu

On 2025/4/25 16:55, Jani Nikula wrote:
>>  		} else if (!strncmp(this_opt, "noscale", 7)) {
>>  			noscale = 1;
> A further cleanup could be to replace all of the strncmp's with
> str_has_prefix(this_opt, "...") to avoid this class of errors
> altogether. It also returns the length of the prefix on match, and that
> can be used to drop more magic numbers.

very agree with your point. may use strstarts().

there are many strncmp() usages with long const string and hardcoded
string length. some usages are wrong.




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

end of thread, other threads:[~2025-04-25 11:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-07 11:55 [PATCH] fbdev/nvidiafb: Correct const string length in nvidiafb_setup() Zijun Hu
2025-04-24 22:18 ` Helge Deller
2025-04-25  8:55 ` Jani Nikula
2025-04-25 11:21   ` Zijun Hu

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