[PATCH net-next v1] ethtool: ethtool_get_drvinfo: populate drvinfo fields even if callback exits

Vincent Mailhol posted 1 patch 3 years, 5 months ago
net/ethtool/ioctl.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
[PATCH net-next v1] ethtool: ethtool_get_drvinfo: populate drvinfo fields even if callback exits
Posted by Vincent Mailhol 3 years, 5 months ago
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>
---
 net/ethtool/ioctl.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 57e7238a4136..546f931c3b6c 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -713,15 +713,22 @@ static int
 ethtool_get_drvinfo(struct net_device *dev, struct ethtool_devlink_compat *rsp)
 {
 	const struct ethtool_ops *ops = dev->ethtool_ops;
+	struct device *parent = dev->dev.parent;
 
 	rsp->info.cmd = ETHTOOL_GDRVINFO;
 	strscpy(rsp->info.version, UTS_RELEASE, sizeof(rsp->info.version));
 	if (ops->get_drvinfo) {
 		ops->get_drvinfo(dev, &rsp->info);
-	} else if (dev->dev.parent && dev->dev.parent->driver) {
-		strscpy(rsp->info.bus_info, dev_name(dev->dev.parent),
+		if (!rsp->info.bus_info[0] && parent)
+			strscpy(rsp->info.bus_info, dev_name(parent),
+				sizeof(rsp->info.bus_info));
+		if (!rsp->info.driver[0] && parent && parent->driver)
+			strscpy(rsp->info.driver, parent->driver->name,
+				sizeof(rsp->info.driver));
+	} else if (parent && parent->driver) {
+		strscpy(rsp->info.bus_info, dev_name(parent),
 			sizeof(rsp->info.bus_info));
-		strscpy(rsp->info.driver, dev->dev.parent->driver->name,
+		strscpy(rsp->info.driver, parent->driver->name,
 			sizeof(rsp->info.driver));
 	} else if (dev->rtnl_link_ops) {
 		strscpy(rsp->info.driver, dev->rtnl_link_ops->kind,
-- 
2.37.4
Re: [PATCH net-next v1] ethtool: ethtool_get_drvinfo: populate drvinfo fields even if callback exits
Posted by patchwork-bot+netdevbpf@kernel.org 3 years, 5 months ago
Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Tue,  8 Nov 2022 12:57:54 +0900 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [net-next,v1] ethtool: ethtool_get_drvinfo: populate drvinfo fields even if callback exits
    https://git.kernel.org/netdev/net-next/c/edaf5df22cb8

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Re: [PATCH net-next v1] ethtool: ethtool_get_drvinfo: populate drvinfo fields even if callback exits
Posted by Leon Romanovsky 3 years, 5 months ago
On Tue, Nov 08, 2022 at 12:57:54PM +0900, Vincent Mailhol wrote:
> 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.

Can you please point to such drivers? One can argue that they don't need
to touch these fields in a first place and ethtool_drvinfo should always
overwrite them.

Thanks