linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] phy: intel: fix enum type mismatch warning
@ 2020-05-27 13:45 Arnd Bergmann
  2020-05-27 16:40 ` Nathan Chancellor
  2020-06-24 12:11 ` Vinod Koul
  0 siblings, 2 replies; 4+ messages in thread
From: Arnd Bergmann @ 2020-05-27 13:45 UTC (permalink / raw)
  To: Kishon Vijay Abraham I, Vinod Koul, Dilip Kota
  Cc: Arnd Bergmann, linux-kernel, clang-built-linux

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")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/phy/intel/phy-intel-combo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/intel/phy-intel-combo.c b/drivers/phy/intel/phy-intel-combo.c
index c2a35be4cdfb..04f7b0d08742 100644
--- a/drivers/phy/intel/phy-intel-combo.c
+++ b/drivers/phy/intel/phy-intel-combo.c
@@ -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);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] phy: intel: fix enum type mismatch warning
  2020-05-27 13:45 [PATCH] phy: intel: fix enum type mismatch warning Arnd Bergmann
@ 2020-05-27 16:40 ` Nathan Chancellor
  2020-05-28  8:51   ` Dilip Kota
  2020-06-24 12:11 ` Vinod Koul
  1 sibling, 1 reply; 4+ messages in thread
From: Nathan Chancellor @ 2020-05-27 16:40 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Kishon Vijay Abraham I, Vinod Koul, Dilip Kota, linux-kernel,
	clang-built-linux

On Wed, May 27, 2020 at 03:45:06PM +0200, Arnd Bergmann wrote:
> 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")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/phy/intel/phy-intel-combo.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/phy/intel/phy-intel-combo.c b/drivers/phy/intel/phy-intel-combo.c
> index c2a35be4cdfb..04f7b0d08742 100644
> --- a/drivers/phy/intel/phy-intel-combo.c
> +++ b/drivers/phy/intel/phy-intel-combo.c
> @@ -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);
> -- 
> 2.26.2
> 

I sent an almost identical patch:

https://lore.kernel.org/lkml/20200523035043.3305846-1-natechancellor@gmail.com/

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: Nathan Chancellor <natechancellor@gmail.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] phy: intel: fix enum type mismatch warning
  2020-05-27 16:40 ` Nathan Chancellor
@ 2020-05-28  8:51   ` Dilip Kota
  0 siblings, 0 replies; 4+ messages in thread
From: Dilip Kota @ 2020-05-28  8:51 UTC (permalink / raw)
  To: Nathan Chancellor, Arnd Bergmann
  Cc: Kishon Vijay Abraham I, Vinod Koul, linux-kernel, clang-built-linux


On 5/28/2020 12:40 AM, Nathan Chancellor wrote:
> On Wed, May 27, 2020 at 03:45:06PM +0200, Arnd Bergmann wrote:
>> 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")
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>> ---
>>   drivers/phy/intel/phy-intel-combo.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/phy/intel/phy-intel-combo.c b/drivers/phy/intel/phy-intel-combo.c
>> index c2a35be4cdfb..04f7b0d08742 100644
>> --- a/drivers/phy/intel/phy-intel-combo.c
>> +++ b/drivers/phy/intel/phy-intel-combo.c
>> @@ -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);
>> -- 
>> 2.26.2
>>
> I sent an almost identical patch:
>
> https://lore.kernel.org/lkml/20200523035043.3305846-1-natechancellor@gmail.com/
>
> 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: Nathan Chancellor <natechancellor@gmail.com>
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.
Reviewed-by: Dilip Kota <eswara.kota@linux.intel.com>

Regards,
Dilip

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] phy: intel: fix enum type mismatch warning
  2020-05-27 13:45 [PATCH] phy: intel: fix enum type mismatch warning Arnd Bergmann
  2020-05-27 16:40 ` Nathan Chancellor
@ 2020-06-24 12:11 ` Vinod Koul
  1 sibling, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2020-06-24 12:11 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Kishon Vijay Abraham I, Dilip Kota, linux-kernel, clang-built-linux

On 27-05-20, 15:45, Arnd Bergmann wrote:
> 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.

Applied, thanks

-- 
~Vinod

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-06-24 12:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-27 13:45 [PATCH] phy: intel: fix enum type mismatch warning Arnd Bergmann
2020-05-27 16:40 ` Nathan Chancellor
2020-05-28  8:51   ` Dilip Kota
2020-06-24 12:11 ` Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).