Re: [PATCH v2] net: ethtool: do not call get_regs() for zero-length dumps

From: netdev-bot+sashiko

Date: Thu Nov 26 2026 - 21:41:56 EST


Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] In ethtool_get_regs() (net/ethtool/ioctl.c), the new `if
(!regs.len) return 0;` check runs before `ops->get_regs_len()` and its…
- [Low] In ethtool_get_regs() (net/ethtool/ioctl.c), ETHTOOL_GREGS with
regs.len == 0 now returns success without calling ops->get_regs() and…

--

net: ethtool: do not call get_regs() for zero-length dumps

This patch adds an early return to ethtool_get_regs() when the
user-supplied regs.len is zero, so the driver's get_regs() is no longer
called for a zero-length dump. The goal is to stop drivers such as mcs7830
from issuing zero-length USB control transfers on the receive pipe. Those
transfers trip a WARN in usb_submit_urb().

> diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
> index 80b7930b3fe0d..e8af861ee5de3 100644
> --- a/net/ethtool/ioctl.c
> +++ b/net/ethtool/ioctl.c
> @@ -1779,6 +1779,10 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
> if (copy_from_user(&regs, useraddr, sizeof(regs)))
> return -EFAULT;
>
> + /* A zero-length dump has nothing to fill in. */
> + if (!regs.len)
> + return 0;
> +
> reglen = ops->get_regs_len(dev);
> if (reglen <= 0)
> return reglen;

[Severity: Medium]
Can this early return hide errors from get_regs_len()?

The new check runs before ops->get_regs_len(). So when regs.len is 0, a
negative return such as -EOPNOTSUPP is never passed back. The ioctl
reports success and copies nothing back.

A GREGS request with len == 0 is what a normal ethtool -d sends when
get_regs_len() fails. That happens because ethtool_get_drvinfo() only sets
regdump_len for positive values:

net/ethtool/ioctl.c:ethtool_get_drvinfo() {
...
if (ops->get_regs_len) {
int ret = ops->get_regs_len(dev);

if (ret > 0)
rsp->info.regdump_len = ret;
}
...
}

Userspace then sees regdump_len == 0 and sends ETHTOOL_GREGS with
regs.len == 0.

There are two in-tree examples. DSA user ports always install
dsa_user_get_regs(), so the !ops->get_regs check does not catch them, but:

net/dsa/user.c:dsa_user_get_regs_len() {
...
if (ds->ops->get_regs_len)
return ds->ops->get_regs_len(ds, dp->index);

return -EOPNOTSUPP;
}

And hns3:

drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c:hns3_get_regs_len() {
...
if (!h->ae_algo->ops->get_regs_len)
return -EOPNOTSUPP;

return h->ae_algo->ops->get_regs_len(h);
}

Before this patch, ethtool -d on these devices printed an error such as
"Cannot get register dump: Operation not supported". With this patch,
ethtool -d appears to succeed with an empty dump.

In the standard ethtool flow, this seems to undo the error reporting that
commit f9fc54d313fa ("ethtool: check the return value of get_regs_len")
added for hns3. The commit message does not mention this.

Would moving the zero-length check after the "if (reglen <= 0) return
reglen;" check keep the error codes? It would still avoid calling
get_regs() with len == 0.

[Severity: Low]
For drivers whose get_regs_len() returns a positive value, does this
change what a len == 0 query returns in regs.version?

Before this patch, such a request skipped the clamp and set reglen to 0.
It then called ops->get_regs() and copied the ethtool_regs header back.
For example, mcs7830 fills in the version:

drivers/net/usb/mcs7830.c:mcs7830_get_regs() {
...
regs->version = mcs7830_get_rev(dev);
mcs7830_get_reg(dev, 0, regs->len, data);
}

Now the ioctl returns success without calling get_regs() and without
copying the header back. regs.version keeps whatever userspace passed in.

The uAPI kernel-doc for struct ethtool_regs in
include/uapi/linux/ethtool.h still describes @version as driver-specific
output.

Stock ethtool sends len = regdump_len, so it is not affected. This only
affects callers that send len == 0 to read the version alone.

The commit message says:

A zero-length dump cannot return any data, so there is nothing for the
driver to do.

and:

Zero-length register dumps used to be issued so that drivers which only
report a revision ID could fill regs->version. Those drivers return
zero from get_regs_len(), and the core has returned early for them
since commit f9fc54d313fa ("ethtool: check the return value of
get_regs_len").

That covers the case where get_regs_len() returns 0. It does not cover
the reglen > 0 case that this patch changes.

Should the commit message or the uAPI documentation describe this change?
Alternatively, should a len == 0 request fail instead of reporting success
with the header left unfilled?

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126015239.6038-1-25031212351%40stu.xidian.edu.cn