Skip to contentSkip to conversation

fbdev/nvidiafb: Correct const string length in nvidiafb_setup()

PATCH Applied Zijun Hu 3 participants 4 messages Apr 7, 2025 – Apr 25, 2025

Subsystems (2)
lore
Share & tools
lore

Zijun Hu

author
#0 lore raw

PATCH 1/1 fbdev/nvidiafb: Correct const string length in nvidiafb_setup()

From: Zijun Hu <[email protected]>

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

---
 drivers/video/fbdev/nvidia/nvidia.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/fbdev/nvidia/nvidia.c +1 -1
index 8900f181f1952acd2acc16a6ab49a5a42ec056ac..cfaf9454014d8161bedc3598fb68855e04ea9408 100644
@@ -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,

Signature · 1 line
Zijun Hu <[email protected]>
maintainer Applied
#1 lore raw
Quoted 11 lines · Zijun Hu

From: Zijun Hu <[email protected]>

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

---
  drivers/video/fbdev/nvidia/nvidia.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

applied.

Thanks!
Helge

#2 lore raw
In reply to Zijun Hu
Quoted 17 lines · Zijun Hu

From: Zijun Hu <[email protected]>

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

---
 drivers/video/fbdev/nvidia/nvidia.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/fbdev/nvidia/nvidia.c +0 -0
index 8900f181f1952acd2acc16a6ab49a5a42ec056ac..cfaf9454014d8161bedc3598fb68855e04ea9408 100644

drivers/video/fbdev/nvidia/nvidia.c static int nvidiafb_setup(char *options) · line 1490

Quoted 8 lines
drivers/video/fbdev/nvidia/nvidia.c +1 -1
@@ -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.

Quoted 6 lines

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

Best regards,

Signature · 1 line
Jani Nikula, Intel
author
#3 lore raw
Quoted 6 lines · Jani Nikula

drivers/video/fbdev/nvidia/nvidia.c static int nvidiafb_setup(char *options) · line 1490

Quoted 2 lines
drivers/video/fbdev/nvidia/nvidia.c +0 -0
 		} 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.