Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-wired-lan] [PATCH] igb: Convert a series of if statements to switch case
@ 2022-05-10  2:57 xiaolinkui
  2022-05-11  6:32 ` Paul Menzel
  0 siblings, 1 reply; 7+ messages in thread
From: xiaolinkui @ 2022-05-10  2:57 UTC (permalink / raw)
  To: intel-wired-lan

From: Linkui Xiao<xiaolinkui@kylinos.cn>

Convert a series of if statements that handle different events to
a switch case statement to simplify the code.

Signed-off-by: Linkui Xiao<xiaolinkui@kylinos.cn>
---
 drivers/net/ethernet/intel/igb/igb_main.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 34b33b21e0dc..4ce0718eeff6 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -4588,13 +4588,17 @@ static inline void igb_set_vf_vlan_strip(struct igb_adapter *adapter,
 	struct e1000_hw *hw = &adapter->hw;
 	u32 val, reg;
 
-	if (hw->mac.type < e1000_82576)
+	switch (hw->mac.type) {
+	case e1000_undefined:
+	case e1000_82575:
 		return;
-
-	if (hw->mac.type == e1000_i350)
+	case e1000_i350:
 		reg = E1000_DVMOLR(vfn);
-	else
+		break;
+	default:
 		reg = E1000_VMOLR(vfn);
+		break;
+	}
 
 	val = rd32(reg);
 	if (enable)
-- 
2.17.1


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

* [Intel-wired-lan] [PATCH] igb: Convert a series of if statements to switch case
  2022-05-10  2:57 xiaolinkui
@ 2022-05-11  6:32 ` Paul Menzel
  2022-05-11  9:13   ` Linkui Xiao
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Menzel @ 2022-05-11  6:32 UTC (permalink / raw)
  To: intel-wired-lan

Dear Linkui,


Thank you for your patch.

Am 10.05.22 um 04:57 schrieb xiaolinkui:
> From: Linkui Xiao<xiaolinkui@kylinos.cn>

Please add a space before the <.

> Convert a series of if statements that handle different events to
> a switch case statement to simplify the code.

(Nit: Please use 75 characters per line.)

> Signed-off-by: Linkui Xiao<xiaolinkui@kylinos.cn>
> ---
>   drivers/net/ethernet/intel/igb/igb_main.c | 12 ++++++++----
>   1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
> index 34b33b21e0dc..4ce0718eeff6 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> @@ -4588,13 +4588,17 @@ static inline void igb_set_vf_vlan_strip(struct igb_adapter *adapter,
>   	struct e1000_hw *hw = &adapter->hw;
>   	u32 val, reg;
>   
> -	if (hw->mac.type < e1000_82576)
> +	switch (hw->mac.type) {
> +	case e1000_undefined:
> +	case e1000_82575:
>   		return;
> -
> -	if (hw->mac.type == e1000_i350)
> +	case e1000_i350:
>   		reg = E1000_DVMOLR(vfn);
> -	else
> +		break;
> +	default:
>   		reg = E1000_VMOLR(vfn);
> +		break;
> +	}
>   
>   	val = rd32(reg);
>   	if (enable)

Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>


Kind regards,

Paul

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

* [Intel-wired-lan] [PATCH] igb: Convert a series of if statements to switch case
  2022-05-11  6:32 ` Paul Menzel
@ 2022-05-11  9:13   ` Linkui Xiao
  0 siblings, 0 replies; 7+ messages in thread
From: Linkui Xiao @ 2022-05-11  9:13 UTC (permalink / raw)
  To: intel-wired-lan

Dear Paul:

Thank you for your reply and suggestions, I will send the V2 version soon.

On 5/11/22 14:32, Paul Menzel wrote:
> Dear Linkui,
>
>
> Thank you for your patch.
>
> Am 10.05.22 um 04:57 schrieb xiaolinkui:
>> From: Linkui Xiao<xiaolinkui@kylinos.cn>
>
> Please add a space before the <.
>
>> Convert a series of if statements that handle different events to
>> a switch case statement to simplify the code.
>
> (Nit: Please use 75 characters per line.)
>
>> Signed-off-by: Linkui Xiao<xiaolinkui@kylinos.cn>
>> ---
>> ? drivers/net/ethernet/intel/igb/igb_main.c | 12 ++++++++----
>> ? 1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c 
>> b/drivers/net/ethernet/intel/igb/igb_main.c
>> index 34b33b21e0dc..4ce0718eeff6 100644
>> --- a/drivers/net/ethernet/intel/igb/igb_main.c
>> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
>> @@ -4588,13 +4588,17 @@ static inline void 
>> igb_set_vf_vlan_strip(struct igb_adapter *adapter,
>> ????? struct e1000_hw *hw = &adapter->hw;
>> ????? u32 val, reg;
>> ? -??? if (hw->mac.type < e1000_82576)
>> +??? switch (hw->mac.type) {
>> +??? case e1000_undefined:
>> +??? case e1000_82575:
>> ????????? return;
>> -
>> -??? if (hw->mac.type == e1000_i350)
>> +??? case e1000_i350:
>> ????????? reg = E1000_DVMOLR(vfn);
>> -??? else
>> +??????? break;
>> +??? default:
>> ????????? reg = E1000_VMOLR(vfn);
>> +??????? break;
>> +??? }
>> ? ????? val = rd32(reg);
>> ????? if (enable)
>
> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
>
>
> Kind regards,
>
> Paul

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

* [Intel-wired-lan] [PATCH] igb: Convert a series of if statements to switch case
@ 2022-05-11  9:20 xiaolinkui
  2022-05-12 13:14 ` David Laight
  0 siblings, 1 reply; 7+ messages in thread
From: xiaolinkui @ 2022-05-11  9:20 UTC (permalink / raw)
  To: intel-wired-lan

From: Linkui Xiao <xiaolinkui@kylinos.cn>

Convert a series of if statements that handle different events to a switch
case statement to simplify the code.

V2: fix patch description and email format.

Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
---
 drivers/net/ethernet/intel/igb/igb_main.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 34b33b21e0dc..4ce0718eeff6 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -4588,13 +4588,17 @@ static inline void igb_set_vf_vlan_strip(struct igb_adapter *adapter,
 	struct e1000_hw *hw = &adapter->hw;
 	u32 val, reg;
 
-	if (hw->mac.type < e1000_82576)
+	switch (hw->mac.type) {
+	case e1000_undefined:
+	case e1000_82575:
 		return;
-
-	if (hw->mac.type == e1000_i350)
+	case e1000_i350:
 		reg = E1000_DVMOLR(vfn);
-	else
+		break;
+	default:
 		reg = E1000_VMOLR(vfn);
+		break;
+	}
 
 	val = rd32(reg);
 	if (enable)
-- 
2.17.1


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

* [Intel-wired-lan] [PATCH] igb: Convert a series of if statements to switch case
  2022-05-11  9:20 [Intel-wired-lan] [PATCH] igb: Convert a series of if statements to switch case xiaolinkui
@ 2022-05-12 13:14 ` David Laight
  2022-05-12 13:31   ` Linkui Xiao
  2022-05-12 18:47   ` Tony Nguyen
  0 siblings, 2 replies; 7+ messages in thread
From: David Laight @ 2022-05-12 13:14 UTC (permalink / raw)
  To: intel-wired-lan

> From: Linkui Xiao <xiaolinkui@kylinos.cn>
>
> Convert a series of if statements that handle different events to a switch
> case statement to simplify the code.
>
> V2: fix patch description and email format.
>
> Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
> ---
>  drivers/net/ethernet/intel/igb/igb_main.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
> index 34b33b21e0dc..4ce0718eeff6 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> @@ -4588,13 +4588,17 @@ static inline void igb_set_vf_vlan_strip(struct igb_adapter *adapter,
>       struct e1000_hw *hw = &adapter->hw;
>       u32 val, reg;
>
> -     if (hw->mac.type < e1000_82576)
> +     switch (hw->mac.type) {
> +     case e1000_undefined:
> +     case e1000_82575:
>               return;
> -
> -     if (hw->mac.type == e1000_i350)
> +     case e1000_i350:
>               reg = E1000_DVMOLR(vfn);
> -     else
> +             break;
> +     default:
>               reg = E1000_VMOLR(vfn);
> +             break;
> +     }
>
>       val = rd32(reg);
>       if (enable)
> --
> 2.17.1

Are you sure that generates reasonable code?
The compiler could generate something completely different
for the two versions.

It isn't even obvious they are equivalent.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* [Intel-wired-lan] [PATCH] igb: Convert a series of if statements to switch case
  2022-05-12 13:14 ` David Laight
@ 2022-05-12 13:31   ` Linkui Xiao
  2022-05-12 18:47   ` Tony Nguyen
  1 sibling, 0 replies; 7+ messages in thread
From: Linkui Xiao @ 2022-05-12 13:31 UTC (permalink / raw)
  To: intel-wired-lan

Dear David,

Thanks for your reply

Logically the two versions are equivalent, hw->mac.type is defined as 
follows:

enum e1000_mac_type {
 ??????? e1000_undefined = 0,
 ??????? e1000_82575,
 ??????? e1000_82576,
 ??????? e1000_82580,
 ??????? e1000_i350,
 ??????? e1000_i354,
 ??????? e1000_i210,
 ??????? e1000_i211,
 ??????? e1000_num_macs? /* List is 1-based, so subtract 1 for true 
count. */
};
Therefore, hw->mac.type < e1000_82576 has only two cases: 
e1000_undefined or e1000_82575.

On 5/12/22 21:14, David Laight wrote:
>> From: Linkui Xiao <xiaolinkui@kylinos.cn>
>>
>> Convert a series of if statements that handle different events to a switch
>> case statement to simplify the code.
>>
>> V2: fix patch description and email format.
>>
>> Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
>> ---
>>   drivers/net/ethernet/intel/igb/igb_main.c | 12 ++++++++----
>>   1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
>> index 34b33b21e0dc..4ce0718eeff6 100644
>> --- a/drivers/net/ethernet/intel/igb/igb_main.c
>> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
>> @@ -4588,13 +4588,17 @@ static inline void igb_set_vf_vlan_strip(struct igb_adapter *adapter,
>>        struct e1000_hw *hw = &adapter->hw;
>>        u32 val, reg;
>>
>> -     if (hw->mac.type < e1000_82576)
>> +     switch (hw->mac.type) {
>> +     case e1000_undefined:
>> +     case e1000_82575:
>>                return;
>> -
>> -     if (hw->mac.type == e1000_i350)
>> +     case e1000_i350:
>>                reg = E1000_DVMOLR(vfn);
>> -     else
>> +             break;
>> +     default:
>>                reg = E1000_VMOLR(vfn);
>> +             break;
>> +     }
>>
>>        val = rd32(reg);
>>        if (enable)
>> --
>> 2.17.1
> Are you sure that generates reasonable code?
> The compiler could generate something completely different
> for the two versions.
>
> It isn't even obvious they are equivalent.
>
> 	David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>

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

* [Intel-wired-lan] [PATCH] igb: Convert a series of if statements to switch case
  2022-05-12 13:14 ` David Laight
  2022-05-12 13:31   ` Linkui Xiao
@ 2022-05-12 18:47   ` Tony Nguyen
  1 sibling, 0 replies; 7+ messages in thread
From: Tony Nguyen @ 2022-05-12 18:47 UTC (permalink / raw)
  To: intel-wired-lan



On 5/12/2022 6:14 AM, David Laight wrote:
>> From: Linkui Xiao <xiaolinkui@kylinos.cn>
>>
>> Convert a series of if statements that handle different events to a switch
>> case statement to simplify the code.
>>
>> V2: fix patch description and email format.
>>
>> Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
>> ---
>>   drivers/net/ethernet/intel/igb/igb_main.c | 12 ++++++++----
>>   1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
>> index 34b33b21e0dc..4ce0718eeff6 100644
>> --- a/drivers/net/ethernet/intel/igb/igb_main.c
>> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
>> @@ -4588,13 +4588,17 @@ static inline void igb_set_vf_vlan_strip(struct igb_adapter *adapter,
>>        struct e1000_hw *hw = &adapter->hw;
>>        u32 val, reg;
>>
>> -     if (hw->mac.type < e1000_82576)
>> +     switch (hw->mac.type) {
>> +     case e1000_undefined:
>> +     case e1000_82575:
>>                return;
>> -
>> -     if (hw->mac.type == e1000_i350)
>> +     case e1000_i350:
>>                reg = E1000_DVMOLR(vfn);
>> -     else
>> +             break;
>> +     default:
>>                reg = E1000_VMOLR(vfn);
>> +             break;
>> +     }
>>
>>        val = rd32(reg);
>>        if (enable)
>> --
>> 2.17.1
> 
> Are you sure that generates reasonable code?
> The compiler could generate something completely different
> for the two versions.
> 
> It isn't even obvious they are equivalent.

It seems like these just happen to line up this way and appear to be two 
different checks; one as the bail out for unsupported MACs and the other 
for register reads for supported ones. Combining them seems to muddy 
that distinction.

Thanks,
Tony

> 
> 	David
> 
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
> 

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

end of thread, other threads:[~2022-05-12 18:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-11  9:20 [Intel-wired-lan] [PATCH] igb: Convert a series of if statements to switch case xiaolinkui
2022-05-12 13:14 ` David Laight
2022-05-12 13:31   ` Linkui Xiao
2022-05-12 18:47   ` Tony Nguyen
  -- strict thread matches above, loose matches on Subject: below --
2022-05-10  2:57 xiaolinkui
2022-05-11  6:32 ` Paul Menzel
2022-05-11  9:13   ` Linkui Xiao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox