diff mbox series

drivers: correct parameters passed to strncmp

Message ID CAA42iKzuae0PL1qm20sU87D2V-GF8mMFPSjKJu=fB81RrZgZbg@mail.gmail.com
State New
Headers show
Series drivers: correct parameters passed to strncmp | expand

Commit Message

Seija K. Dec. 13, 2022, 1:36 a.m. UTC
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@gmail.com>

power->bat_type_enum = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
diff mbox series

Patch

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 e3318e5575a3..1d832f484f8d 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -4333,7 +4333,7 @@  static int __init amd64_edac_init(void)
return -EBUSY;
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 65aeea53e2df..546dd9fc5cc5 100644
--- a/drivers/edac/i10nm_base.c
+++ b/drivers/edac/i10nm_base.c
@@ -759,7 +759,7 @@  static int __init i10nm_init(void)
return -EBUSY;
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 544dd19072ea..7df2b3a82221 100644
--- a/drivers/edac/igen6_edac.c
+++ b/drivers/edac/igen6_edac.c
@@ -1275,7 +1275,7 @@  static int __init igen6_init(void)
return -EBUSY;
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;
edac_op_state = EDAC_OPSTATE_NMI;
diff --git a/drivers/edac/pnd2_edac.c b/drivers/edac/pnd2_edac.c
index 2b306f2cc605..08aeab382cb4 100644
--- a/drivers/edac/pnd2_edac.c
+++ b/drivers/edac/pnd2_edac.c
@@ -1532,7 +1532,7 @@  static int __init pnd2_init(void)
return -EBUSY;
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 0c779a0326b6..6f8904b55213 100644
--- a/drivers/edac/sb_edac.c
+++ b/drivers/edac/sb_edac.c
@@ -3638,7 +3638,7 @@  static int __init sbridge_init(void)
return -EBUSY;
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 9397abb42c49..ea38449710f5 100644
--- a/drivers/edac/skx_base.c
+++ b/drivers/edac/skx_base.c
@@ -657,7 +657,7 @@  static int __init skx_init(void)
return -EBUSY;
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