All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Anderson <sean.anderson@seco.com>
To: Antoine Tenart <atenart@kernel.org>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	netdev@vger.kernel.org
Cc: Russell King <linux@armlinux.org.uk>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Claudiu Beznea <claudiu.beznea@microchip.com>
Subject: Re: [PATCH v2 1/2] net: macb: Clean up macb_validate
Date: Tue, 12 Oct 2021 12:34:50 -0400	[thread overview]
Message-ID: <419c2d47-4748-8ba4-613c-cc99558eeb48@seco.com> (raw)
In-Reply-To: <163402758460.4280.9175185858026827934@kwain>



On 10/12/21 4:33 AM, Antoine Tenart wrote:
> Hello Sean,
>
> Quoting Sean Anderson (2021-10-11 18:55:16)
>> As the number of interfaces grows, the number of if statements grows
>> ever more unweildy. Clean everything up a bit by using a switch
>> statement. No functional change intended.
>
> I'm not 100% convinced this makes macb_validate more readable: there are
> lots of conditions, and jumps, in the switch.

The conditions are necessary to determine if the mac actually supports
the mode being requested. The jumps are all forward, and all but one
could be replaced with

	bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
	return;

The idea being that the NA mode goes from top to bottom, and all the
other modes do as well.

> Maybe you could try a mixed approach; keeping the invalid modes checks
> (bitmap_zero) at the beginning and once we know the mode is valid using
> a switch statement. That might make it easier to read as this should
> remove lots of conditionals. (We'll still have the one/_NA checks
> though).

This is actually the issue I wanted to address. The interface checks are
effectively performed twice or sometimes three times. There are also
gotos in the original design to deal with e.g. 10GBASE not having
10/100/1000 modes. This makes it easy to introduce bugs when adding new
modes, such as what happened with SGMII.

> (Also having patch 1 first will improve things).

Yes. Some of the complexity is simply to deal with SGMII being a special
case.

--Sean

  parent reply	other threads:[~2021-10-12 16:35 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-11 16:55 [PATCH v2 1/2] net: macb: Clean up macb_validate Sean Anderson
2021-10-11 16:55 ` [PATCH v2 2/2] net: macb: Allow SGMII only if we are a GEM in mac_validate Sean Anderson
2021-10-12  0:17   ` Jakub Kicinski
2021-10-12  8:27     ` Antoine Tenart
2021-10-12 16:20       ` Sean Anderson
2021-10-12  8:33 ` [PATCH v2 1/2] net: macb: Clean up macb_validate Antoine Tenart
2021-10-12  8:34   ` Antoine Tenart
2021-10-12  9:24   ` Nicolas Ferre
2021-10-12 16:34   ` Sean Anderson [this message]
2021-10-12 16:53     ` Antoine Tenart
2021-10-14 16:34   ` Russell King (Oracle)
2021-10-14 17:50     ` Sean Anderson
2021-10-14 23:08       ` Russell King (Oracle)
2021-10-15 22:28         ` Sean Anderson
2021-10-15 22:47           ` Russell King (Oracle)
2021-10-19 15:02             ` Russell King (Oracle)
2021-10-22 17:37               ` Sean Anderson
2021-10-25 10:35                 ` Russell King (Oracle)
2021-10-25 15:26                   ` Sean Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=419c2d47-4748-8ba4-613c-cc99558eeb48@seco.com \
    --to=sean.anderson@seco.com \
    --cc=atenart@kernel.org \
    --cc=claudiu.beznea@microchip.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.