Skip to contentSkip to conversation

phy: intel: Eliminate unnecessary assignment in intel_cbphy_set_mode

PATCH In review Nathan Chancellor 3 participants 5 messages May 23, 2020 – Jun 24, 2020 Generic PHY framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 phy: intel: Eliminate unnecessary assignment in intel_cbphy_set_mode

Clang warns:

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

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

1 warning generated.

The correct enum to use would be PCIE0_PCIE1_MODE. However, eliminating this assignment is a little better because the switch statement always assigns a new value to cb_mode, which also takes care of the warning.

Fixes ac0a95a3ea78 ("phy: intel: Add driver support for ComboPhy")
---
 drivers/phy/intel/phy-intel-combo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/intel/phy-intel-combo.c +1 -1
index c2a35be4cdfb..4bc1276ecf23 100644
@@ -199,9 +199,9 @@ 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 aggregated_mode aggr = cbphy->aggr_mode;
 	struct device *dev = cbphy->dev;
+	enum intel_combo_mode cb_mode;
 	enum intel_phy_mode mode;
 	int ret;
 

base-commit: c11d28ab4a691736e30b49813fb801847bd44e83

Signature · 1 line
2.27.0.rc0
#1 lore raw
Quoted 6 lines · Nathan Chancellor

Clang warns:

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

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

1 warning generated.

The correct enum to use would be PCIE0_PCIE1_MODE. However, eliminating this assignment is a little better because the switch statement always

Indeed, the switch is exhaustive. Might be a risk if new enumeration values are added to the enum, though.

Probably should just initialize it to PCIE0_PCIE1_MODE, then you can simplify the PHY_PCIE_MODE case a little (replace ternary with if+assignment).

Quoted 27 lines

assigns a new value to cb_mode, which also takes care of the warning.

Fixes ac0a95a3ea78 ("phy: intel: Add driver support for ComboPhy")
---
 drivers/phy/intel/phy-intel-combo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/intel/phy-intel-combo.c +1 -1
index c2a35be4cdfb..4bc1276ecf23 100644
@@ -199,9 +199,9 @@ 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 aggregated_mode aggr = cbphy->aggr_mode;
        struct device *dev = cbphy->dev;
+       enum intel_combo_mode cb_mode;
        enum intel_phy_mode mode;
        int ret;
 

base-commit: c11d28ab4a691736e30b49813fb801847bd44e83 --

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw
Quoted 12 lines · Nick Desaulniers
Quoted 10 lines · Nathan Chancellor

Clang warns:

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

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

1 warning generated.

Quoted 5 lines
Quoted 2 lines

The correct enum to use would be PCIE0_PCIE1_MODE. However, eliminating this assignment is a little better because the switch statement always

Indeed, the switch is exhaustive. Might be a risk if new enumeration values are added to the enum, though.

Clang will warn about that (and since there is no default case statement, that would point to a bug).

Quoted 3 lines

Probably should just initialize it to PCIE0_PCIE1_MODE, then you can simplify the PHY_PCIE_MODE case a little (replace ternary with if+assignment).

I did consider this but every maintainer has their preference around initializing local variables at the top versus close to their usage...

I do not really have a preference for what happens here, I'm happy to rework the patch based on maintainer feedback, thanks for the review!

Cheers,
Nathan

Quoted 31 lines
Quoted 27 lines

assigns a new value to cb_mode, which also takes care of the warning.

Fixes ac0a95a3ea78 ("phy: intel: Add driver support for ComboPhy")
---
 drivers/phy/intel/phy-intel-combo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/intel/phy-intel-combo.c +1 -1
index c2a35be4cdfb..4bc1276ecf23 100644
@@ -199,9 +199,9 @@ 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 aggregated_mode aggr = cbphy->aggr_mode;
        struct device *dev = cbphy->dev;
+       enum intel_combo_mode cb_mode;
        enum intel_phy_mode mode;
        int ret;
 

base-commit: c11d28ab4a691736e30b49813fb801847bd44e83 --

Signature · 2 lines
Thanks,
~Nick Desaulniers
#3 lore raw
In reply to Nathan Chancellor
Quoted 36 lines · Nathan Chancellor

Clang warns:

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

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

1 warning generated.

The correct enum to use would be PCIE0_PCIE1_MODE. However, eliminating this assignment is a little better because the switch statement always assigns a new value to cb_mode, which also takes care of the warning.

Fixes ac0a95a3ea78 ("phy: intel: Add driver support for ComboPhy")
---
 drivers/phy/intel/phy-intel-combo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/intel/phy-intel-combo.c +1 -1
index c2a35be4cdfb..4bc1276ecf23 100644
@@ -199,9 +199,9 @@ 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 aggregated_mode aggr = cbphy->aggr_mode;
 	struct device *dev = cbphy->dev;
+	enum intel_combo_mode cb_mode;
 	enum intel_phy_mode mode;
 	int ret;
 
Quoted 4 lines

base-commit: c11d28ab4a691736e30b49813fb801847bd44e83

Signature · 1 line
2.27.0.rc0

Gentle ping for review. Nick did comment that maybe keeping the assignment and tidying up one of the switch cases would be better but every maintainer has their preference. This warning has slipped into mainline so it would be nice to get it cleaned up.

Cheers,
Nathan

maintainer
#4 lore raw
Quoted 37 lines · Nathan Chancellor
Quoted 36 lines · Nathan Chancellor

Clang warns:

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

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

1 warning generated.

The correct enum to use would be PCIE0_PCIE1_MODE. However, eliminating this assignment is a little better because the switch statement always assigns a new value to cb_mode, which also takes care of the warning.

Fixes ac0a95a3ea78 ("phy: intel: Add driver support for ComboPhy")
---
 drivers/phy/intel/phy-intel-combo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/intel/phy-intel-combo.c +1 -1
index c2a35be4cdfb..4bc1276ecf23 100644
@@ -199,9 +199,9 @@ 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 aggregated_mode aggr = cbphy->aggr_mode;
 	struct device *dev = cbphy->dev;
+	enum intel_combo_mode cb_mode;
 	enum intel_phy_mode mode;
 	int ret;
 
Quoted 9 lines
Quoted 4 lines

base-commit: c11d28ab4a691736e30b49813fb801847bd44e83

Signature · 1 line
2.27.0.rc0

Gentle ping for review. Nick did comment that maybe keeping the assignment and tidying up one of the switch cases would be better but every maintainer has their preference. This warning has slipped into mainline so it would be nice to get it cleaned up.

Sorry for the delay, I have applied Anrd patch for this already and should be in linux-next tomorrow

Signature · 1 line
~Vinod