[PATCH 23/28] Input: synaptics_usb - use seq_buf and snprintf() for name and phys

Bill Wendling morbo at google.com
Tue Sep 15 08:18:40 UTC 2026


synusb_probe() constructs the device name and physical path using a mix of
strscpy(), strlcat(), and snprintf().

In preparation for removing the deprecated strlcat() API[1], use struct
seq_buf to incrementally build synusb->name, and format synusb->phys with
snprintf() after generating the USB path.

Link: https://github.com/KSPP/linux/issues/370 [1]
Cc: codemender-patching+linux at google.com
Assisted-by: Gemini:1.5-Pro-002 [editor_update_file, make_kernel_build_single_file, test_runner_run_kunit_test]
Signed-off-by: Bill Wendling <morbo at google.com>
---
Cc: Russell King <linux at armlinux.org.uk>
Cc: Huacai Chen <chenhuacai at kernel.org>
Cc: WANG Xuerui <kernel at xen0n.name>
Cc: Thomas Bogendoerfer <tsbogend at alpha.franken.de>
Cc: "James E.J. Bottomley" <James.Bottomley at HansenPartnership.com>
Cc: Helge Deller <deller at gmx.de>
Cc: Thomas Gleixner <tglx at kernel.org>
Cc: Ingo Molnar <mingo at redhat.com>
Cc: Borislav Petkov <bp at alien8.de>
Cc: Dave Hansen <dave.hansen at linux.intel.com>
Cc: x86 at kernel.org
Cc: "H. Peter Anvin" <hpa at zytor.com>
Cc: Ian Abbott <abbotti at mev.co.uk>
Cc: H Hartley Sweeten <hsweeten at visionengravers.com>
Cc: Tony Luck <tony.luck at intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
Cc: Maxime Ripard <mripard at kernel.org>
Cc: Thomas Zimmermann <tzimmermann at suse.de>
Cc: David Airlie <airlied at gmail.com>
Cc: Simona Vetter <simona at ffwll.ch>
Cc: Matthew Brost <matthew.brost at intel.com>
Cc: "Thomas Hellström" <thomas.hellstrom at linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi at intel.com>
Cc: Dmitry Torokhov <dmitry.torokhov at gmail.com>
Cc: Matthias Schwarzott <zzam at gentoo.org>
Cc: Mauro Carvalho Chehab <mchehab at kernel.org>
Cc: Tony Nguyen <anthony.l.nguyen at intel.com>
Cc: Przemek Kitszel <przemyslaw.kitszel at intel.com>
Cc: Andrew Lunn <andrew+netdev at lunn.ch>
Cc: "David S. Miller" <davem at davemloft.net>
Cc: Eric Dumazet <edumazet at google.com>
Cc: Jakub Kicinski <kuba at kernel.org>
Cc: Paolo Abeni <pabeni at redhat.com>
Cc: Arend van Spriel <arend.vanspriel at broadcom.com>
Cc: Rob Herring <robh at kernel.org>
Cc: Saravana Kannan <saravanak at kernel.org>
Cc: Krzysztof Kozlowski <krzk at kernel.org>
Cc: Sylwester Nawrocki <s.nawrocki at samsung.com>
Cc: Peter Griffin <peter.griffin at linaro.org>
Cc: Alim Akhtar <alim.akhtar at samsung.com>
Cc: Linus Walleij <linusw at kernel.org>
Cc: Anil Gurumurthy <anil.gurumurthy at qlogic.com>
Cc: Sudarsana Kalluru <sudarsana.kalluru at qlogic.com>
Cc: "Martin K. Petersen" <mkp at kernel.org>
Cc: Trond Myklebust <trondmy at kernel.org>
Cc: Anna Schumaker <anna at kernel.org>
Cc: Mike Marshall <hubcap at omnibond.com>
Cc: Martin Brandenburg <martin at omnibond.com>
Cc: Kees Cook <kees at kernel.org>
Cc: Jiri Pirko <jiri at resnulli.us>
Cc: Simon Horman <horms at kernel.org>
Cc: Chuck Lever <cel at kernel.org>
Cc: Jeff Layton <jlayton at kernel.org>
Cc: NeilBrown <neil at brown.name>
Cc: Olga Kornievskaia <okorniev at redhat.com>
Cc: Dai Ngo <Dai.Ngo at oracle.com>
Cc: Tom Talpey <tom at talpey.com>
Cc: Jaroslav Kysela <perex at perex.cz>
Cc: Takashi Iwai <tiwai at suse.com>
Cc: Bill Wendling <morbo at google.com>
Cc: Andrew Morton <akpm at linux-foundation.org>
Cc: "Mike Rapoport (Microsoft)" <rppt at kernel.org>
Cc: Kanglong Wang <wangkanglong at loongson.cn>
Cc: Tiezhu Yang <yangtiezhu at loongson.cn>
Cc: Qiang Ma <maqianga at uniontech.com>
Cc: Randy Dunlap <rdunlap at infradead.org>
Cc: Pengpeng Hou <pengpeng at iscas.ac.cn>
Cc: Ard Biesheuvel <ardb at kernel.org>
Cc: Breno Leitao <leitao at debian.org>
Cc: Thorsten Blum <blum at kernel.org>
Cc: Harshit Mogalapalli <harshit.m.mogalapalli at oracle.com>
Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
Cc: Lyude Paul <lyude at redhat.com>
Cc: Ashutosh Desai <ashutoshdesai993 at gmail.com>
Cc: Imre Deak <imre.deak at intel.com>
Cc: Dmitry Baryshkov <dmitry.baryshkov at oss.qualcomm.com>
Cc: Johan Hovold <johan at kernel.org>
Cc: Johannes Berg <johannes.berg at intel.com>
Cc: Miri Korenblit <miriam.rachel.korenblit at intel.com>
Cc: Alexander Stein <alexander.stein at ew.tq-group.com>
Cc: Cryolitia PukNgae <cryolitia at uniontech.com>
Cc: Jiaming Zhang <r772577952 at gmail.com>
Cc: Will Porter <mrwillporter at gmail.com>
Cc: Cen Zhang <zzzccc427 at gmail.com>
Cc: "Cássio Gabriel" <cassiogabrielcontato at gmail.com>
Cc: Rong Zhang <i at rong.moe>
Cc: Arun Raghavan <arunr at valvesoftware.com>
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-kernel at vger.kernel.org
Cc: loongarch at lists.linux.dev
Cc: linux-mips at vger.kernel.org
Cc: linux-parisc at vger.kernel.org
Cc: linux-edac at vger.kernel.org
Cc: dri-devel at lists.freedesktop.org
Cc: intel-xe at lists.freedesktop.org
Cc: linux-input at vger.kernel.org
Cc: linux-media at vger.kernel.org
Cc: intel-wired-lan at lists.osuosl.org
Cc: netdev at vger.kernel.org
Cc: linux-wireless at vger.kernel.org
Cc: brcm80211 at lists.linux.dev
Cc: brcm80211-dev-list.pdl at broadcom.com
Cc: devicetree at vger.kernel.org
Cc: linux-samsung-soc at vger.kernel.org
Cc: linux-gpio at vger.kernel.org
Cc: linux-scsi at vger.kernel.org
Cc: linux-nfs at vger.kernel.org
Cc: devel at lists.orangefs.org
Cc: linux-hardening at vger.kernel.org
Cc: linux-sound at vger.kernel.org
---
 drivers/input/mouse/synaptics_usb.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/input/mouse/synaptics_usb.c b/drivers/input/mouse/synaptics_usb.c
index 880a0c79148c..d13d2d6202ee 100644
--- a/drivers/input/mouse/synaptics_usb.c
+++ b/drivers/input/mouse/synaptics_usb.c
@@ -41,6 +41,7 @@
 #include <linux/usb.h>
 #include <linux/input.h>
 #include <linux/usb/input.h>
+#include <linux/seq_buf.h>
 
 #define USB_VENDOR_ID_SYNAPTICS	0x06cb
 #define USB_DEVICE_ID_SYNAPTICS_TP	0x0001	/* Synaptics USB TouchPad */
@@ -278,6 +279,8 @@ static int synusb_probe(struct usb_interface *intf,
 	struct input_dev *input_dev;
 	unsigned int intf_num = intf->cur_altsetting->desc.bInterfaceNumber;
 	unsigned int altsetting = min(intf->num_altsetting, 1U);
+	struct seq_buf s;
+	char path[64];
 	int error;
 
 	error = usb_set_interface(udev, intf_num, altsetting);
@@ -334,27 +337,29 @@ static int synusb_probe(struct usb_interface *intf,
 			 ep->bInterval);
 	synusb->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
 
+	seq_buf_init(&s, synusb->name, sizeof(synusb->name));
+
 	if (udev->manufacturer)
-		strscpy(synusb->name, udev->manufacturer,
-			sizeof(synusb->name));
+		seq_buf_puts(&s, udev->manufacturer);
 
 	if (udev->product) {
 		if (udev->manufacturer)
-			strlcat(synusb->name, " ", sizeof(synusb->name));
-		strlcat(synusb->name, udev->product, sizeof(synusb->name));
+			seq_buf_puts(&s, " ");
+		seq_buf_puts(&s, udev->product);
 	}
 
-	if (!strlen(synusb->name))
-		snprintf(synusb->name, sizeof(synusb->name),
-			 "USB Synaptics Device %04x:%04x",
-			 le16_to_cpu(udev->descriptor.idVendor),
-			 le16_to_cpu(udev->descriptor.idProduct));
+	if (!seq_buf_used(&s))
+		seq_buf_printf(&s, "USB Synaptics Device %04x:%04x",
+			       le16_to_cpu(udev->descriptor.idVendor),
+			       le16_to_cpu(udev->descriptor.idProduct));
 
 	if (synusb->flags & SYNUSB_STICK)
-		strlcat(synusb->name, " (Stick)", sizeof(synusb->name));
+		seq_buf_puts(&s, " (Stick)");
 
-	usb_make_path(udev, synusb->phys, sizeof(synusb->phys));
-	strlcat(synusb->phys, "/input0", sizeof(synusb->phys));
+	seq_buf_str(&s);
+
+	usb_make_path(udev, path, sizeof(path));
+	snprintf(synusb->phys, sizeof(synusb->phys), "%s/input0", path);
 
 	input_dev->name = synusb->name;
 	input_dev->phys = synusb->phys;
-- 
2.55.0.1032.g73a4cd73de-goog



More information about the Intel-wired-lan mailing list