From: Jakub Kicinski <kuba@kernel.org>
To: dmantipov@yandex.ru
Cc: Jakub Kicinski <kuba@kernel.org>,
bharat@chelsio.com, netdev@vger.kernel.org
Subject: Re: [PATCH] cxgb4: use kstrtou16_from_user() in tp_la_write()
Date: Mon, 17 Aug 2026 16:51:40 -0700 [thread overview]
Message-ID: <20260817235140.3752193-1-kuba@kernel.org> (raw)
In-Reply-To: <20260814064127.1957130-1-dmantipov@yandex.ru>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
cxgb4: use kstrtou16_from_user() in tp_la_write()
This replaces the open-coded copy_from_user() plus kstrtoul() parsing in
tp_la_write() with kstrtou16_from_user(), storing the parsed value in a u16
and dropping the explicit val > 0xffff check.
> diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
> index f521737d12756..5c6c274188913 100644
> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
> @@ -664,20 +664,13 @@ static ssize_t tp_la_write(struct file *file, const char __user *buf,
> size_t count, loff_t *pos)
> {
> int err;
> - char s[32];
> - unsigned long val;
> - size_t size = min(sizeof(s) - 1, count);
> + u16 val;
> struct adapter *adap = file_inode(file)->i_private;
>
> - if (copy_from_user(s, buf, size))
> - return -EFAULT;
> - s[size] = '\0';
> - err = kstrtoul(s, 0, &val);
> + err = kstrtou16_from_user(buf, count, 0, &val);
> if (err)
> return err;
> - if (val > 0xffff)
> - return -EINVAL;
> - adap->params.tp.la_mask = val << 16;
> + adap->params.tp.la_mask = (unsigned int)val << 16;
[Severity: Low]
Does this change the accepted input length and the returned errno for
tp_la_write()?
The helper instantiated for u16 in lib/kstrtox.c sizes its buffer from the
target type:
#define kstrto_from_user(f, g, type) \
int f(const char __user *s, size_t count, unsigned int base, type *res) \
{ \
/* sign, base 2 representation, newline, terminator */ \
char buf[1 + sizeof(type) * 8 + 1 + 1]; \
\
count = min(count, sizeof(buf) - 1); \
if (copy_from_user(buf, s, count)) \
return -EFAULT; \
buf[count] = '\0'; \
return g(buf, base, res); \
} \
...
kstrto_from_user(kstrtou16_from_user, kstrtou16, u16);
so buf is 19 bytes and the input is clamped to 18 bytes, where the previous
code used char s[32] and accepted up to 31 characters.
For a write longer than 18 bytes, such as a zero-padded
"0x0000000000000000ffff", the clamp keeps only the 18-byte prefix, a
different value is programmed into TP_DBG_LA_CONFIG_A by
t4_set_reg_field(), and tp_la_write() still returns the full count, so the
write looks successful. Any invalid characters past byte 18 are also never
seen by the parser. Should the handler reject count larger than what the
helper can consume instead?
Separately, values above 0xffff now come back as -ERANGE from kstrtou16()
rather than the -EINVAL that the removed check produced:
- if (val > 0xffff)
- return -EINVAL;
Could the commit message mention the new 18-byte input limit and the errno
change, since it currently describes the change only as a way to
"simplify 'tp_la_write()'"?
--
pw-bot: cr
prev parent reply other threads:[~2026-08-17 23:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-14 6:41 [PATCH] cxgb4: use kstrtou16_from_user() in tp_la_write() Dmitry Antipov
2026-08-17 23:51 ` Jakub Kicinski [this message]
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=20260817235140.3752193-1-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=bharat@chelsio.com \
--cc=dmantipov@yandex.ru \
--cc=netdev@vger.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