From nobody Fri Dec 19 18:41:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03863C10DC1 for ; Thu, 30 Nov 2023 10:55:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345104AbjK3KzM (ORCPT ); Thu, 30 Nov 2023 05:55:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345084AbjK3KzH (ORCPT ); Thu, 30 Nov 2023 05:55:07 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C299510F4 for ; Thu, 30 Nov 2023 02:55:13 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E26CFC433CA; Thu, 30 Nov 2023 10:55:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701341713; bh=5UqF6R+sWlvabSQcifcTgrUGPsaALtx849UaV5ZfAKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EOBnh8dQw28r6W0KPBw5vHS0NSBkkMQADsIb+Ve3s5U/7V/iBgkdOyaSMTt6ijwzj 6Ov39DhGrVN/xtHRUygR0xpAkRjnXxyWBY4uBB/iS+11vAe2+40UEvgD8xqgcUzd+e HM/otnXIKQTW5mBIvxY9MjH7704FN4JMwb67INriEKjmFuVF0dlyXiPKRxABvydoB4 b1H8w4EnGqE2tD/rrI2SfwQLzNCEORoKyOFeo+dTDhdcx0/aqwFc1tgMmqXbygHXo2 EVo7qW7D7BGO2ZoO34GganL2z0nMzryMQU+WdCfCGr9+UQcU4eZdUgJhCTkivgPOl/ h9e2lzRBWT6Gg== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, Matthieu CASTET , Stanislaw Gruszka , Greg Kroah-Hartman , Damien Bergamini , linux-usb@vger.kernel.org Subject: [PATCH 1/5] usb: atm: Remove snprintf() from sysfs call-backs and replace with sysfs_emit() Date: Thu, 30 Nov 2023 10:54:35 +0000 Message-ID: <20231130105459.3208986-2-lee@kernel.org> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog In-Reply-To: <20231130105459.3208986-1-lee@kernel.org> References: <20231130105459.3208986-1-lee@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since snprintf() has the documented, but still rather strange trait of returning the length of the data that *would have been* written to the array if space were available, rather than the arguably more useful length of data *actually* written, it is usually considered wise to use something else instead in order to avoid confusion. In the case of sysfs call-backs, new wrappers exist that do just that. This patch replaces the 2 uses of snprintf() found in the sysfs .show() call-backs with the new sysfs_emit() helpers. Whist we're at it, let's replace the sprintf()s as well. For no other reason than consistency. Link: https://lwn.net/Articles/69419/ Link: https://github.com/KSPP/linux/issues/105 Cc: Matthieu CASTET Cc: Stanislaw Gruszka Cc: Greg Kroah-Hartman Cc: Damien Bergamini Cc: linux-usb@vger.kernel.org Signed-off-by: Lee Jones --- drivers/usb/atm/ueagle-atm.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c index 5812f7ea7f902..8d5580d8d20a8 100644 --- a/drivers/usb/atm/ueagle-atm.c +++ b/drivers/usb/atm/ueagle-atm.c @@ -2252,7 +2252,7 @@ static ssize_t stat_status_show(struct device *dev, s= truct device_attribute *att sc =3D dev_to_uea(dev); if (!sc) goto out; - ret =3D snprintf(buf, 10, "%08x\n", sc->stats.phy.state); + ret =3D sysfs_emit(buf, "%08x\n", sc->stats.phy.state); out: mutex_unlock(&uea_mutex); return ret; @@ -2318,19 +2318,19 @@ static ssize_t stat_human_status_show(struct device= *dev, =20 switch (modem_state) { case 0: - ret =3D sprintf(buf, "Modem is booting\n"); + ret =3D sysfs_emit(buf, "Modem is booting\n"); break; case 1: - ret =3D sprintf(buf, "Modem is initializing\n"); + ret =3D sysfs_emit(buf, "Modem is initializing\n"); break; case 2: - ret =3D sprintf(buf, "Modem is operational\n"); + ret =3D sysfs_emit(buf, "Modem is operational\n"); break; case 3: - ret =3D sprintf(buf, "Modem synchronization failed\n"); + ret =3D sysfs_emit(buf, "Modem synchronization failed\n"); break; default: - ret =3D sprintf(buf, "Modem state is unknown\n"); + ret =3D sysfs_emit(buf, "Modem state is unknown\n"); break; } out: @@ -2364,7 +2364,7 @@ static ssize_t stat_delin_show(struct device *dev, st= ruct device_attribute *attr delin =3D "LOSS"; } =20 - ret =3D sprintf(buf, "%s\n", delin); + ret =3D sysfs_emit(buf, "%s\n", delin); out: mutex_unlock(&uea_mutex); return ret; @@ -2384,7 +2384,7 @@ static ssize_t stat_##name##_show(struct device *dev,= \ sc =3D dev_to_uea(dev); \ if (!sc) \ goto out; \ - ret =3D snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \ + ret =3D sysfs_emit(buf, "%08x\n", sc->stats.phy.name); \ if (reset) \ sc->stats.phy.name =3D 0; \ out: \ --=20 2.43.0.rc1.413.gea7ed67945-goog