From: sashiko-bot@kernel.org
To: "Dmitry Antipov" <dmantipov@yandex.ru>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] USB: usbsevseg: cleanup sysfs show handlers
Date: Thu, 29 Oct 2026 12:53:00 +0000 [thread overview]
Message-ID: <sashiko-outbox-189323@kernel.org> (raw)
In-Reply-To: <20261029124716.611540-1-dmantipov@yandex.ru>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] usb: usbsevseg: off-by-one in textmode_show() emits trailing NUL byte
--
commit a74c1b2c71cf0a70caf0b902cff95d63b0e182d0
Author: Dmitry Antipov <dmantipov@yandex.ru>
USB: usbsevseg: cleanup sysfs show handlers
This commit replaces sprintf() and strcat() calls in usbsevseg sysfs show
handlers with sysfs_emit() and sysfs_emit_at().
> diff --git a/drivers/usb/misc/usbsevseg.c b/drivers/usb/misc/usbsevseg.c
> index 89d25fcef6424..f456a7161a260 100644
> --- a/drivers/usb/misc/usbsevseg.c
> +++ b/drivers/usb/misc/usbsevseg.c
[ ... ]
> @@ -246,25 +246,19 @@ static ssize_t textmode_show(struct device *dev,
> {
> struct usb_interface *intf = to_usb_interface(dev);
> struct usb_sevsegdev *mydev = usb_get_intfdata(intf);
> - int i;
> -
> - buf[0] = 0;
> + int i, ret = 0;
>
> for (i = 0; i < ARRAY_SIZE(display_textmodes); i++) {
> - if (mydev->textmode == i) {
> - strcat(buf, " [");
> - strcat(buf, display_textmodes[i]);
> - strcat(buf, "] ");
> - } else {
> - strcat(buf, " ");
> - strcat(buf, display_textmodes[i]);
> - strcat(buf, " ");
> - }
> + if (mydev->textmode == i)
> + ret += sysfs_emit_at(buf, ret, " [%s] ",
> + display_textmodes[i]);
> + else
> + ret += sysfs_emit_at(buf, ret, " %s ",
> + display_textmodes[i]);
> }
> - strcat(buf, "\n");
> -
>
> - return strlen(buf);
> + ret += sysfs_emit_at(buf, ret - 1, "\n");
> + return ret;
[Severity: Medium]
Does passing ret - 1 to sysfs_emit_at() while still adding its return value
to ret cause textmode_show() in drivers/usb/misc/usbsevseg.c to include a
trailing NUL byte in the output returned to userspace when reading the
textmode sysfs attribute?
At the end of the loop, buf[0 .. ret - 1] holds the formatted string with a
trailing space at buf[ret - 1] and a NUL terminator at buf[ret]. Calling
sysfs_emit_at(buf, ret - 1, "\n") overwrites the space at buf[ret - 1] with
a newline, writes the NUL terminator at buf[ret], and returns 1.
Adding that return value to ret increments ret to strlen(buf) + 1. When
sysfs_kf_seq_show() in fs/sysfs/file.c calls seq_commit(sf, count) with that
returned count, the NUL byte at buf[ret - 1] is committed into the seq_file
buffer and exposed to userspace.
Should this either pass ret instead of ret - 1 to preserve the original
trailing space before the newline, or avoid incrementing ret if overwriting
the trailing space was intentional?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261029124716.611540-1-dmantipov@yandex.ru?part=1
next prev parent reply other threads:[~2026-10-29 12:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 12:47 [PATCH] USB: usbsevseg: cleanup sysfs show handlers Dmitry Antipov
2026-10-29 12:53 ` sashiko-bot [this message]
2026-10-29 13:14 ` [PATCH v2] " Dmitry Antipov
2026-10-29 13:17 ` sashiko-bot
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=sashiko-outbox-189323@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmantipov@yandex.ru \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.