netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net-core: remove unnecessary ETHTOOL_GCHANNELS initialization
@ 2020-01-22 22:33 Luigi Rizzo
  2020-01-22 23:47 ` Andrew Lunn
  0 siblings, 1 reply; 7+ messages in thread
From: Luigi Rizzo @ 2020-01-22 22:33 UTC (permalink / raw)
  To: netdev; +Cc: David S. Miller, Michal Kubecek, Luigi Rizzo

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
Signed-off-by: Luigi Rizzo <lrizzo@google.com>
---
 net/ethtool/ioctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 182bffbffa78..92442507a57e 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -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;
-- 
2.25.0.341.g760bfbb309-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] net-core: remove unnecessary ETHTOOL_GCHANNELS initialization
  2020-01-22 22:33 [PATCH] net-core: remove unnecessary ETHTOOL_GCHANNELS initialization Luigi Rizzo
@ 2020-01-22 23:47 ` Andrew Lunn
  2020-01-23  0:18   ` Luigi Rizzo
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Lunn @ 2020-01-22 23:47 UTC (permalink / raw)
  To: Luigi Rizzo; +Cc: netdev, David S. Miller, Michal Kubecek

On Wed, Jan 22, 2020 at 02:33:26PM -0800, Luigi Rizzo wrote:
> 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

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] net-core: remove unnecessary ETHTOOL_GCHANNELS initialization
  2020-01-22 23:47 ` Andrew Lunn
@ 2020-01-23  0:18   ` Luigi Rizzo
  2020-01-23  8:28     ` Michal Kubecek
  2020-01-23  8:40     ` Michal Kubecek
  0 siblings, 2 replies; 7+ messages in thread
From: Luigi Rizzo @ 2020-01-23  0:18 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: netdev, David S. Miller, Michal Kubecek

On Wed, Jan 22, 2020 at 3:47 PM Andrew Lunn <andrew@lunn.ch> wrote:
>
> On Wed, Jan 22, 2020 at 02:33:26PM -0800, Luigi Rizzo wrote:
> > 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
>
> 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

>
>      Andrew

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] net-core: remove unnecessary ETHTOOL_GCHANNELS initialization
  2020-01-23  0:18   ` Luigi Rizzo
@ 2020-01-23  8:28     ` Michal Kubecek
  2020-01-23  8:40     ` Michal Kubecek
  1 sibling, 0 replies; 7+ messages in thread
From: Michal Kubecek @ 2020-01-23  8:28 UTC (permalink / raw)
  To: netdev; +Cc: Luigi Rizzo, Andrew Lunn, David S. Miller

On Wed, Jan 22, 2020 at 04:18:56PM -0800, Luigi Rizzo wrote:
> On Wed, Jan 22, 2020 at 3:47 PM Andrew Lunn <andrew@lunn.ch> wrote:
> >
> > On Wed, Jan 22, 2020 at 02:33:26PM -0800, Luigi Rizzo wrote:
> > > 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
> >
> > 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

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.

> and only replace the value in ethtool_set_channels() with the correct
> one ETHTOOL_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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] net-core: remove unnecessary ETHTOOL_GCHANNELS initialization
  2020-01-23  0:18   ` Luigi Rizzo
  2020-01-23  8:28     ` Michal Kubecek
@ 2020-01-23  8:40     ` Michal Kubecek
  2020-01-23 17:47       ` Luigi Rizzo
  1 sibling, 1 reply; 7+ messages in thread
From: Michal Kubecek @ 2020-01-23  8:40 UTC (permalink / raw)
  To: netdev; +Cc: Luigi Rizzo, Andrew Lunn, David S. Miller

On Wed, Jan 22, 2020 at 04:18:56PM -0800, Luigi Rizzo wrote:
> On Wed, Jan 22, 2020 at 3:47 PM Andrew Lunn <andrew@lunn.ch> wrote:
> >
> > On Wed, Jan 22, 2020 at 02:33:26PM -0800, Luigi Rizzo wrote:
> > > 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
> >
> > 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

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.

> and only replace the value in ethtool_set_channels() with the correct
> one ETHTOOL_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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] net-core: remove unnecessary ETHTOOL_GCHANNELS initialization
  2020-01-23  8:40     ` Michal Kubecek
@ 2020-01-23 17:47       ` Luigi Rizzo
  2020-01-23 20:01         ` Michal Kubecek
  0 siblings, 1 reply; 7+ messages in thread
From: Luigi Rizzo @ 2020-01-23 17:47 UTC (permalink / raw)
  To: Michal Kubecek; +Cc: netdev, Andrew Lunn, David S. Miller

On Thu, Jan 23, 2020 at 12:40 AM Michal Kubecek <mkubecek@suse.cz> wrote:
>
> On Wed, Jan 22, 2020 at 04:18:56PM -0800, Luigi Rizzo wrote:
> > On Wed, Jan 22, 2020 at 3:47 PM Andrew Lunn <andrew@lunn.ch> wrote:
> > >
> > > On Wed, Jan 22, 2020 at 02:33:26PM -0800, Luigi Rizzo wrote:
> > > > 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
> > >
> > > 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
>
> 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
>
> > and only replace the value in ethtool_set_channels() with the correct
> > one ETHTOOL_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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] net-core: remove unnecessary ETHTOOL_GCHANNELS initialization
  2020-01-23 17:47       ` Luigi Rizzo
@ 2020-01-23 20:01         ` Michal Kubecek
  0 siblings, 0 replies; 7+ messages in thread
From: Michal Kubecek @ 2020-01-23 20:01 UTC (permalink / raw)
  To: netdev; +Cc: Luigi Rizzo, Andrew Lunn, David S. Miller

On Thu, Jan 23, 2020 at 09:47:56AM -0800, Luigi Rizzo wrote:
> 
> 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)

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-01-23 20:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-22 22:33 [PATCH] net-core: remove unnecessary ETHTOOL_GCHANNELS initialization Luigi Rizzo
2020-01-22 23:47 ` Andrew Lunn
2020-01-23  0:18   ` Luigi Rizzo
2020-01-23  8:28     ` Michal Kubecek
2020-01-23  8:40     ` Michal Kubecek
2020-01-23 17:47       ` Luigi Rizzo
2020-01-23 20:01         ` Michal Kubecek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).