drivers: correct parameters passed to strncmp

From: Seija K.
Date: Mon Dec 12 2022 - 10:38:22 EST


commit 599072f16ad675aaf6c1f87ca5be129725ce2728
Author: Seija Kijin <doremylover123@xxxxxxxxx>
Date: Sun Dec 11 22:01:46 2022 -0500

drivers: correct parameters passed to strncmp
Many times when strncmp is called with the intent of ignoring the NULL
terminator, the null terminator is accidentally included in that
comparison, which in practice is just an strcmp with extra steps.
Subtract from the places where the intent seems to be to do a
comparison without the NULL terminator.
Signed-off-by: Seija Kijin <doremylover123@xxxxxxxxx>

diff --git a/arch/arm/mach-omap2/sr_device.c b/arch/arm/mach-omap2/sr_device.c
index db672cf19a51..883f3078e233 100644
--- a/arch/arm/mach-omap2/sr_device.c
+++ b/arch/arm/mach-omap2/sr_device.c
@@ -94,12 +94,12 @@ static int __init sr_init_by_name(const char
*name, const char *voltdm)
struct omap_volt_data *volt_data;
static int i;
- if (!strncmp(name, "smartreflex_mpu_iva", 20) ||
- !strncmp(name, "smartreflex_mpu", 16))
+ if (!strncmp(name, "smartreflex_mpu_iva", 19) ||
+ !strncmp(name, "smartreflex_mpu", 15))
sr_data = &omap_sr_pdata[OMAP_SR_MPU];
- else if (!strncmp(name, "smartreflex_core", 17))
+ else if (!strncmp(name, "smartreflex_core", 16))
sr_data = &omap_sr_pdata[OMAP_SR_CORE];
- else if (!strncmp(name, "smartreflex_iva", 16))
+ else if (!strncmp(name, "smartreflex_iva", 15))
sr_data = &omap_sr_pdata[OMAP_SR_IVA];
if (!sr_data) {
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index 2f854feeeb23..f25f97d73edc 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -4330,7 +4330,7 @@ static int __init amd64_edac_init(void)
int i;
owner = edac_get_owner();
- if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR)))
+ if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR) - 1))
return -EBUSY;
if (!x86_match_cpu(amd64_cpuids))
diff --git a/drivers/edac/i10nm_base.c b/drivers/edac/i10nm_base.c
index a22ea053f8e1..da3f02b97352 100644
--- a/drivers/edac/i10nm_base.c
+++ b/drivers/edac/i10nm_base.c
@@ -757,7 +757,7 @@ static int __init i10nm_init(void)
edac_dbg(2, "\n");
owner = edac_get_owner();
- if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR)))
+ if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR) - 1))
return -EBUSY;
if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
diff --git a/drivers/edac/igen6_edac.c b/drivers/edac/igen6_edac.c
index a07bbfd075d0..1ccb38dac56b 100644
--- a/drivers/edac/igen6_edac.c
+++ b/drivers/edac/igen6_edac.c
@@ -1272,7 +1272,7 @@ static int __init igen6_init(void)
edac_dbg(2, "\n");
owner = edac_get_owner();
- if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR)))
+ if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR) - 1))
return -ENODEV;
edac_op_state = EDAC_OPSTATE_NMI;
diff --git a/drivers/edac/pnd2_edac.c b/drivers/edac/pnd2_edac.c
index a20b299f1202..e7fa4deb6b57 100644
--- a/drivers/edac/pnd2_edac.c
+++ b/drivers/edac/pnd2_edac.c
@@ -1529,7 +1529,7 @@ static int __init pnd2_init(void)
edac_dbg(2, "\n");
owner = edac_get_owner();
- if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR)))
+ if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR) - 1))
return -EBUSY;
if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
index 8e39370fdb5c..4834c02fd241 100644
--- a/drivers/edac/sb_edac.c
+++ b/drivers/edac/sb_edac.c
@@ -3635,7 +3635,7 @@ static int __init sbridge_init(void)
edac_dbg(2, "\n");
owner = edac_get_owner();
- if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR)))
+ if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR) - 1))
return -EBUSY;
if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
diff --git a/drivers/edac/skx_base.c b/drivers/edac/skx_base.c
index 7e2762f62eec..adea8ff23f85 100644
--- a/drivers/edac/skx_base.c
+++ b/drivers/edac/skx_base.c
@@ -654,7 +654,7 @@ static int __init skx_init(void)
edac_dbg(2, "\n");
owner = edac_get_owner();
- if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR)))
+ if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR) - 1))
return -EBUSY;
if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
diff --git a/drivers/media/pci/bt8xx/bttv-cards.c
b/drivers/media/pci/bt8xx/bttv-cards.c
index c2b5ab287dd7..c24cc2f46d2f 100644
--- a/drivers/media/pci/bt8xx/bttv-cards.c
+++ b/drivers/media/pci/bt8xx/bttv-cards.c
@@ -2968,7 +2968,7 @@ static void identify_by_eeprom(struct bttv *btv,
unsigned char eeprom_data[256])
if (0 == strncmp(eeprom_data,"GET MM20xPCTV",13))
type = BTTV_BOARD_MODTEC_205;
- else if (0 == strncmp(eeprom_data+20,"Picolo",7))
+ else if (0 == strncmp(eeprom_data + 20, "Picolo", 6))
type = BTTV_BOARD_EURESYS_PICOLO;
else if (eeprom_data[0] == 0x84 && eeprom_data[2]== 0)
type = BTTV_BOARD_HAUPPAUGE; /* old bt848 */
diff --git a/drivers/net/ethernet/cavium/liquidio/lio_main.c
b/drivers/net/ethernet/cavium/liquidio/lio_main.c
index 98793b2ac2c7..795c44656ab3 100644
--- a/drivers/net/ethernet/cavium/liquidio/lio_main.c
+++ b/drivers/net/ethernet/cavium/liquidio/lio_main.c
@@ -912,7 +912,7 @@ liquidio_probe(struct pci_dev *pdev, const struct
pci_device_id __maybe_unused *
static bool fw_type_is_auto(void)
{
return strncmp(fw_type, LIO_FW_NAME_TYPE_AUTO,
- sizeof(LIO_FW_NAME_TYPE_AUTO)) == 0;
+ sizeof(LIO_FW_NAME_TYPE_AUTO) - 1) == 0;
}
/**
diff --git a/drivers/staging/nvec/nvec_power.c
b/drivers/staging/nvec/nvec_power.c
index b1ef196e1cfe..3ed9e06e32de 100644
--- a/drivers/staging/nvec/nvec_power.c
+++ b/drivers/staging/nvec/nvec_power.c
@@ -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 (!strncmp(power->bat_type, "Li", 2))
power->bat_type_enum = POWER_SUPPLY_TECHNOLOGY_LION;
else
power->bat_type_enum = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;