mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx@kernel.org>
To: linux-hardening@vger.kernel.org
Cc: Alejandro Colomar <alx@kernel.org>,
	 Krzysztof Kozlowski <krzk@kernel.org>,
	"Maciej W. Rozycki" <macro@orcam.me.uk>,
	 Geert Uytterhoeven <geert@linux-m68k.org>,
	Andreas Schwab <schwab@linux-m68k.org>,
	 Andy Shevchenko <andy@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>,
	 Daniel Scally <djrscally@gmail.com>,
	Danilo Krummrich <dakr@kernel.org>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	 Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Joe Perches <joe@perches.com>, Johan Hovold <johan@kernel.org>,
	 Kees Cook <kees@kernel.org>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	 Len Brown <lenb@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	 Linus Walleij <linusw@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	 "Rafael J. Wysocki" <rafael@kernel.org>,
	Rob Herring <robh@kernel.org>,
	 Sakari Ailus <sakari.ailus@linux.intel.com>,
	Saravana Kannan <saravanak@kernel.org>,
	 Steven Rostedt <rostedt@goodmis.org>,
	Tom Zanussi <zanussi@kernel.org>,
	linux-acpi@vger.kernel.org,  driver-core@lists.linux.dev,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	 linux-gpio@vger.kernel.org
Subject: [PATCH v6 14/19] treewide: Replace boolean uses of str_has_prefix() by strprefix()
Date: Sat, 14 Nov 2026 16:23:37 +0100	[thread overview]
Message-ID: <0c0070455de00eb63b43c6697555398fa5ef9d87.1794667407.git.alx@kernel.org> (raw)
In-Reply-To: <cover.1794667407.git.alx@kernel.org>

[-- Attachment #1: Type: text/plain, Size: 26894 bytes --]

str_has_prefix() doesn't work well for empty prefixes (see link below),
so this might actually fix some bugs silently where the prefix is an
empty string.

Link: https://lore.kernel.org/linux-hardening/20261104-fwnode-for-each-prop-v1-1-6e28fe1c72c4@oss.qualcomm.com/
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
 arch/alpha/kernel/setup.c                     |  2 +-
 arch/parisc/kernel/setup.c                    |  2 +-
 arch/powerpc/platforms/powernv/pci-ioda.c     |  2 +-
 arch/s390/kernel/early_printk.c               |  2 +-
 arch/s390/kernel/module.c                     |  6 ++---
 arch/s390/kernel/setup.c                      |  4 ++--
 arch/s390/lib/test_unwind.c                   |  6 ++---
 drivers/gpio/gpio-aggregator.c                |  2 +-
 drivers/gpu/drm/xe/xe_configfs.c              |  6 ++---
 drivers/iio/pressure/hsc030pa.c               |  2 +-
 drivers/md/dm-inlinecrypt.c                   |  2 +-
 drivers/media/i2c/ds90ub960.c                 |  2 +-
 drivers/remoteproc/mtk_scp.c                  |  2 +-
 .../media/atomisp/pci/atomisp_csi2_bridge.c   |  2 +-
 drivers/tty/serial/serial_base_bus.c          |  4 ++--
 kernel/debug/kdb/kdb_main.c                   |  2 +-
 kernel/kcsan/debugfs.c                        |  2 +-
 kernel/kcsan/report.c                         |  2 +-
 kernel/kprobes.c                              |  4 ++--
 kernel/locking/locktorture.c                  |  8 +++----
 kernel/power/main.c                           |  2 +-
 kernel/trace/trace_events.c                   |  2 +-
 kernel/trace/trace_events_hist.c              | 14 ++++++------
 kernel/trace/trace_events_synth.c             |  2 +-
 kernel/trace/trace_events_user.c              | 22 +++++++++----------
 kernel/trace/trace_probe.c                    | 22 +++++++++----------
 mm/arch_numa.c                                |  2 +-
 mm/kfence/report.c                            | 14 ++++++------
 sound/soc/sdw_utils/soc_sdw_senary_sdca.c     |  2 +-
 29 files changed, 73 insertions(+), 73 deletions(-)

diff --git a/arch/alpha/kernel/setup.c b/arch/alpha/kernel/setup.c
index 4cbcfb1852d5..79e63580b419 100644
--- a/arch/alpha/kernel/setup.c
+++ b/arch/alpha/kernel/setup.c
@@ -452,7 +452,7 @@ setup_arch(char **cmdline_p)
 #ifndef alpha_using_srm
 	/* Assume that we've booted from SRM if we haven't booted from MILO.
 	   Detect the later by looking for "MILO" in the system serial nr.  */
-	alpha_using_srm = !str_has_prefix((const char *)hwrpb->ssn, "MILO");
+	alpha_using_srm = !strprefix((const char *)hwrpb->ssn, "MILO");
 #endif
 #ifndef alpha_using_qemu
 	/* Similarly, look for QEMU.  */
diff --git a/arch/parisc/kernel/setup.c b/arch/parisc/kernel/setup.c
index 4d3015a411d6..6cd1b65276b5 100644
--- a/arch/parisc/kernel/setup.c
+++ b/arch/parisc/kernel/setup.c
@@ -56,7 +56,7 @@ static void __init setup_cmdline(char **cmdline_p)
 
 	/* autodetect console type (if not done by palo yet) */
 	p = boot_command_line;
-	if (!str_has_prefix(p, "console=") && !strstr(p, " console=")) {
+	if (!strprefix(p, "console=") && !strstr(p, " console=")) {
 		strlcat(p, " console=", COMMAND_LINE_SIZE);
 		if (PAGE0->mem_cons.cl_class == CL_DUPLEX)
 			strlcat(p, "ttyS0", COMMAND_LINE_SIZE);
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 728a5610d167..1cf0b4afe3df 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1629,7 +1629,7 @@ int64_t pnv_opal_pci_msi_eoi(struct irq_data *d)
  */
 bool is_pnv_opal_msi(struct irq_chip *chip)
 {
-	return chip && chip->name && str_has_prefix(chip->name, "PNV-");
+	return chip && chip->name && strprefix(chip->name, "PNV-");
 }
 EXPORT_SYMBOL_GPL(is_pnv_opal_msi);
 
diff --git a/arch/s390/kernel/early_printk.c b/arch/s390/kernel/early_printk.c
index cefe020a3be3..095e282c1e06 100644
--- a/arch/s390/kernel/early_printk.c
+++ b/arch/s390/kernel/early_printk.c
@@ -36,7 +36,7 @@ static int __init setup_early_printk(char *buf)
 	if (early_console)
 		return 0;
 	/* Accept only "earlyprintk" and "earlyprintk=sclp" */
-	if (buf && !str_has_prefix(buf, "sclp"))
+	if (buf && !strprefix(buf, "sclp"))
 		return 0;
 	register_early_console();
 	return 0;
diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
index 9d1f8a50f5a4..e9734d2b25f3 100644
--- a/arch/s390/kernel/module.c
+++ b/arch/s390/kernel/module.c
@@ -520,15 +520,15 @@ int module_finalize(const Elf_Ehdr *hdr,
 			apply_alternatives(aseg, aseg + s->sh_size);
 
 		if (IS_ENABLED(CONFIG_EXPOLINE) &&
-		    (str_has_prefix(secname, ".s390_indirect")))
+		    (strprefix(secname, ".s390_indirect")))
 			nospec_revert(aseg, aseg + s->sh_size);
 
 		if (IS_ENABLED(CONFIG_EXPOLINE) &&
-		    (str_has_prefix(secname, ".s390_return")))
+		    (strprefix(secname, ".s390_return")))
 			nospec_revert(aseg, aseg + s->sh_size);
 
 		if (IS_ENABLED(CONFIG_STACKPROTECTOR) &&
-		    (str_has_prefix(secname, "__stack_protector_loc"))) {
+		    (strprefix(secname, "__stack_protector_loc"))) {
 			rc = stack_protector_apply(aseg, aseg + s->sh_size);
 			if (rc)
 				break;
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index b60284328fe3..7074cdd58aa3 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -269,7 +269,7 @@ static void __init conmode_default(void)
 #endif
 			return;
 		}
-		if (str_has_prefix(ptr + 8, "3270")) {
+		if (strprefix(ptr + 8, "3270")) {
 #if defined(CONFIG_TN3270_CONSOLE)
 			SET_CONSOLE_3270;
 #elif defined(CONFIG_TN3215_CONSOLE)
@@ -277,7 +277,7 @@ static void __init conmode_default(void)
 #elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
 			SET_CONSOLE_SCLP;
 #endif
-		} else if (str_has_prefix(ptr + 8, "3215")) {
+		} else if (strprefix(ptr + 8, "3215")) {
 #if defined(CONFIG_TN3215_CONSOLE)
 			SET_CONSOLE_3215;
 #elif defined(CONFIG_TN3270_CONSOLE)
diff --git a/arch/s390/lib/test_unwind.c b/arch/s390/lib/test_unwind.c
index bb47958f5aed..8d6b6efe02fc 100644
--- a/arch/s390/lib/test_unwind.c
+++ b/arch/s390/lib/test_unwind.c
@@ -87,10 +87,10 @@ static noinline int test_unwind(struct task_struct *task, struct pt_regs *regs,
 				kunit_err(current_test, "backtrace buffer is too small\n");
 		}
 		frame_count += 1;
-		if (prev_is_func2 && str_has_prefix(sym, "unwindme_func1"))
+		if (prev_is_func2 && strprefix(sym, "unwindme_func1"))
 			seen_func2_func1 = true;
-		prev_is_func2 = str_has_prefix(sym, "unwindme_func2");
-		if (str_has_prefix(sym, "arch_rethook_trampoline+0x0/"))
+		prev_is_func2 = strprefix(sym, "unwindme_func2");
+		if (strprefix(sym, "arch_rethook_trampoline+0x0/"))
 			seen_arch_rethook_trampoline = true;
 	}
 
diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index b0b65416d74d..efa92e925461 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -1546,7 +1546,7 @@ static ssize_t gpio_aggregator_delete_device_store(struct device_driver *driver,
 	unsigned int id;
 	int error;
 
-	if (!str_has_prefix(buf, DRV_NAME "."))
+	if (!strprefix(buf, DRV_NAME "."))
 		return -EINVAL;
 
 	error = kstrtouint(buf + strlen(DRV_NAME "."), 10, &id);
diff --git a/drivers/gpu/drm/xe/xe_configfs.c b/drivers/gpu/drm/xe/xe_configfs.c
index 2ddd707a6dbd..8bd11f5bdfa1 100644
--- a/drivers/gpu/drm/xe/xe_configfs.c
+++ b/drivers/gpu/drm/xe/xe_configfs.c
@@ -521,7 +521,7 @@ static const struct engine_info *lookup_engine_info(const char *pattern, u64 *ma
 		u8 instance;
 		u16 bit;
 
-		if (!str_has_prefix(pattern, engine_info[i].cls))
+		if (!strprefix(pattern, engine_info[i].cls))
 			continue;
 
 		pattern += strlen(engine_info[i].cls);
@@ -836,7 +836,7 @@ static ssize_t parse_wa_bb_lines(const char *lines,
 		p += ret;
 		p += strspn(p, " \t");
 
-		if (str_has_prefix(p, "cmd")) {
+		if (strprefix(p, "cmd")) {
 			for (p += strlen("cmd"); *p;) {
 				ret = parse_hex(p, &val);
 				if (ret < 0)
@@ -848,7 +848,7 @@ static ssize_t parse_wa_bb_lines(const char *lines,
 				dwords++;
 				wa_bb_append(&wa_bb[info->engine_class], val);
 			}
-		} else if (str_has_prefix(p, "reg")) {
+		} else if (strprefix(p, "reg")) {
 			p += strlen("reg");
 			ret = parse_hex(p, &val);
 			if (ret <= 0)
diff --git a/drivers/iio/pressure/hsc030pa.c b/drivers/iio/pressure/hsc030pa.c
index 0374d406b401..eaf5ee190be5 100644
--- a/drivers/iio/pressure/hsc030pa.c
+++ b/drivers/iio/pressure/hsc030pa.c
@@ -476,7 +476,7 @@ int hsc_common_probe(struct device *dev, hsc_recv_fn recv)
 		return dev_err_probe(dev, ret,
 			     "honeywell,pressure-triplet could not be read\n");
 
-	if (str_has_prefix(triplet, "NA")) {
+	if (strprefix(triplet, "NA")) {
 		ret = device_property_read_u32(dev, "honeywell,pmin-pascal",
 					       &hsc->pmin);
 		if (ret)
diff --git a/drivers/md/dm-inlinecrypt.c b/drivers/md/dm-inlinecrypt.c
index 3479dfe5f708..4a1cc2da4c29 100644
--- a/drivers/md/dm-inlinecrypt.c
+++ b/drivers/md/dm-inlinecrypt.c
@@ -257,7 +257,7 @@ static int inlinecrypt_ctr_optional(struct dm_target *ti,
 			ti->error = "Not enough feature arguments";
 			return -EINVAL;
 		}
-		if (str_has_prefix(opt_string, "keytype:")) {
+		if (strprefix(opt_string, "keytype:")) {
 			const char *val = opt_string + strlen("keytype:");
 
 			if (!*val) {
diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c
index 7d7ba6d349fc..725245a1680b 100644
--- a/drivers/media/i2c/ds90ub960.c
+++ b/drivers/media/i2c/ds90ub960.c
@@ -4692,7 +4692,7 @@ ub960_fwnode_get_link_by_regs(struct fwnode_handle *links_fwnode,
 	fwnode_for_each_child_node(links_fwnode, link_fwnode) {
 		u32 link_num;
 
-		if (!str_has_prefix(fwnode_get_name(link_fwnode), "link@"))
+		if (!strprefix(fwnode_get_name(link_fwnode), "link@"))
 			continue;
 
 		ret = fwnode_property_read_u32(link_fwnode, "reg", &link_num);
diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index 9751acc2bf83..2dd18b34a378 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -1147,7 +1147,7 @@ static const char *scp_get_default_fw_path(struct device *dev, int core_id)
 		return ERR_PTR(-EINVAL);
 
 	/* If the compatible string starts with "mediatek,mt" assume that it's ok */
-	if (!str_has_prefix(compatible, "mediatek,mt"))
+	if (!strprefix(compatible, "mediatek,mt"))
 		return ERR_PTR(-EINVAL);
 
 	if (core_id >= 0)
diff --git a/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c b/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
index cca91c6d71a5..2cfe5f92ca3b 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
@@ -222,7 +222,7 @@ static int atomisp_csi2_get_pmc_clk_nr_from_acpi_pr0(struct acpi_device *adev)
 
 		acpi_get_name(rhandle, ACPI_SINGLE_NAME, &b_name);
 
-		if (str_has_prefix(name, "CLK") && !kstrtou8(&name[3], 10, &clock_num) &&
+		if (strprefix(name, "CLK") && !kstrtou8(&name[3], 10, &clock_num) &&
 		    clock_num <= 4) {
 			ret = clock_num;
 			break;
diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/serial_base_bus.c
index 5f23284a8778..1a5512457b74 100644
--- a/drivers/tty/serial/serial_base_bus.c
+++ b/drivers/tty/serial/serial_base_bus.c
@@ -33,11 +33,11 @@ static const struct device_type serial_port_type = {
 static int serial_base_match(struct device *dev, const struct device_driver *drv)
 {
 	if (dev->type == &serial_ctrl_type &&
-	    str_has_prefix(drv->name, serial_ctrl_type.name))
+	    strprefix(drv->name, serial_ctrl_type.name))
 		return 1;
 
 	if (dev->type == &serial_port_type &&
-	    str_has_prefix(drv->name, serial_port_type.name))
+	    strprefix(drv->name, serial_port_type.name))
 		return 1;
 
 	return 0;
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index 40c332d2179d..d3c8afaae4b3 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -803,7 +803,7 @@ static void parse_grep(const char *str)
 	cp++;
 	while (isspace(*cp))
 		cp++;
-	if (!str_has_prefix(cp, "grep ")) {
+	if (!strprefix(cp, "grep ")) {
 		kdb_printf("invalid 'pipe', see grephelp\n");
 		return;
 	}
diff --git a/kernel/kcsan/debugfs.c b/kernel/kcsan/debugfs.c
index 2af39ba5b70b..b945f9ab39a3 100644
--- a/kernel/kcsan/debugfs.c
+++ b/kernel/kcsan/debugfs.c
@@ -233,7 +233,7 @@ debugfs_write(struct file *file, const char __user *buf, size_t count, loff_t *o
 		WRITE_ONCE(kcsan_enabled, true);
 	} else if (!strcmp(arg, "off")) {
 		WRITE_ONCE(kcsan_enabled, false);
-	} else if (str_has_prefix(arg, "microbench=")) {
+	} else if (strprefix(arg, "microbench=")) {
 		unsigned long iters;
 
 		if (kstrtoul(&arg[strlen("microbench=")], 0, &iters))
diff --git a/kernel/kcsan/report.c b/kernel/kcsan/report.c
index 11a48b78f8d1..00f9b12f6a6d 100644
--- a/kernel/kcsan/report.c
+++ b/kernel/kcsan/report.c
@@ -292,7 +292,7 @@ static int get_stack_skipnr(const unsigned long stack_entries[], int num_entries
 		cur = strnstr(buf, "kcsan_", len);
 		if (cur) {
 			cur += strlen("kcsan_");
-			if (!str_has_prefix(cur, "test"))
+			if (!strprefix(cur, "test"))
 				continue; /* KCSAN runtime function. */
 			/* KCSAN related test. */
 		}
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 2441b9e39343..e8ce9ad73389 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1860,8 +1860,8 @@ static bool is_cfi_preamble_symbol(unsigned long addr)
 	if (lookup_symbol_name(addr, symbuf))
 		return false;
 
-	return str_has_prefix(symbuf, "__cfi_") ||
-		str_has_prefix(symbuf, "__pfx_");
+	return strprefix(symbuf, "__cfi_") ||
+		strprefix(symbuf, "__pfx_");
 }
 
 static int check_kprobe_address_safe(struct kprobe *p,
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index e618bcf75e2d..5408c4de5b01 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -1277,16 +1277,16 @@ static int __init lock_torture_init(void)
 	}
 
 #ifdef CONFIG_DEBUG_MUTEXES
-	if (str_has_prefix(torture_type, "mutex"))
+	if (strprefix(torture_type, "mutex"))
 		cxt.debug_lock = true;
 #endif
 #ifdef CONFIG_DEBUG_RT_MUTEXES
-	if (str_has_prefix(torture_type, "rtmutex"))
+	if (strprefix(torture_type, "rtmutex"))
 		cxt.debug_lock = true;
 #endif
 #ifdef CONFIG_DEBUG_SPINLOCK
-	if ((str_has_prefix(torture_type, "spin")) ||
-	    (str_has_prefix(torture_type, "rw_lock")))
+	if ((strprefix(torture_type, "spin")) ||
+	    (strprefix(torture_type, "rw_lock")))
 		cxt.debug_lock = true;
 #endif
 
diff --git a/kernel/power/main.c b/kernel/power/main.c
index 5429e9f19b65..763f84900e4b 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -781,7 +781,7 @@ static suspend_state_t decode_state(const char *buf, size_t n)
 	len = p ? p - buf : n;
 
 	/* Check hibernation first. */
-	if (len == 4 && str_has_prefix(buf, "disk"))
+	if (len == 4 && strprefix(buf, "disk"))
 		return PM_SUSPEND_MAX;
 
 #ifdef CONFIG_SUSPEND
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 49d135bc2fbf..d467cdf9c805 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -2182,7 +2182,7 @@ static int f_show(struct seq_file *m, void *v)
 	 */
 	array_descriptor = strchr(field->type, '[');
 
-	if (str_has_prefix(field->type, "__data_loc"))
+	if (strprefix(field->type, "__data_loc"))
 		array_descriptor = NULL;
 
 	if (!array_descriptor)
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 1aae7d7c6dc5..c099bfbb9fb6 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -1468,9 +1468,9 @@ static int parse_action(char *str, struct hist_trigger_attrs *attrs)
 	if (attrs->n_actions >= HIST_ACTIONS_MAX)
 		return ret;
 
-	if ((str_has_prefix(str, "onmatch(")) ||
-	    (str_has_prefix(str, "onmax(")) ||
-	    (str_has_prefix(str, "onchange("))) {
+	if ((strprefix(str, "onmatch(")) ||
+	    (strprefix(str, "onmax(")) ||
+	    (strprefix(str, "onchange("))) {
 		attrs->action_str[attrs->n_actions] = kstrdup(str, GFP_KERNEL);
 		if (!attrs->action_str[attrs->n_actions]) {
 			ret = -ENOMEM;
@@ -1508,7 +1508,7 @@ static int parse_assignment(struct trace_array *tr,
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (str_has_prefix(str, "name=")) {
+	} else if (strprefix(str, "name=")) {
 		attrs->name = kstrdup(str, GFP_KERNEL);
 		if (!attrs->name) {
 			ret = -ENOMEM;
@@ -3775,7 +3775,7 @@ static int action_parse(struct trace_array *tr, char *str, struct action_data *d
 		goto out;
 	}
 
-	if (str_has_prefix(action_name, "save")) {
+	if (strprefix(action_name, "save")) {
 		char *params = strsep(&str, ")");
 
 		if (!params) {
@@ -3801,7 +3801,7 @@ static int action_parse(struct trace_array *tr, char *str, struct action_data *d
 		data->track_data.save_data = save_track_data_vars;
 		data->fn = ontrack_action;
 		data->action = ACTION_SAVE;
-	} else if (str_has_prefix(action_name, "snapshot")) {
+	} else if (strprefix(action_name, "snapshot")) {
 		char *params = strsep(&str, ")");
 
 		if (!str) {
@@ -3826,7 +3826,7 @@ static int action_parse(struct trace_array *tr, char *str, struct action_data *d
 	} else {
 		char *params = strsep(&str, ")");
 
-		if (str_has_prefix(action_name, "trace"))
+		if (strprefix(action_name, "trace"))
 			data->use_trace_keyword = true;
 
 		if (params) {
diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
index e2870212e58d..016ca522e5af 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -167,7 +167,7 @@ static int synth_event_define_fields(struct trace_event_call *call)
 
 static bool synth_field_signed(char *type)
 {
-	if (str_has_prefix(type, "u"))
+	if (strprefix(type, "u"))
 		return false;
 	if (strcmp(type, "gfp_t") == 0)
 		return false;
diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
index f658c3a77aa7..8669f11fb9bd 100644
--- a/kernel/trace/trace_events_user.c
+++ b/kernel/trace/trace_events_user.c
@@ -1098,13 +1098,13 @@ static int user_field_size(const char *type)
 		return sizeof(char);
 	if (strcmp(type, "unsigned char") == 0)
 		return sizeof(unsigned char);
-	if (str_has_prefix(type, "char["))
+	if (strprefix(type, "char["))
 		return user_field_array_size(type);
-	if (str_has_prefix(type, "unsigned char["))
+	if (strprefix(type, "unsigned char["))
 		return user_field_array_size(type);
-	if (str_has_prefix(type, "__data_loc "))
+	if (strprefix(type, "__data_loc "))
 		return sizeof(u32);
-	if (str_has_prefix(type, "__rel_loc "))
+	if (strprefix(type, "__rel_loc "))
 		return sizeof(u32);
 
 	/* Unknown basic type, error */
@@ -1145,10 +1145,10 @@ static int user_event_add_field(struct user_event *user, const char *type,
 	if (!field)
 		return -ENOMEM;
 
-	if (str_has_prefix(type, "__data_loc "))
+	if (strprefix(type, "__data_loc "))
 		goto add_validator;
 
-	if (str_has_prefix(type, "__rel_loc ")) {
+	if (strprefix(type, "__rel_loc ")) {
 		validator_flags |= VALIDATOR_REL;
 		goto add_validator;
 	}
@@ -1349,12 +1349,12 @@ static const char *user_field_format(const char *type)
 
 static bool user_field_is_dyn_string(const char *type, const char **str_func)
 {
-	if (str_has_prefix(type, "__data_loc ")) {
+	if (strprefix(type, "__data_loc ")) {
 		*str_func = "__get_str";
 		goto check;
 	}
 
-	if (str_has_prefix(type, "__rel_loc ")) {
+	if (strprefix(type, "__rel_loc ")) {
 		*str_func = "__get_rel_str";
 		goto check;
 	}
@@ -1401,7 +1401,7 @@ static int user_field_set_string(struct ftrace_event_field *field,
 	pos += snprintf(buf + pos, LEN_OR_ZERO, " ");
 	pos += snprintf(buf + pos, LEN_OR_ZERO, "%s", field->name);
 
-	if (str_has_prefix(field->type, "struct "))
+	if (strprefix(field->type, "struct "))
 		pos += snprintf(buf + pos, LEN_OR_ZERO, " %d", field->size);
 
 	if (colon)
@@ -1808,7 +1808,7 @@ static int user_event_create(const char *raw_command)
 	char *name;
 	int ret;
 
-	if (!str_has_prefix(raw_command, USER_EVENTS_PREFIX))
+	if (!strprefix(raw_command, USER_EVENTS_PREFIX))
 		return -ECANCELED;
 
 	raw_command += USER_EVENTS_PREFIX_LEN;
@@ -1861,7 +1861,7 @@ static int user_event_show(struct seq_file *m, struct dyn_event *ev)
 
 		seq_printf(m, "%s %s", field->type, field->name);
 
-		if (str_has_prefix(field->type, "struct "))
+		if (strprefix(field->type, "struct "))
 			seq_printf(m, " %d", field->size);
 
 		depth++;
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index a880a90642d7..62acdf737c12 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -370,10 +370,10 @@ static int parse_this_cpu(char *arg, struct traceprobe_parse_context *ctx)
 		trace_probe_log_err(ctx->offset, NOSUP_PERCPU);
 		return -EINVAL;
 	}
-	if (str_has_prefix(arg, THIS_CPU_PTR_PREFIX)) {
+	if (strprefix(arg, THIS_CPU_PTR_PREFIX)) {
 		arg += THIS_CPU_PTR_LEN;
 		ctx->offset += THIS_CPU_PTR_LEN;
-	} else if (str_has_prefix(arg, THIS_CPU_READ_PREFIX)) {
+	} else if (strprefix(arg, THIS_CPU_READ_PREFIX)) {
 		arg += THIS_CPU_READ_LEN;
 		ctx->offset += THIS_CPU_READ_LEN;
 		is_read = true;
@@ -745,7 +745,7 @@ static int parse_btf_arg(char *varname,
 	u32 tid;
 
 	/* Note: field is not separated at this point, so check prefix. */
-	if (!str_has_prefix(varname, "$current") &&
+	if (!strprefix(varname, "$current") &&
 	    !ctx->funcname && !(ctx->flags & TPARG_FL_TEVENT))
 		return -EINVAL;
 
@@ -1001,8 +1001,8 @@ static int handle_typecast(char *arg, struct traceprobe_parse_context *ctx)
 		ctx->offset += 1;
 		tmp++;
 	} else if (*tmp == '+' || *tmp == '-' ||
-		   str_has_prefix(tmp, THIS_CPU_PTR_PREFIX) ||
-		   str_has_prefix(tmp, THIS_CPU_READ_PREFIX)) {
+		   strprefix(tmp, THIS_CPU_PTR_PREFIX) ||
+		   strprefix(tmp, THIS_CPU_READ_PREFIX)) {
 		/* Dereference can have another field access inside it. */
 		char *open = strchr(tmp + 1, '(');
 
@@ -1412,7 +1412,7 @@ static int parse_probe_vars(char *orig_arg, const struct fetch_type *t,
 	if (ctx->flags & TPARG_FL_TEVENT)
 		goto inval;
 
-	if (str_has_prefix(arg, "retval"))
+	if (strprefix(arg, "retval"))
 		return parse_probe_var_retval(orig_arg, pcode, end, ctx);
 
 	len = str_has_prefix(arg, "stack");
@@ -1420,7 +1420,7 @@ static int parse_probe_vars(char *orig_arg, const struct fetch_type *t,
 		return parse_probe_var_stack(arg, len, code, ctx);
 
 	/* $current returns the address of the current task_struct. */
-	if (str_has_prefix(arg, "current"))
+	if (strprefix(arg, "current"))
 		return parse_probe_var_current(orig_arg, arg, pcode, end, ctx);
 
 	len = str_has_prefix(arg, "arg");
@@ -1642,8 +1642,8 @@ static int parse_probe_arg_nested(char **parg, struct traceprobe_parse_context *
 	while (true) {
 		/* Determine if this is a nested argument */
 		if (arg[0] != '+' && arg[0] != '-' && arg[0] != '(' &&
-		    !str_has_prefix(arg, THIS_CPU_PTR_PREFIX) &&
-		    !str_has_prefix(arg, THIS_CPU_READ_PREFIX))
+		    !strprefix(arg, THIS_CPU_PTR_PREFIX) &&
+		    !strprefix(arg, THIS_CPU_READ_PREFIX))
 			break;
 
 		/* If nested, check the maximum depth limit */
@@ -2228,7 +2228,7 @@ static int argv_has_var_arg(int argc, const char *argv[], int *args_idx,
 	int i, found = 0;
 
 	for (i = 0; i < argc; i++)
-		if (str_has_prefix(argv[i], "$arg")) {
+		if (strprefix(argv[i], "$arg")) {
 			trace_probe_log_set_index(i + 2);
 
 			if (!tparg_is_function_entry(ctx->flags) &&
@@ -2335,7 +2335,7 @@ const char **traceprobe_expand_meta_args(int argc, const char *argv[],
 			continue;
 		}
 
-		if (str_has_prefix(argv[i], "$arg")) {
+		if (strprefix(argv[i], "$arg")) {
 			char *type = NULL;
 
 			n = simple_strtoul(argv[i] + 4, &type, 10);
diff --git a/mm/arch_numa.c b/mm/arch_numa.c
index a4b1732274fa..8380b8fe11d5 100644
--- a/mm/arch_numa.c
+++ b/mm/arch_numa.c
@@ -24,7 +24,7 @@ static __init int numa_parse_early_param(char *opt)
 {
 	if (!opt)
 		return -EINVAL;
-	if (str_has_prefix(opt, "off"))
+	if (strprefix(opt, "off"))
 		numa_off = true;
 	if (!strncmp(opt, "fake=", 5))
 		return numa_emu_cmdline(opt + 5);
diff --git a/mm/kfence/report.c b/mm/kfence/report.c
index d548536864b1..e6fae0c2b9b5 100644
--- a/mm/kfence/report.c
+++ b/mm/kfence/report.c
@@ -97,9 +97,9 @@ static int get_stack_skipnr(const unsigned long stack_entries[], int num_entries
 	for (skipnr = 0; skipnr < num_entries; skipnr++) {
 		int len = scnprintf(buf, sizeof(buf), "%ps", (void *)stack_entries[skipnr]);
 
-		if (str_has_prefix(buf, ARCH_FUNC_PREFIX "kfence_") ||
-		    str_has_prefix(buf, ARCH_FUNC_PREFIX "__kfence_") ||
-		    str_has_prefix(buf, ARCH_FUNC_PREFIX "__kmem_cache_free") ||
+		if (strprefix(buf, ARCH_FUNC_PREFIX "kfence_") ||
+		    strprefix(buf, ARCH_FUNC_PREFIX "__kfence_") ||
+		    strprefix(buf, ARCH_FUNC_PREFIX "__kmem_cache_free") ||
 		    !strncmp(buf, ARCH_FUNC_PREFIX "__slab_free", len)) {
 			/*
 			 * In case of tail calls from any of the below to any of
@@ -114,10 +114,10 @@ static int get_stack_skipnr(const unsigned long stack_entries[], int num_entries
 		 * into the slab allocators. Includes the *_bulk() variants by
 		 * checking prefixes.
 		 */
-		if (str_has_prefix(buf, ARCH_FUNC_PREFIX "kfree") ||
-		    str_has_prefix(buf, ARCH_FUNC_PREFIX "kmem_cache_free") ||
-		    str_has_prefix(buf, ARCH_FUNC_PREFIX "__kmalloc") ||
-		    str_has_prefix(buf, ARCH_FUNC_PREFIX "kmem_cache_alloc"))
+		if (strprefix(buf, ARCH_FUNC_PREFIX "kfree") ||
+		    strprefix(buf, ARCH_FUNC_PREFIX "kmem_cache_free") ||
+		    strprefix(buf, ARCH_FUNC_PREFIX "__kmalloc") ||
+		    strprefix(buf, ARCH_FUNC_PREFIX "kmem_cache_alloc"))
 			goto found;
 	}
 	if (fallback < num_entries)
diff --git a/sound/soc/sdw_utils/soc_sdw_senary_sdca.c b/sound/soc/sdw_utils/soc_sdw_senary_sdca.c
index 5c2cd75307c9..afaca66e41ef 100644
--- a/sound/soc/sdw_utils/soc_sdw_senary_sdca.c
+++ b/sound/soc/sdw_utils/soc_sdw_senary_sdca.c
@@ -33,7 +33,7 @@ static const struct codec_route_map codec_routes[] = {
 static const struct codec_route_map *get_codec_route_map(const char *dai_name)
 {
 	for (size_t i = 0; i < ARRAY_SIZE(codec_routes); i++) {
-		if (str_has_prefix(dai_name, codec_routes[i].codec_name))
+		if (strprefix(dai_name, codec_routes[i].codec_name))
 			return &codec_routes[i];
 	}
 	return NULL;
-- 
2.55.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2026-11-14 15:23 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 15:21 [PATCH v6 00/19] Add strprefix() and fix a bug with it Alejandro Colomar
2026-11-14 15:21 ` [PATCH v6 01/19] string: Add streq() Alejandro Colomar
2026-11-14 15:22 ` [PATCH v6 02/19] string: Add strprefix() Alejandro Colomar
2026-11-14 15:28   ` Joe Perches
2026-11-14 15:53   ` Joe Perches
2026-11-14 15:22 ` [PATCH v6 03/19] string: Document corner-case misbehavior in str_has_prefix() for empty prefix Alejandro Colomar
2026-11-14 15:22 ` [PATCH v6 04/19] device property: Fix fwnode_name_eq() for empty node names Alejandro Colomar
2026-11-14 15:22 ` [PATCH v6 05/19] stddef: Add const_cast() Alejandro Colomar
2026-11-14 15:22 ` [PATCH v6 06/19] string: Add [C]QChar_of() and QVoid_of() Alejandro Colomar
2026-11-14 15:22 ` [PATCH v6 07/19] string: Make strprefix() const-qualifier-generic Alejandro Colomar
2026-11-14 15:22 ` [PATCH v6 08/19] perf map: Use bool for return type instead of int Alejandro Colomar
2026-11-14 15:22 ` [PATCH v6 09/19] string: Make strstarts() a legacy alias for strprefix() Alejandro Colomar
2026-11-14 15:23 ` [PATCH v6 10/19] platform/x86: hp-bioscfg: Rename local variable Alejandro Colomar
2026-11-14 16:04   ` Joe Perches
2026-11-14 15:23 ` [PATCH v6 11/19] treewide: s/strstarts/strprefix/g Alejandro Colomar
2026-11-14 15:23 ` [PATCH v6 12/19] string: Remove strstarts() Alejandro Colomar
2026-11-14 15:23 ` [PATCH v6 13/19] s390/test_unwind: Use bool for booleans Alejandro Colomar
2026-11-14 15:23 ` Alejandro Colomar [this message]
2026-11-14 15:23 ` [PATCH v6 15/19] treewide: Replace some uses of str_has_prefix() by strprefix() Alejandro Colomar
2026-11-14 15:23 ` [PATCH v6 16/19] string: Add strsuffix() Alejandro Colomar
2026-11-14 15:24 ` [PATCH v6 17/19] string: Make strends() a legacy alias for strsuffix() Alejandro Colomar
2026-11-14 15:24 ` [PATCH v6 18/19] treewide: s/\<strends\>/strsuffix/g Alejandro Colomar
2026-11-14 15:24 ` [PATCH v6 19/19] string: Remove strends() Alejandro Colomar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0c0070455de00eb63b43c6697555398fa5ef9d87.1794667407.git.alx@kernel.org \
    --to=alx@kernel.org \
    --cc=andy@kernel.org \
    --cc=brgl@kernel.org \
    --cc=dakr@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=djrscally@gmail.com \
    --cc=driver-core@lists.linux.dev \
    --cc=geert@linux-m68k.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=joe@perches.com \
    --cc=johan@kernel.org \
    --cc=kees@kernel.org \
    --cc=krzk@kernel.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=lenb@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=macro@orcam.me.uk \
    --cc=namhyung@kernel.org \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=saravanak@kernel.org \
    --cc=schwab@linux-m68k.org \
    --cc=torvalds@linux-foundation.org \
    --cc=zanussi@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®