net-core: remove unnecessary ETHTOOL_GCHANNELS initialization
Subsystems (3)
PATCH 1/1 net-core: remove unnecessary ETHTOOL_GCHANNELS initialization
struct ethtool_channels does not need .cmd to be set when calling the driver's ethtool methods. Just zero-initialize it.
Tested: run ethtool -l and ethtool -L
--- net/ethtool/ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ethtool/ioctl.c +2 -2
@@ -1555,7 +1555,7 @@ static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr) static noinline_for_stack int ethtool_get_channels(struct net_device *dev,void __user *useraddr) { -struct ethtool_channels channels = { .cmd =ETHTOOL_GCHANNELS }; +struct ethtool_channels channels = {};if (!dev->ethtool_ops->get_channels)return -EOPNOTSUPP ;
@@ -1570,7 +1570,7 @@ static noinline_for_stack int ethtool_get_channels(struct net_device *dev, static noinline_for_stack int ethtool_set_channels(struct net_device *dev,void __user *useraddr) { -struct ethtool_channels channels, curr = { .cmd =ETHTOOL_GCHANNELS }; +struct ethtool_channels channels, curr = {};u16 from_channel, to_channel;u32 max_rx_in_use =0 ;unsigned int i;
Signature · 1 line
2.25.0.341.g760bfbb309-goog
Andrew Lunn
maintainerQuoted 4 lines · Luigi Rizzo
struct
ethtool_channelsdoes not need .cmd to be set when calling the driver's ethtool methods. Just zero-initialize it.Tested: run ethtool -l and ethtool -L
Hi Luigi
This seems pretty risky. You are assuming ethtool is the only user of this API. What is actually wrong with putting a sane cmd value, rather than the undefined value 0.
Andrew
Quoted 5 lines · Andrew Lunn
Quoted 3 lines · Luigi Rizzo
struct
ethtool_channelsdoes not need .cmd to be set when calling the driver's ethtool methods. Just zero-initialize it.
Quoted 7 lines
Quoted 1 line
Tested: run ethtool -l and ethtool -L
Hi Luigi
This seems pretty risky. You are assuming ethtool is the only user of this API. What is actually wrong with putting a sane cmd value, rather than the undefined value 0.
Hi Andrew, if I understand correctly your suggestion is that even if the values are
unused, it is better to stay compliant with the header file include/uapi/linux/ethtool.h,
which does suggest a value for .cmd for the various structs, and only replace the value
in ethtool_set_channels() with the correct one ETHTOOL_SCHANNELS ?
cheers
luigi
Quoted 2 lines
Andrew
Quoted 10 lines · Luigi Rizzo
Quoted 9 lines · Andrew Lunn
Quoted 4 lines · Luigi Rizzo
struct
ethtool_channelsdoes not need .cmd to be set when calling the driver's ethtool methods. Just zero-initialize it.Tested: run ethtool -l and ethtool -L
Hi Luigi
Quoted 8 lines
Quoted 3 lines
This seems pretty risky. You are assuming ethtool is the only user of this API. What is actually wrong with putting a sane cmd value, rather than the undefined value 0.
Hi Andrew, if I understand correctly your suggestion is that even if the values are unused, it is better to stay compliant with the header file
include/uapi/linux/ethtool.h, which does suggest a value for .cmd for the various structs
The point is that unless you check ethtool_ops::get_channels() of all in tree drivers, you cannot be sure there isn't one which depends on .cmd being set to expected value. And even then there could be some out of tree drivers; we usually don't care too much about those but it's always question of what you gain by the cleanup. AFAICS, in this case it might be few CPU cycles and even that isn't really sure.
Quoted 2 lines
and only replace the value in
ethtool_set_channels()with the correct oneETHTOOL_SCHANNELS?
That would be incorrect. In ethtool_set_channels(), the structure initialized is curr which is used with ->get_channels() to get current values (for comparison of new values against driver maximum) so that ETHTOOL_GCHANNELS is the right command.
Michal
Quoted 10 lines · Luigi Rizzo
Quoted 9 lines · Andrew Lunn
Quoted 4 lines · Luigi Rizzo
struct
ethtool_channelsdoes not need .cmd to be set when calling the driver's ethtool methods. Just zero-initialize it.Tested: run ethtool -l and ethtool -L
Hi Luigi
Quoted 8 lines
Quoted 3 lines
This seems pretty risky. You are assuming ethtool is the only user of this API. What is actually wrong with putting a sane cmd value, rather than the undefined value 0.
Hi Andrew, if I understand correctly your suggestion is that even if the values are unused, it is better to stay compliant with the header file
include/uapi/linux/ethtool.h, which does suggest a value for .cmd for the various structs
Unless you check all in tree drivers, you cannot be sure there isn't one which would in fact rely on .cmd being set to expected value. And even then there could be some out of tree driver; we usually don't care too much about them but it's always matter of what you gain by the cleanup. AFAICS it might be just few CPU cycles in this case - if we are lucky.
Quoted 2 lines
and only replace the value in
ethtool_set_channels()with the correct oneETHTOOL_SCHANNELS?
That would be incorrect. The initialization in ethtool_set_channels() is for curr variable which is passed to ->get_channels() (to get current values for checking new values against maximum). Therefore the correct command really is ETHTOOL_GCHANNELS.
Michal
Quoted 21 lines · Michal Kubecek
Quoted 10 lines · Luigi Rizzo
Quoted 9 lines · Andrew Lunn
Quoted 4 lines · Luigi Rizzo
struct
ethtool_channelsdoes not need .cmd to be set when calling the driver's ethtool methods. Just zero-initialize it.Tested: run ethtool -l and ethtool -L
Hi Luigi
Quoted 8 lines
Quoted 3 lines
This seems pretty risky. You are assuming ethtool is the only user of this API. What is actually wrong with putting a sane cmd value, rather than the undefined value 0.
Hi Andrew, if I understand correctly your suggestion is that even if the values are unused, it is better to stay compliant with the header file
include/uapi/linux/ethtool.h, which does suggest a value for .cmd for the various structs
Quoted 5 lines
Unless you check all in tree drivers, you cannot be sure there isn't one which would in fact rely on .cmd being set to expected value. And even then there could be some out of tree driver; we usually don't care too much about them but it's always matter of what you gain by the cleanup. AFAICS it might be just few CPU cycles in this case - if we are lucky.
The change was not about CPU savings, but trying to remove what I thought were misleading or incorrect values.
Now I stand corrected, thank you for the feedback:
the header mentions that cmd should have a value
so let it be in, and as you say later, the first operation in ethtool_set_channels()
is a get_channels so ETHTOOL_GCHANNELS is the correct value.
For the same reason though (comply with the header) we might perhaps want to replace with cmd with ETHTOOL_SCHANNELS before actually calling dev->ethtool_ops->set_channels()
(I realize this is not particularly important)
cheers
luigi
Quoted 10 lines
Quoted 3 lines
and only replace the value in
ethtool_set_channels()with the correct oneETHTOOL_SCHANNELS?That would be incorrect. The initialization in
ethtool_set_channels()is for curr variable which is passed to ->get_channels() (to get current values for checking new values against maximum). Therefore the correct command really isETHTOOL_GCHANNELS.Michal
Quoted 6 lines · Luigi Rizzo
For the same reason though (comply with the header) we might perhaps want to replace with cmd with
ETHTOOL_SCHANNELSbefore actually callingdev->ethtool_ops->set_channels()(I realize this is not particularly important)
That structure is filled by copy_from_user() and the structure passed by userspace already has .cmd = ETHTOOL_SCHANNELS - otherwise we wouldn't end up in ethtool_set_channels().
Michal