* [PATCH v1 1/4] string: Add streq()
2026-11-15 18:46 [PATCH v1 0/4] Add streq(3), and use it to replace confusing uses of strncmp(3) Alejandro Colomar
@ 2026-11-15 18:46 ` Alejandro Colomar
2026-11-15 18:46 ` [PATCH v1 2/4] tools/: Add streq() to nolibc/string Alejandro Colomar
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Alejandro Colomar @ 2026-11-15 18:46 UTC (permalink / raw)
To: linux-hardening
Cc: Alejandro Colomar, alx+linux-hardening, Kees Cook,
Andy Shevchenko
[-- Attachment #1: Type: text/plain, Size: 3184 bytes --]
The return value of strcmp(3) being reversed makes it prone to mistakes.
Since most of the time we're only interested in simple equality, add
this API for those cases.
This removes some driver-specific definitions of streq(3).
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
drivers/clk/socfpga/clk-gate-a10.c | 2 --
drivers/clk/socfpga/clk.h | 1 -
include/linux/string.h | 12 ++++++++++++
lib/tests/string_kunit.c | 13 +++++++++++++
4 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/drivers/clk/socfpga/clk-gate-a10.c b/drivers/clk/socfpga/clk-gate-a10.c
index ba12179061b3..df9f660db8a0 100644
--- a/drivers/clk/socfpga/clk-gate-a10.c
+++ b/drivers/clk/socfpga/clk-gate-a10.c
@@ -11,8 +11,6 @@
#include "clk.h"
-#define streq(a, b) (strcmp((a), (b)) == 0)
-
#define to_socfpga_gate_clk(p) container_of(p, struct socfpga_gate_clk, hw.hw)
/* SDMMC Group for System Manager defines */
diff --git a/drivers/clk/socfpga/clk.h b/drivers/clk/socfpga/clk.h
index 9a2fb2dde5b8..2008e6f34a5d 100644
--- a/drivers/clk/socfpga/clk.h
+++ b/drivers/clk/socfpga/clk.h
@@ -19,7 +19,6 @@
#define SOCFPGA_MAX_PARENTS 5
-#define streq(a, b) (strcmp((a), (b)) == 0)
#define SYSMGR_SDMMC_CTRL_SET(smplsel, drvsel) \
((((smplsel) & 0x7) << 3) | (((drvsel) & 0x7) << 0))
diff --git a/include/linux/string.h b/include/linux/string.h
index 6cb5cdd01158..9b3e578d9aca 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -14,6 +14,18 @@
#include <linux/stdarg.h>
#include <uapi/linux/string.h>
+/**
+ * streq - strings equal
+ *
+ * @s1: string to compare
+ * @s2: string to compare
+ *
+ * Compare two strings for equality.
+ *
+ * Return: true iff the strings are equal
+ */
+#define streq(s1, s2) (strcmp(s1, s2) == 0)
+
extern char *strndup_user(const char __user *, long);
extern void *memdup_user(const void __user *, size_t) __realloc_size(2);
extern void *vmemdup_user(const void __user *, size_t) __realloc_size(2);
diff --git a/lib/tests/string_kunit.c b/lib/tests/string_kunit.c
index 0819ace5b027..f84a60d4414c 100644
--- a/lib/tests/string_kunit.c
+++ b/lib/tests/string_kunit.c
@@ -287,6 +287,18 @@ static void string_test_strspn(struct kunit *test)
}
}
+static void string_test_streq(struct kunit *test)
+{
+ KUNIT_ASSERT_TRUE(test, streq("foo", "foo"));
+ KUNIT_ASSERT_TRUE(test, streq("", ""));
+
+ KUNIT_ASSERT_FALSE(test, streq("foo", "foobar"));
+ KUNIT_ASSERT_FALSE(test, streq("foobar", "foo"));
+ KUNIT_ASSERT_FALSE(test, streq("foo", "bar"));
+ KUNIT_ASSERT_FALSE(test, streq("foo", ""));
+ KUNIT_ASSERT_FALSE(test, streq("", "bar"));
+}
+
static char strcmp_buffer1[STRCMP_LARGE_BUF_LEN];
static char strcmp_buffer2[STRCMP_LARGE_BUF_LEN];
@@ -891,6 +903,7 @@ static struct kunit_case string_test_cases[] = {
KUNIT_CASE(string_test_strnchr),
KUNIT_CASE(string_test_strrchr),
KUNIT_CASE(string_test_strspn),
+ KUNIT_CASE(string_test_streq),
KUNIT_CASE(string_test_strcmp),
KUNIT_CASE(string_test_strcmp_long_strings),
KUNIT_CASE(string_test_strncmp),
--
2.55.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v1 2/4] tools/: Add streq() to nolibc/string
2026-11-15 18:46 [PATCH v1 0/4] Add streq(3), and use it to replace confusing uses of strncmp(3) Alejandro Colomar
2026-11-15 18:46 ` [PATCH v1 1/4] string: Add streq() Alejandro Colomar
@ 2026-11-15 18:46 ` Alejandro Colomar
2026-11-15 18:46 ` [PATCH v1 3/4] treewide: Use streq(3) instead of confusing uses of strncmp(3) Alejandro Colomar
2026-11-15 18:46 ` [PATCH v1 4/4] treewide: Use streq(3) instead of unnecessary " Alejandro Colomar
3 siblings, 0 replies; 5+ messages in thread
From: Alejandro Colomar @ 2026-11-15 18:46 UTC (permalink / raw)
To: linux-hardening
Cc: Alejandro Colomar, alx+linux-hardening, Kees Cook,
Andy Shevchenko
[-- Attachment #1: Type: text/plain, Size: 1799 bytes --]
It's more readable than strcmp(3).
This de-duplicates the existing definitions of streq().
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
tools/include/nolibc/string.h | 2 ++
tools/testing/selftests/proc/proc-subset-pid.c | 5 -----
tools/testing/selftests/proc/proc.h | 5 -----
3 files changed, 2 insertions(+), 10 deletions(-)
diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h
index 4000926f44ac..53137fb56213 100644
--- a/tools/include/nolibc/string.h
+++ b/tools/include/nolibc/string.h
@@ -130,6 +130,8 @@ int strcmp(const char *a, const char *b)
return diff;
}
+#define streq(a, b) (strcmp(a, b) == 0)
+
static __attribute__((unused))
char *strcpy(char *dst, const char *src)
{
diff --git a/tools/testing/selftests/proc/proc-subset-pid.c b/tools/testing/selftests/proc/proc-subset-pid.c
index d1052bcab039..1f41fcb89f5f 100644
--- a/tools/testing/selftests/proc/proc-subset-pid.c
+++ b/tools/testing/selftests/proc/proc-subset-pid.c
@@ -32,11 +32,6 @@
#include <unistd.h>
#include <stdio.h>
-static inline bool streq(const char *a, const char *b)
-{
- return strcmp(a, b) == 0;
-}
-
static void make_private_proc(void)
{
if (unshare(CLONE_NEWNS) == -1) {
diff --git a/tools/testing/selftests/proc/proc.h b/tools/testing/selftests/proc/proc.h
index b7d57ea40237..85ac9d4c9cf8 100644
--- a/tools/testing/selftests/proc/proc.h
+++ b/tools/testing/selftests/proc/proc.h
@@ -19,11 +19,6 @@ static inline pid_t sys_gettid(void)
return syscall(SYS_gettid);
}
-static inline bool streq(const char *s1, const char *s2)
-{
- return strcmp(s1, s2) == 0;
-}
-
static unsigned long long xstrtoull(const char *p, char **end)
{
if (*p == '0') {
--
2.55.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v1 3/4] treewide: Use streq(3) instead of confusing uses of strncmp(3)
2026-11-15 18:46 [PATCH v1 0/4] Add streq(3), and use it to replace confusing uses of strncmp(3) Alejandro Colomar
2026-11-15 18:46 ` [PATCH v1 1/4] string: Add streq() Alejandro Colomar
2026-11-15 18:46 ` [PATCH v1 2/4] tools/: Add streq() to nolibc/string Alejandro Colomar
@ 2026-11-15 18:46 ` Alejandro Colomar
2026-11-15 18:46 ` [PATCH v1 4/4] treewide: Use streq(3) instead of unnecessary " Alejandro Colomar
3 siblings, 0 replies; 5+ messages in thread
From: Alejandro Colomar @ 2026-11-15 18:46 UTC (permalink / raw)
To: linux-hardening
Cc: Alejandro Colomar, alx+linux-hardening, Kees Cook,
Andy Shevchenko
[-- Attachment #1: Type: text/plain, Size: 7388 bytes --]
Uses of strncmp(a, b, N) where N==strlen(b)+1 are really the same as
strcmp(a,b). It's hard to distinguish whether the strcmp(3) behavior
was intentional, or it strstarts() behavior was intended.
This code seems to have been confused, and probably thought using
strncmp(3) was somehow safer than strcmp(3), but it is not.
Let's rewrite with streq(3), which makes it more readable.
This patch is not changing the behavior of the existing code.
If any of these was actually a bug and intended to write strstarts(),
that should be fixed in a separate patch.
These cases were found with the following script:
$ seq 20 \
| while read n; do
git grep -E 'strncmp\([^,]*, "[^"]{'"$n"'}", '"$(expr 1 + $n)"'\)';
done;
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
arch/arm/mach-omap2/sr_device.c | 8 ++++----
arch/mips/bcm47xx/time.c | 2 +-
arch/powerpc/kernel/security.c | 2 +-
drivers/net/ethernet/intel/i40e/i40e_ddp.c | 2 +-
fs/ocfs2/filecheck.c | 6 +++---
net/netfilter/xt_set.c | 2 +-
tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c | 8 ++++----
tools/testing/selftests/kvm/steal_time.c | 2 +-
tools/testing/selftests/kvm/x86/xen_shinfo_test.c | 4 ++--
9 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/arch/arm/mach-omap2/sr_device.c b/arch/arm/mach-omap2/sr_device.c
index 758d90e0340b..dfc27dc25293 100644
--- a/arch/arm/mach-omap2/sr_device.c
+++ b/arch/arm/mach-omap2/sr_device.c
@@ -92,12 +92,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 (streq(name, "smartreflex_mpu_iva") ||
+ streq(name, "smartreflex_mpu"))
sr_data = &omap_sr_pdata[OMAP_SR_MPU];
- else if (!strncmp(name, "smartreflex_core", 17))
+ else if (streq(name, "smartreflex_core"))
sr_data = &omap_sr_pdata[OMAP_SR_CORE];
- else if (!strncmp(name, "smartreflex_iva", 16))
+ else if (streq(name, "smartreflex_iva"))
sr_data = &omap_sr_pdata[OMAP_SR_IVA];
if (!sr_data) {
diff --git a/arch/mips/bcm47xx/time.c b/arch/mips/bcm47xx/time.c
index 74224cf2e84d..6ab6f55ce47e 100644
--- a/arch/mips/bcm47xx/time.c
+++ b/arch/mips/bcm47xx/time.c
@@ -60,7 +60,7 @@ void __init plat_time_init(void)
if (chip_id == 0x5354) {
len = bcm47xx_nvram_getenv("clkfreq", buf, sizeof(buf));
- if (len >= 0 && !strncmp(buf, "200", 4))
+ if (len >= 0 && streq(buf, "200"))
hz = 100000000;
}
diff --git a/arch/powerpc/kernel/security.c b/arch/powerpc/kernel/security.c
index 600596cb4ffb..8c1484ae6c21 100644
--- a/arch/powerpc/kernel/security.c
+++ b/arch/powerpc/kernel/security.c
@@ -273,7 +273,7 @@ enum stf_barrier_type stf_barrier_type_get(void)
/* This is the generic flag used by other architectures */
static int __init handle_ssbd(char *p)
{
- if (!p || strncmp(p, "auto", 5) == 0 || strncmp(p, "on", 2) == 0 ) {
+ if (!p || streq(p, "auto") || strncmp(p, "on", 2) == 0 ) {
/* Until firmware tells us, we have the barrier with auto */
return 0;
} else if (strncmp(p, "off", 3) == 0) {
diff --git a/drivers/net/ethernet/intel/i40e/i40e_ddp.c b/drivers/net/ethernet/intel/i40e/i40e_ddp.c
index daa9f2c42f70..c84eddf98b06 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_ddp.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_ddp.c
@@ -452,7 +452,7 @@ int i40e_ddp_flash(struct net_device *netdev, struct ethtool_flash *flash)
/* If the user supplied "-" instead of file name rollback previously
* stored profile.
*/
- if (strncmp(flash->data, "-", 2) != 0) {
+ if (!streq(flash->data, "-")) {
struct i40e_ddp_old_profile_list *list_entry;
char profile_name[sizeof(I40E_DDP_PROFILE_PATH)
+ I40E_DDP_PROFILE_NAME_MAX];
diff --git a/fs/ocfs2/filecheck.c b/fs/ocfs2/filecheck.c
index 75334e4bd082..3fcd538ff2c5 100644
--- a/fs/ocfs2/filecheck.c
+++ b/fs/ocfs2/filecheck.c
@@ -258,11 +258,11 @@ ocfs2_filecheck_args_get_long(const char *buf, size_t count,
static int
ocfs2_filecheck_type_parse(const char *name, unsigned int *type)
{
- if (!strncmp(name, "fix", 4))
+ if (streq(name, "fix"))
*type = OCFS2_FILECHECK_TYPE_FIX;
- else if (!strncmp(name, "check", 6))
+ else if (streq(name, "check"))
*type = OCFS2_FILECHECK_TYPE_CHK;
- else if (!strncmp(name, "set", 4))
+ else if (streq(name, "set"))
*type = OCFS2_FILECHECK_TYPE_SET;
else
return 1;
diff --git a/net/netfilter/xt_set.c b/net/netfilter/xt_set.c
index 4ae04bba9358..6f4e306196fe 100644
--- a/net/netfilter/xt_set.c
+++ b/net/netfilter/xt_set.c
@@ -436,7 +436,7 @@ set_target_v3_check_hooks(const struct xt_tgchk_param *par)
const struct xt_set_info_target_v3 *info = par->targinfo;
if (info->map_set.index != IPSET_INVALID_ID) {
- if (strncmp(par->table, "mangle", 7)) {
+ if (!streq(par->table, "mangle")) {
pr_info_ratelimited("--map-set only usable from mangle table\n");
return -EINVAL;
}
diff --git a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
index 1d49df671919..af4692942810 100644
--- a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
+++ b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
@@ -507,9 +507,9 @@ static int numer_of_heaps(void)
int heaps = 0;
while ((dir = readdir(d))) {
- if (!strncmp(dir->d_name, ".", 2))
+ if (streq(dir->d_name, "."))
continue;
- if (!strncmp(dir->d_name, "..", 3))
+ if (streq(dir->d_name, ".."))
continue;
heaps++;
}
@@ -533,9 +533,9 @@ int main(void)
ksft_set_plan(12 * numer_of_heaps());
while ((dir = readdir(d))) {
- if (!strncmp(dir->d_name, ".", 2))
+ if (streq(dir->d_name, "."))
continue;
- if (!strncmp(dir->d_name, "..", 3))
+ if (streq(dir->d_name, ".."))
continue;
ksft_print_msg("Testing heap: %s\n", dir->d_name);
diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
index 82b94a82dd03..64327e8fbd78 100644
--- a/tools/testing/selftests/kvm/steal_time.c
+++ b/tools/testing/selftests/kvm/steal_time.c
@@ -526,7 +526,7 @@ int main(int ac, char **av)
bool verbose;
int i, cpu;
- verbose = ac > 1 && (!strncmp(av[1], "-v", 3) || !strncmp(av[1], "--verbose", 10));
+ verbose = ac > 1 && (streq(av[1], "-v") || streq(av[1], "--verbose"));
/* Set CPU affinity so we can force preemption of the VCPU */
cpu = pin_self_to_any_cpu();
diff --git a/tools/testing/selftests/kvm/x86/xen_shinfo_test.c b/tools/testing/selftests/kvm/x86/xen_shinfo_test.c
index aaa414c677ad..e254720df86f 100644
--- a/tools/testing/selftests/kvm/x86/xen_shinfo_test.c
+++ b/tools/testing/selftests/kvm/x86/xen_shinfo_test.c
@@ -438,8 +438,8 @@ int main(int argc, char *argv[])
pthread_t thread;
bool verbose;
- verbose = argc > 1 && (!strncmp(argv[1], "-v", 3) ||
- !strncmp(argv[1], "--verbose", 10));
+ verbose = argc > 1 && (streq(argv[1], "-v") ||
+ streq(argv[1], "--verbose"));
int xen_caps = kvm_check_cap(KVM_CAP_XEN_HVM);
TEST_REQUIRE(xen_caps & KVM_XEN_HVM_CONFIG_SHARED_INFO);
--
2.55.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v1 4/4] treewide: Use streq(3) instead of unnecessary uses of strncmp(3)
2026-11-15 18:46 [PATCH v1 0/4] Add streq(3), and use it to replace confusing uses of strncmp(3) Alejandro Colomar
` (2 preceding siblings ...)
2026-11-15 18:46 ` [PATCH v1 3/4] treewide: Use streq(3) instead of confusing uses of strncmp(3) Alejandro Colomar
@ 2026-11-15 18:46 ` Alejandro Colomar
3 siblings, 0 replies; 5+ messages in thread
From: Alejandro Colomar @ 2026-11-15 18:46 UTC (permalink / raw)
To: linux-hardening
Cc: Alejandro Colomar, alx+linux-hardening, Kees Cook,
Andy Shevchenko
[-- Attachment #1: Type: text/plain, Size: 10182 bytes --]
Uses of strncmp(foo,"bar",sizeof("bar")) are really the same as
strcmp(foo,"bar"). There's no good reason to use strncmp(3).
This code seems to have been confused, and probably thought using
strncmp(3) was somehow safer than strcmp(3), but it is not.
Let's rewrite with streq(3), which makes it more readable.
This patch is not changing the behavior of the existing code.
These cases were found with the following script:
$ git grep -E 'strncmp\([^,]*, [^,]*, sizeof.*[A-Z"]' \
| grep -v -- '- 1';
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
arch/m68k/sun3/prom/console.c | 6 +++---
drivers/edac/amd64_edac.c | 2 +-
drivers/edac/i10nm_base.c | 2 +-
drivers/edac/igen6_edac.c | 2 +-
drivers/edac/imh_base.c | 2 +-
drivers/edac/pnd2_edac.c | 2 +-
drivers/edac/sb_edac.c | 2 +-
drivers/edac/skx_base.c | 2 +-
drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 2 +-
include/linux/remoteproc/pruss.h | 2 +-
sound/hda/codecs/side-codecs/tas2781_hda_i2c.c | 2 +-
tools/bpf/bpftool/btf.c | 4 ++--
tools/perf/util/callchain.c | 8 ++++----
tools/perf/util/evsel.c | 3 +--
14 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/arch/m68k/sun3/prom/console.c b/arch/m68k/sun3/prom/console.c
index eb4f6c903fb8..f54a52b1e8d2 100644
--- a/arch/m68k/sun3/prom/console.c
+++ b/arch/m68k/sun3/prom/console.c
@@ -92,7 +92,7 @@ prom_query_input_device()
if(prom_node_has_property(st_p, "keyboard"))
return PROMDEV_IKBD;
prom_getproperty(st_p, "device_type", propb, sizeof(propb));
- if(strncmp(propb, "serial", sizeof("serial")))
+ if(!streq(propb, "serial"))
return PROMDEV_I_UNK;
prom_getproperty(prom_root_node, "stdin-path", propb, sizeof(propb));
p = propb;
@@ -139,12 +139,12 @@ prom_query_output_device()
local_irq_restore(flags);
propl = prom_getproperty(st_p, "device_type", propb, sizeof(propb));
if (propl >= 0 && propl == sizeof("display") &&
- strncmp("display", propb, sizeof("display")) == 0)
+ streq("display", propb))
{
return PROMDEV_OSCREEN;
}
if(prom_vers == PROM_V3) {
- if(strncmp("serial", propb, sizeof("serial")))
+ if(!streq("serial", propb))
return PROMDEV_O_UNK;
prom_getproperty(prom_root_node, "stdout-path", propb, sizeof(propb));
p = propb;
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index 0c0d11c72925..19bba83a900f 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -4137,7 +4137,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 && !streq(owner, EDAC_MOD_STR))
return -EBUSY;
if (!x86_match_cpu(amd64_cpuids))
diff --git a/drivers/edac/i10nm_base.c b/drivers/edac/i10nm_base.c
index 87e541c3bf4b..338101240c8d 100644
--- a/drivers/edac/i10nm_base.c
+++ b/drivers/edac/i10nm_base.c
@@ -938,7 +938,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 && !streq(owner, EDAC_MOD_STR))
return -EBUSY;
if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
diff --git a/drivers/edac/igen6_edac.c b/drivers/edac/igen6_edac.c
index 776c5db2f598..4225ad0ae13f 100644
--- a/drivers/edac/igen6_edac.c
+++ b/drivers/edac/igen6_edac.c
@@ -1990,7 +1990,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 && !streq(owner, EDAC_MOD_STR))
return -EBUSY;
rc = pci_register_driver(&igen6_driver);
diff --git a/drivers/edac/imh_base.c b/drivers/edac/imh_base.c
index 6ca0df031bf5..5fbbd5dc69f3 100644
--- a/drivers/edac/imh_base.c
+++ b/drivers/edac/imh_base.c
@@ -543,7 +543,7 @@ static int __init imh_init(void)
return -EBUSY;
owner = edac_get_owner();
- if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR)))
+ if (owner && !streq(owner, EDAC_MOD_STR))
return -EBUSY;
if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
diff --git a/drivers/edac/pnd2_edac.c b/drivers/edac/pnd2_edac.c
index ea208c637113..5f2bbf2a89e4 100644
--- a/drivers/edac/pnd2_edac.c
+++ b/drivers/edac/pnd2_edac.c
@@ -1528,7 +1528,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 && !streq(owner, EDAC_MOD_STR))
return -EBUSY;
if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
index 6e248855a549..38948fd88c16 100644
--- a/drivers/edac/sb_edac.c
+++ b/drivers/edac/sb_edac.c
@@ -3629,7 +3629,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 && !streq(owner, EDAC_MOD_STR))
return -EBUSY;
if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
diff --git a/drivers/edac/skx_base.c b/drivers/edac/skx_base.c
index ae2fda006632..2fcb766527e0 100644
--- a/drivers/edac/skx_base.c
+++ b/drivers/edac/skx_base.c
@@ -612,7 +612,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 && !streq(owner, EDAC_MOD_STR))
return -EBUSY;
if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
diff --git a/drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c b/drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c
index 7583b6ebba2a..9201080106ba 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c
@@ -74,7 +74,7 @@ static int __init tilcdc_panel_copy_props(struct device_node *old_panel,
/* Copy all panel properties to the new panel node */
for_each_property_of_node(old_panel, prop) {
- if (!strncmp(prop->name, "compatible", sizeof("compatible")))
+ if (streq(prop->name, "compatible"))
continue;
ret = tilcdc_panel_update_prop(&ocs, new_panel, prop->name,
diff --git a/include/linux/remoteproc/pruss.h b/include/linux/remoteproc/pruss.h
index 039b50d58df2..0ff71e8ca016 100644
--- a/include/linux/remoteproc/pruss.h
+++ b/include/linux/remoteproc/pruss.h
@@ -74,7 +74,7 @@ static inline bool is_pru_rproc(struct device *dev)
{
const char *drv_name = dev_driver_string(dev);
- if (strncmp(drv_name, PRU_RPROC_DRVNAME, sizeof(PRU_RPROC_DRVNAME)))
+ if (!streq(drv_name, PRU_RPROC_DRVNAME))
return false;
return true;
diff --git a/sound/hda/codecs/side-codecs/tas2781_hda_i2c.c b/sound/hda/codecs/side-codecs/tas2781_hda_i2c.c
index 0c8faa583baa..28e33c9e960d 100644
--- a/sound/hda/codecs/side-codecs/tas2781_hda_i2c.c
+++ b/sound/hda/codecs/side-codecs/tas2781_hda_i2c.c
@@ -109,7 +109,7 @@ static int tas2781_read_acpi(struct tasdevice_priv *p, const char *hid)
sub = acpi_get_subsystem_id(ACPI_HANDLE(physdev));
if (IS_ERR(sub)) {
/* No subsys id in older tas2563 projects. */
- if (!strncmp(hid, "INT8866", sizeof("INT8866"))) {
+ if (streq(hid, "INT8866")) {
p->speaker_id = -1;
goto end_2563;
}
diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index abd661db91e6..0a38e7f5cebb 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -860,13 +860,13 @@ static int dump_btf_kfuncs(struct btf_dump *d, const struct btf *btf)
continue;
name = btf__name_by_offset(btf, t->name_off);
- if (strncmp(name, KFUNC_DECL_TAG, sizeof(KFUNC_DECL_TAG)) == 0) {
+ if (streq(name, KFUNC_DECL_TAG)) {
err = ptr_array_push(ft, &kfuncs);
if (err)
goto out;
}
- if (strncmp(name, FASTCALL_DECL_TAG, sizeof(FASTCALL_DECL_TAG)) == 0) {
+ if (streq(name, FASTCALL_DECL_TAG)) {
err = ptr_array_push(ft, &fastcalls);
if (err)
goto out;
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 31c675cbab63..bcdb5da09b1f 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -277,7 +277,7 @@ int parse_callchain_record(const char *arg, struct callchain_param *param)
do {
/* Framepointer style */
- if (!strncmp(name, "fp", sizeof("fp"))) {
+ if (streq(name, "fp")) {
ret = 0;
param->record_mode = CALLCHAIN_FP;
@@ -285,7 +285,7 @@ int parse_callchain_record(const char *arg, struct callchain_param *param)
if (tok) {
unsigned long size;
- if (!strncmp(tok, "defer", sizeof("defer"))) {
+ if (streq(tok, "defer")) {
param->defer = true;
} else {
size = strtoul(tok, &name, 0);
@@ -296,7 +296,7 @@ int parse_callchain_record(const char *arg, struct callchain_param *param)
break;
/* Dwarf style */
- } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) {
+ } else if (streq(name, "dwarf")) {
const unsigned long default_stack_dump_size = 8192;
ret = 0;
@@ -311,7 +311,7 @@ int parse_callchain_record(const char *arg, struct callchain_param *param)
ret = get_stack_size(tok, &size);
param->dump_size = size;
}
- } else if (!strncmp(name, "lbr", sizeof("lbr"))) {
+ } else if (streq(name, "lbr")) {
if (!strtok_r(NULL, ",", &saveptr)) {
param->record_mode = CALLCHAIN_LBR;
ret = 0;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index d060fca8090f..a40ca32fdaf7 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -445,8 +445,7 @@ bool evsel__is_function_event(struct evsel *evsel)
{
#define FUNCTION_EVENT "ftrace:function"
- return evsel->name &&
- !strncmp(FUNCTION_EVENT, evsel->name, sizeof(FUNCTION_EVENT));
+ return evsel->name && streq(FUNCTION_EVENT, evsel->name);
#undef FUNCTION_EVENT
}
--
2.55.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 5+ messages in thread