ethtool: check the return value of get_regs_len
authorYunsheng Lin <linyunsheng@huawei.com>
Wed, 26 Dec 2018 11:51:46 +0000 (19:51 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 Jun 2019 10:21:51 +0000 (12:21 +0200)
commit f9fc54d313fab2834f44f516459cdc8ac91d797f upstream.

The return type for get_regs_len in struct ethtool_ops is int,
the hns3 driver may return error when failing to get the regs
len by sending cmd to firmware.

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Cc: Michal Kubecek <mkubecek@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/core/ethtool.c

index ddf510c31f3d3d6387169fef35514b3d8827e434..97569d3e1937315eb20c199e295f5d49ec2a15ec 100644 (file)
@@ -890,8 +890,13 @@ static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
                if (rc >= 0)
                        info.n_priv_flags = rc;
        }
-       if (ops->get_regs_len)
-               info.regdump_len = ops->get_regs_len(dev);
+       if (ops->get_regs_len) {
+               int ret = ops->get_regs_len(dev);
+
+               if (ret > 0)
+                       info.regdump_len = ret;
+       }
+
        if (ops->get_eeprom_len)
                info.eedump_len = ops->get_eeprom_len(dev);
 
@@ -1392,6 +1397,9 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
                return -EFAULT;
 
        reglen = ops->get_regs_len(dev);
+       if (reglen <= 0)
+               return reglen;
+
        if (regs.len > reglen)
                regs.len = reglen;