staging: nvec: use strcmp() instead of strncmp() with magic length
Subsystems (3)
PATCH 1/1 staging: nvec: use strcmp() instead of strncmp() with magic length
Replace strncmp() with a hardcoded length of 30 with strcmp(). The bat_type string is already null-terminated (set two lines above), so strncmp() with an arbitrary length is misleading and functionally equivalent to strcmp().
--- drivers/staging/nvec/nvec_power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/nvec/nvec_power.c +1 -1
@@ -207,7 +207,7 @@ static int nvec_power_bat_notifier(struct notifier_block *nb,* This differs a little from the spec fill in more if you find * some. */ -if (!strncmp (power->bat_type,"Li" ,30 )) +if (!strcmp (power->bat_type,"Li" )) power->bat_type_enum =POWER_SUPPLY_TECHNOLOGY_LION ;else power->bat_type_enum =POWER_SUPPLY_TECHNOLOGY_UNKNOWN ;
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerQuoted 15 lines · Artem Lytkin
Replace
strncmp()with a hardcoded length of 30 withstrcmp(). Thebat_typestring is already null-terminated (set two lines above), sostrncmp()with an arbitrary length is misleading and functionally equivalent tostrcmp().Signed-off-by Artem Lytkin <[email protected]>--- drivers/staging/nvec/nvec_power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/nvec/nvec_power.c +0
-0
drivers/staging/nvec/nvec_power.c static int nvec_power_bat_notifier(struct notifier_block *nb, · line 210
Quoted 5 lines
drivers/staging/nvec/nvec_power.c +1
-1@@ -207,7 +207,7 @@ static int nvec_power_bat_notifier(struct notifier_block *nb,* This differs a little from the spec fill in more if you find * some. */ -if (!strncmp (power->bat_type,"Li" ,30 )) +if (!strcmp (power->bat_type,"Li" ))
Now the checking tools that look for "strcmp() is bad!" will come along and someone will send a patch that essencially reverts this :)
Please just leave this as-is, it's really fine and is not broken, right?
thanks,
greg k-h