Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ethtool: ethtool_get_drvinfo: populate drvinfo fields even if callback exits

If ethtool_ops::get_drvinfo() callback isn't set,
ethtool_get_drvinfo() will fill the ethtool_drvinfo::name and
ethtool_drvinfo::bus_info fields.

However, if the driver provides the callback function, those two
fields are not touched. This means that the driver has to fill these
itself.

Allow the driver to leave those two fields empty and populate them in
such case. This way, the driver can rely on the default values for the
name and the bus_info. If the driver provides values, do nothing.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Link: https://lore.kernel.org/r/20221108035754.2143-1-mailhol.vincent@wanadoo.fr
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Vincent Mailhol and committed by
Jakub Kicinski
edaf5df2 0c9ef08a

+10 -3
+10 -3
net/ethtool/ioctl.c
··· 706 706 ethtool_get_drvinfo(struct net_device *dev, struct ethtool_devlink_compat *rsp) 707 707 { 708 708 const struct ethtool_ops *ops = dev->ethtool_ops; 709 + struct device *parent = dev->dev.parent; 709 710 710 711 rsp->info.cmd = ETHTOOL_GDRVINFO; 711 712 strscpy(rsp->info.version, UTS_RELEASE, sizeof(rsp->info.version)); 712 713 if (ops->get_drvinfo) { 713 714 ops->get_drvinfo(dev, &rsp->info); 714 - } else if (dev->dev.parent && dev->dev.parent->driver) { 715 - strscpy(rsp->info.bus_info, dev_name(dev->dev.parent), 715 + if (!rsp->info.bus_info[0] && parent) 716 + strscpy(rsp->info.bus_info, dev_name(parent), 717 + sizeof(rsp->info.bus_info)); 718 + if (!rsp->info.driver[0] && parent && parent->driver) 719 + strscpy(rsp->info.driver, parent->driver->name, 720 + sizeof(rsp->info.driver)); 721 + } else if (parent && parent->driver) { 722 + strscpy(rsp->info.bus_info, dev_name(parent), 716 723 sizeof(rsp->info.bus_info)); 717 - strscpy(rsp->info.driver, dev->dev.parent->driver->name, 724 + strscpy(rsp->info.driver, parent->driver->name, 718 725 sizeof(rsp->info.driver)); 719 726 } else if (dev->rtnl_link_ops) { 720 727 strscpy(rsp->info.driver, dev->rtnl_link_ops->kind,