From nobody Thu Apr 2 11:01:49 2026 Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B11F2238159 for ; Sun, 29 Mar 2026 21:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774819189; cv=none; b=RTRore5WniUtHjitcWQUjHIQn9uhLVDuog0cwTJfKAM4R2xQgihT/PcoPBGvRVqd13/cMTDTEjr6LGiDCociz1ARbRUuLNorNoWmgojhOsO56KZcBovF7mrQ4roJg3LCzR7akCiLyBDcdqBG69uAXaKfqYtIW6xgR7xTcCR5FsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774819189; c=relaxed/simple; bh=54lklR+wlMg5SmVFeKONR85hTJb6PsYhSlu0Not93ks=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=br8DH027vOkocTBjFSFlbY6XcZTQhFKhIXoduZq1ezNK6PtzLK2FdjC2O4GZIF/KRnI28GrP4rSzx7thyr1avnem4WyyYgIijqg3k6X+Onw1SXdzCxUZbxzfGFAIpMPX3tjtK21u8tt4Cy4uiKgN+vQ7gY2y/BgmaZj6Y3AnQmg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=UVquPUS2; arc=none smtp.client-ip=95.215.58.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="UVquPUS2" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1774819186; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=WaUlX6re13RdCZQLD37/gV34roPzRfkeksxt6H+7baI=; b=UVquPUS2qotwsSD4PxnOddwX0FLQkjRBnNKWpDH2L0PHQHplEGBXKI11tjxdWblwzVe0e9 fG2Fyxvj5+xu4pYuJA0yXHgW4v1h2jZDrP+H/LqdLrO8FWf2Xzi7LdfuirLyhVBgCR57nN DBw+PD1hH2C7uzH+i0QFd6gPw5oBVAo= From: Thorsten Blum To: Takashi Sakamoto Cc: Thorsten Blum , linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH] firewire: core: clean up modalias buffer handling Date: Sun, 29 Mar 2026 23:19:40 +0200 Message-ID: <20260329211940.371395-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1567; i=thorsten.blum@linux.dev; h=from:subject; bh=54lklR+wlMg5SmVFeKONR85hTJb6PsYhSlu0Not93ks=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDJknp+foSm8KOmSamVFl87jw/YyChhsJSeeN/6k5FasY1 rUt+KHUUcrCIMbFICumyPJg1o8ZvqU1lZtMInbCzGFlAhnCwMUpABOp+MfwVzzS5b9muvTKNawm gvZxglJqAlcTr1ukLln1YH6jsmi5HCPDhJXN1Zv3f9etP7N26R6BAxWK/YZOzv/XHZbXky58WbG OHwA= X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Use scnprintf() in get_modalias() to return the number of characters actually written to the destination buffer. Also reserve space for the trailing newline in modalias_show() and append it explicitly, instead of using strcpy() and relying on the formatted modalias to fit within PAGE_SIZE. While the current code is safe, this makes the sysfs buffer handling more explicit and consistent. Signed-off-by: Thorsten Blum --- drivers/firewire/core-device.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index c0f17da27a22..182eb4321e47 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c @@ -234,9 +234,9 @@ static int get_modalias(const struct fw_unit *unit, cha= r *buffer, size_t buffer_ =20 get_modalias_ids(unit, id); =20 - return snprintf(buffer, buffer_size, - "ieee1394:ven%08Xmo%08Xsp%08Xver%08X", - id[0], id[1], id[2], id[3]); + return scnprintf(buffer, buffer_size, + "ieee1394:ven%08Xmo%08Xsp%08Xver%08X", + id[0], id[1], id[2], id[3]); } =20 static int fw_unit_uevent(const struct device *dev, struct kobj_uevent_env= *env) @@ -435,8 +435,9 @@ static ssize_t modalias_show(struct device *dev, struct fw_unit *unit =3D fw_unit(dev); int length; =20 - length =3D get_modalias(unit, buf, PAGE_SIZE); - strcpy(buf + length, "\n"); + length =3D get_modalias(unit, buf, PAGE_SIZE - 1); + buf[length] =3D '\n'; + buf[length + 1] =3D '\0'; =20 return length + 1; }