diff mbox series

[u-boot-net,10/14] phy: Move PHY_INTERFACE_MODE_NA to the beginning of the enum definition

Message ID 20220317124958.27921-11-kabel@kernel.org
State Superseded
Delegated to: Ramon Fried
Headers show
Series u-boot-net refactors, fixes, cleanups | expand

Commit Message

Marek Behún March 17, 2022, 12:49 p.m. UTC
From: Marek Behún <marek.behun@nic.cz>

Move PHY_INTERFACE_MODE_NA to the beginning of the enum definition to
make it have zero value. This makes it possible (although not
encouraged) to test for invalid/nonexistent interface mode with !val
instead of val == PHY_INTERFACE_MODE_NA.

The comment near the definition says "Must be last", because when the
constant was introduced in commit 5f184715ecd3 ("Create PHY Lib for
U-Boot"), it was used as the maximum value when interating over the
constants. But this is no longer true - we use PHY_INTERFACE_MODE_MAX
for that now, and so we can move it.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
 include/phy_interface.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Stefan Roese March 18, 2022, 7:34 a.m. UTC | #1
On 3/17/22 13:49, Marek Behún wrote:
> From: Marek Behún <marek.behun@nic.cz>
> 
> Move PHY_INTERFACE_MODE_NA to the beginning of the enum definition to
> make it have zero value. This makes it possible (although not
> encouraged) to test for invalid/nonexistent interface mode with !val
> instead of val == PHY_INTERFACE_MODE_NA.
> 
> The comment near the definition says "Must be last", because when the
> constant was introduced in commit 5f184715ecd3 ("Create PHY Lib for
> U-Boot"), it was used as the maximum value when interating over the
> constants. But this is no longer true - we use PHY_INTERFACE_MODE_MAX
> for that now, and so we can move it.
> 
> Signed-off-by: Marek Behún <marek.behun@nic.cz>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

> ---
>   include/phy_interface.h | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/include/phy_interface.h b/include/phy_interface.h
> index 59e119a639..ce3b5004ec 100644
> --- a/include/phy_interface.h
> +++ b/include/phy_interface.h
> @@ -13,6 +13,7 @@
>   #include <string.h>
>   
>   typedef enum {
> +	PHY_INTERFACE_MODE_NA, /* don't touch */
>   	PHY_INTERFACE_MODE_MII,
>   	PHY_INTERFACE_MODE_GMII,
>   	PHY_INTERFACE_MODE_SGMII,
> @@ -39,12 +40,11 @@ typedef enum {
>   	PHY_INTERFACE_MODE_NCSI,
>   	PHY_INTERFACE_MODE_10GBASER,
>   	PHY_INTERFACE_MODE_USXGMII,
> -	PHY_INTERFACE_MODE_NA,	/* Must be last */
> -
>   	PHY_INTERFACE_MODE_MAX,
>   } phy_interface_t;
>   
>   static const char * const phy_interface_strings[] = {
> +	[PHY_INTERFACE_MODE_NA]		= "",
>   	[PHY_INTERFACE_MODE_MII]		= "mii",
>   	[PHY_INTERFACE_MODE_GMII]		= "gmii",
>   	[PHY_INTERFACE_MODE_SGMII]		= "sgmii",
> @@ -71,7 +71,6 @@ static const char * const phy_interface_strings[] = {
>   	[PHY_INTERFACE_MODE_NCSI]		= "NC-SI",
>   	[PHY_INTERFACE_MODE_10GBASER]		= "10gbase-r",
>   	[PHY_INTERFACE_MODE_USXGMII]		= "usxgmii",
> -	[PHY_INTERFACE_MODE_NA]		= "",
>   };
>   
>   /* Backplane modes:

Viele Grüße,
Stefan Roese
Ramon Fried March 18, 2022, 8:08 a.m. UTC | #2
On Thu, Mar 17, 2022 at 2:50 PM Marek Behún <kabel@kernel.org> wrote:
>
> From: Marek Behún <marek.behun@nic.cz>
>
> Move PHY_INTERFACE_MODE_NA to the beginning of the enum definition to
> make it have zero value. This makes it possible (although not
> encouraged) to test for invalid/nonexistent interface mode with !val
> instead of val == PHY_INTERFACE_MODE_NA.
>
> The comment near the definition says "Must be last", because when the
> constant was introduced in commit 5f184715ecd3 ("Create PHY Lib for
> U-Boot"), it was used as the maximum value when interating over the
> constants. But this is no longer true - we use PHY_INTERFACE_MODE_MAX
> for that now, and so we can move it.
>
> Signed-off-by: Marek Behún <marek.behun@nic.cz>
> ---
>  include/phy_interface.h | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/include/phy_interface.h b/include/phy_interface.h
> index 59e119a639..ce3b5004ec 100644
> --- a/include/phy_interface.h
> +++ b/include/phy_interface.h
> @@ -13,6 +13,7 @@
>  #include <string.h>
>
>  typedef enum {
> +       PHY_INTERFACE_MODE_NA, /* don't touch */
>         PHY_INTERFACE_MODE_MII,
>         PHY_INTERFACE_MODE_GMII,
>         PHY_INTERFACE_MODE_SGMII,
> @@ -39,12 +40,11 @@ typedef enum {
>         PHY_INTERFACE_MODE_NCSI,
>         PHY_INTERFACE_MODE_10GBASER,
>         PHY_INTERFACE_MODE_USXGMII,
> -       PHY_INTERFACE_MODE_NA,  /* Must be last */
> -
>         PHY_INTERFACE_MODE_MAX,
>  } phy_interface_t;
>
>  static const char * const phy_interface_strings[] = {
> +       [PHY_INTERFACE_MODE_NA]         = "",
>         [PHY_INTERFACE_MODE_MII]                = "mii",
>         [PHY_INTERFACE_MODE_GMII]               = "gmii",
>         [PHY_INTERFACE_MODE_SGMII]              = "sgmii",
> @@ -71,7 +71,6 @@ static const char * const phy_interface_strings[] = {
>         [PHY_INTERFACE_MODE_NCSI]               = "NC-SI",
>         [PHY_INTERFACE_MODE_10GBASER]           = "10gbase-r",
>         [PHY_INTERFACE_MODE_USXGMII]            = "usxgmii",
> -       [PHY_INTERFACE_MODE_NA]         = "",
>  };
>
>  /* Backplane modes:
> --
> 2.34.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
diff mbox series

Patch

diff --git a/include/phy_interface.h b/include/phy_interface.h
index 59e119a639..ce3b5004ec 100644
--- a/include/phy_interface.h
+++ b/include/phy_interface.h
@@ -13,6 +13,7 @@ 
 #include <string.h>
 
 typedef enum {
+	PHY_INTERFACE_MODE_NA, /* don't touch */
 	PHY_INTERFACE_MODE_MII,
 	PHY_INTERFACE_MODE_GMII,
 	PHY_INTERFACE_MODE_SGMII,
@@ -39,12 +40,11 @@  typedef enum {
 	PHY_INTERFACE_MODE_NCSI,
 	PHY_INTERFACE_MODE_10GBASER,
 	PHY_INTERFACE_MODE_USXGMII,
-	PHY_INTERFACE_MODE_NA,	/* Must be last */
-
 	PHY_INTERFACE_MODE_MAX,
 } phy_interface_t;
 
 static const char * const phy_interface_strings[] = {
+	[PHY_INTERFACE_MODE_NA]		= "",
 	[PHY_INTERFACE_MODE_MII]		= "mii",
 	[PHY_INTERFACE_MODE_GMII]		= "gmii",
 	[PHY_INTERFACE_MODE_SGMII]		= "sgmii",
@@ -71,7 +71,6 @@  static const char * const phy_interface_strings[] = {
 	[PHY_INTERFACE_MODE_NCSI]		= "NC-SI",
 	[PHY_INTERFACE_MODE_10GBASER]		= "10gbase-r",
 	[PHY_INTERFACE_MODE_USXGMII]		= "usxgmii",
-	[PHY_INTERFACE_MODE_NA]		= "",
 };
 
 /* Backplane modes: