Skip to contentSkip to conversation

phy: intel: fix enum type mismatch warning

PATCH Applied Arnd Bergmann 4 participants 4 messages May 27, 2020 – Jun 24, 2020 Generic PHY framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 phy: intel: fix enum type mismatch warning

clang points out that a local variable is initialized with an enum value of the wrong type:

drivers/phy/intel/phy-intel-combo.c:202:34: error: implicit conversion from enumeration type 'enum intel_phy_mode' to different enumeration type 'enum intel_combo_mode' [-Werror,-Wenum-conversion]

        enum intel_combo_mode cb_mode = PHY_PCIE_MODE;
                              ~~~~~~~   ^~~~~~~~~~~~~

From reading the code, it seems that this was not only the wrong type, but not even supposed to be a code path that can happen in practice.

Change the code to have no default phy mode but instead return an error for invalid input.

Fixes ac0a95a3ea78 ("phy: intel: Add driver support for ComboPhy")
---
 drivers/phy/intel/phy-intel-combo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/phy/intel/phy-intel-combo.c +3 -1
index c2a35be4cdfb..04f7b0d08742 100644
@@ -199,7 +199,7 @@ static int intel_cbphy_pcie_dis_pad_refclk(struct intel_cbphy_iphy *iphy)
 
 static int intel_cbphy_set_mode(struct intel_combo_phy *cbphy)
 {
-	enum intel_combo_mode cb_mode = PHY_PCIE_MODE;
+	enum intel_combo_mode cb_mode;
 	enum aggregated_mode aggr = cbphy->aggr_mode;
 	struct device *dev = cbphy->dev;
 	enum intel_phy_mode mode;
@@ -224,6 +224,8 @@ static int intel_cbphy_set_mode(struct intel_combo_phy *cbphy)
 
 		cb_mode = SATA0_SATA1_MODE;
 		break;
+	default:
+		return -EINVAL;
 	}
 
 	ret = regmap_write(cbphy->hsiocfg, REG_COMBO_MODE(cbphy->bid), cb_mode);
Signature · 1 line
2.26.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 45 lines · Arnd Bergmann

clang points out that a local variable is initialized with an enum value of the wrong type:

drivers/phy/intel/phy-intel-combo.c:202:34: error: implicit conversion from enumeration type 'enum intel_phy_mode' to different enumeration type 'enum intel_combo_mode' [-Werror,-Wenum-conversion]

        enum intel_combo_mode cb_mode = PHY_PCIE_MODE;
                              ~~~~~~~   ^~~~~~~~~~~~~

From reading the code, it seems that this was not only the wrong type, but not even supposed to be a code path that can happen in practice.

Change the code to have no default phy mode but instead return an error for invalid input.

Fixes ac0a95a3ea78 ("phy: intel: Add driver support for ComboPhy")
---
 drivers/phy/intel/phy-intel-combo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/phy/intel/phy-intel-combo.c +3 -1
index c2a35be4cdfb..04f7b0d08742 100644
@@ -199,7 +199,7 @@ static int intel_cbphy_pcie_dis_pad_refclk(struct intel_cbphy_iphy *iphy)
 
 static int intel_cbphy_set_mode(struct intel_combo_phy *cbphy)
 {
-	enum intel_combo_mode cb_mode = PHY_PCIE_MODE;
+	enum intel_combo_mode cb_mode;
 	enum aggregated_mode aggr = cbphy->aggr_mode;
 	struct device *dev = cbphy->dev;
 	enum intel_phy_mode mode;
@@ -224,6 +224,8 @@ static int intel_cbphy_set_mode(struct intel_combo_phy *cbphy)
 
 		cb_mode = SATA0_SATA1_MODE;
 		break;
+	default:
+		return -EINVAL;
 	}
 
 	ret = regmap_write(cbphy->hsiocfg, REG_COMBO_MODE(cbphy->bid), cb_mode);
Signature · 1 line
2.26.2

I sent an almost identical patch:

https://lore.kernel.org/lkml/[email protected]/

I left out the default case since clang warns when a switch on an enum does not handle all the values (compile time scream) versus a run time scream like yours.

I don't have a preference for either so:

Reviewed-by
#2 lore raw
Quoted 50 lines · Nathan Chancellor
Quoted 45 lines · Arnd Bergmann

clang points out that a local variable is initialized with an enum value of the wrong type:

drivers/phy/intel/phy-intel-combo.c:202:34: error: implicit conversion from enumeration type 'enum intel_phy_mode' to different enumeration type 'enum intel_combo_mode' [-Werror,-Wenum-conversion]

         enum intel_combo_mode cb_mode = PHY_PCIE_MODE;
                               ~~~~~~~   ^~~~~~~~~~~~~

From reading the code, it seems that this was not only the
wrong type, but not even supposed to be a code path that can happen in practice.

Change the code to have no default phy mode but instead return an error for invalid input.

Fixes ac0a95a3ea78 ("phy: intel: Add driver support for ComboPhy")
---
  drivers/phy/intel/phy-intel-combo.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/phy/intel/phy-intel-combo.c +3 -1
index c2a35be4cdfb..04f7b0d08742 100644
@@ -199,7 +199,7 @@ static int intel_cbphy_pcie_dis_pad_refclk(struct intel_cbphy_iphy *iphy)
 
  static int intel_cbphy_set_mode(struct intel_combo_phy *cbphy)
  {
-	enum intel_combo_mode cb_mode = PHY_PCIE_MODE;
+	enum intel_combo_mode cb_mode;
  	enum aggregated_mode aggr = cbphy->aggr_mode;
  	struct device *dev = cbphy->dev;
  	enum intel_phy_mode mode;
@@ -224,6 +224,8 @@ static int intel_cbphy_set_mode(struct intel_combo_phy *cbphy)
 
  		cb_mode = SATA0_SATA1_MODE;
  		break;
+	default:
+		return -EINVAL;
  	}
 
  	ret = regmap_write(cbphy->hsiocfg, REG_COMBO_MODE(cbphy->bid), cb_mode);
Signature · 1 line
2.26.2

I sent an almost identical patch:

https://lore.kernel.org/lkml/[email protected]/

Quoted 7 lines

I left out the default case since clang warns when a switch on an enum does not handle all the values (compile time scream) versus a run time scream like yours.

I don't have a preference for either so:

Thanks for fixing it. I wrongly initiated it with PHY_PCIE_MODE instead of PCIE0_PCIE1_MODE to fix the compiler warnings. (On real time use case, cb_mode gets initialized with one of the switch case values, it never hits the default case, so I didn't add the default case.)

This patch looks good to fix the warnings.

Regards,
Dilip

maintainer Applied
#3 lore raw
In reply to Arnd Bergmann
Quoted 7 lines · Arnd Bergmann

clang points out that a local variable is initialized with an enum value of the wrong type:

drivers/phy/intel/phy-intel-combo.c:202:34: error: implicit conversion from enumeration type 'enum intel_phy_mode' to different enumeration type 'enum intel_combo_mode' [-Werror,-Wenum-conversion]

        enum intel_combo_mode cb_mode = PHY_PCIE_MODE;
                              ~~~~~~~   ^~~~~~~~~~~~~
Quoted 6 lines
Quoted 1 line

From reading the code, it seems that this was not only the

wrong type, but not even supposed to be a code path that can happen in practice.

Change the code to have no default phy mode but instead return an error for invalid input.

Applied, thanks

Signature · 1 line
~Vinod