Re: [PATCH v2 1/2] net: macb: Clean up macb_validate
From: Antoine Tenart <atenart@kernel.org>
Date: 2021-10-12 16:53:59
Quoting Sean Anderson (2021-10-12 18:34:50)
On 10/12/21 4:33 AM, Antoine Tenart wrote:quoted
Quoting Sean Anderson (2021-10-11 18:55:16)quoted
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.quoted
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.
I don't think having 1) validity checks 2) availability checks is an issue. It's a choice between having possible bugs because the two steps aren't synced vs possible bugs because one of the multiple paths in the switch gets slightly broken by a patch. IMHO the one easier to read and follow should win here. Antoine