diff mbox series

[-next,1/6] net: thunderx: Remove unnecessary ternary operators

Message ID 20230804035346.2879318-2-ruanjinjie@huawei.com (mailing list archive)
State New, archived
Headers show
Series net: Remove unnecessary ternary operators | expand

Commit Message

Jinjie Ruan Aug. 4, 2023, 3:53 a.m. UTC
Ther are a little ternary operators, the true or false judgement
of which is unnecessary in C language semantics.

Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
---
 drivers/net/ethernet/cavium/thunder/nic_main.c    | 2 +-
 drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Jinjie Ruan Aug. 7, 2023, 4:59 a.m. UTC | #1
On 2023/8/7 9:39, Ping-Ke Shih wrote:
> 
> 
>> -----Original Message-----
>> From: Ruan Jinjie <ruanjinjie@huawei.com>
>> Sent: Friday, August 4, 2023 11:54 AM
>> To: sgoutham@marvell.com; davem@davemloft.net; edumazet@google.com; kuba@kernel.org; pabeni@redhat.com;
>> jesse.brandeburg@intel.com; anthony.l.nguyen@intel.com; tariqt@nvidia.com; s.shtylyov@omp.ru;
>> aspriel@gmail.com; franky.lin@broadcom.com; hante.meuleman@broadcom.com; kvalo@kernel.org;
>> richardcochran@gmail.com; yoshihiro.shimoda.uh@renesas.com; ruanjinjie@huawei.com;
>> u.kleine-koenig@pengutronix.de; mkl@pengutronix.de; lee@kernel.org; set_pte_at@outlook.com;
>> linux-arm-kernel@lists.infradead.org; netdev@vger.kernel.org; intel-wired-lan@lists.osuosl.org;
>> linux-rdma@vger.kernel.org; linux-renesas-soc@vger.kernel.org; linux-wireless@vger.kernel.org;
>> brcm80211-dev-list.pdl@broadcom.com; SHA-cyfmac-dev-list@infineon.com
>> Subject: [PATCH -next 1/6] net: thunderx: Remove unnecessary ternary operators
>>
>> Ther are a little ternary operators, the true or false judgement
>> of which is unnecessary in C language semantics.
>>
>> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
>> ---
>>  drivers/net/ethernet/cavium/thunder/nic_main.c    | 2 +-
>>  drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 2 +-
>>  2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/cavium/thunder/nic_main.c
>> b/drivers/net/ethernet/cavium/thunder/nic_main.c
>> index 0ec65ec634df..b7cf4ba89b7c 100644
>> --- a/drivers/net/ethernet/cavium/thunder/nic_main.c
>> +++ b/drivers/net/ethernet/cavium/thunder/nic_main.c
>> @@ -174,7 +174,7 @@ static void nic_mbx_send_ready(struct nicpf *nic, int vf)
>>                 if (mac)
>>                         ether_addr_copy((u8 *)&mbx.nic_cfg.mac_addr, mac);
>>         }
>> -       mbx.nic_cfg.sqs_mode = (vf >= nic->num_vf_en) ? true : false;
>> +       mbx.nic_cfg.sqs_mode = vf >= nic->num_vf_en;
>>         mbx.nic_cfg.node_id = nic->node;
>>
>>         mbx.nic_cfg.loopback_supported = vf < nic->num_vf_en;
>> diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
>> b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
>> index a317feb8decb..9e467cecc33a 100644
>> --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
>> +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
>> @@ -957,7 +957,7 @@ static void bgx_poll_for_sgmii_link(struct lmac *lmac)
>>                 goto next_poll;
>>         }
>>
>> -       lmac->link_up = ((pcs_link & PCS_MRX_STATUS_LINK) != 0) ? true : false;
>> +       lmac->link_up = (pcs_link & PCS_MRX_STATUS_LINK) != 0;
> 
> lmac->link_up = !!(pcs_link & PCS_MRX_STATUS_LINK);

Thank you! I'll improve it sooner.

> 
>>         an_result = bgx_reg_read(lmac->bgx, lmac->lmacid,
>>                                  BGX_GMP_PCS_ANX_AN_RESULTS);
>>
>> --
>> 2.34.1
>>
>>
>> ------Please consider the environment before printing this e-mail.
>
Jacob Keller Aug. 7, 2023, 5:34 p.m. UTC | #2
On 8/6/2023 9:59 PM, Ruan Jinjie wrote:
> 
> 
> On 2023/8/7 9:39, Ping-Ke Shih wrote:
>>
>>
>>> -----Original Message-----
>>> From: Ruan Jinjie <ruanjinjie@huawei.com>
>>> Sent: Friday, August 4, 2023 11:54 AM
>>> To: sgoutham@marvell.com; davem@davemloft.net; edumazet@google.com; kuba@kernel.org; pabeni@redhat.com;
>>> jesse.brandeburg@intel.com; anthony.l.nguyen@intel.com; tariqt@nvidia.com; s.shtylyov@omp.ru;
>>> aspriel@gmail.com; franky.lin@broadcom.com; hante.meuleman@broadcom.com; kvalo@kernel.org;
>>> richardcochran@gmail.com; yoshihiro.shimoda.uh@renesas.com; ruanjinjie@huawei.com;
>>> u.kleine-koenig@pengutronix.de; mkl@pengutronix.de; lee@kernel.org; set_pte_at@outlook.com;
>>> linux-arm-kernel@lists.infradead.org; netdev@vger.kernel.org; intel-wired-lan@lists.osuosl.org;
>>> linux-rdma@vger.kernel.org; linux-renesas-soc@vger.kernel.org; linux-wireless@vger.kernel.org;
>>> brcm80211-dev-list.pdl@broadcom.com; SHA-cyfmac-dev-list@infineon.com
>>> Subject: [PATCH -next 1/6] net: thunderx: Remove unnecessary ternary operators
>>>
>>> Ther are a little ternary operators, the true or false judgement
>>> of which is unnecessary in C language semantics.
>>>
>>> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
>>> ---
>>>  drivers/net/ethernet/cavium/thunder/nic_main.c    | 2 +-
>>>  drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 2 +-
>>>  2 files changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/net/ethernet/cavium/thunder/nic_main.c
>>> b/drivers/net/ethernet/cavium/thunder/nic_main.c
>>> index 0ec65ec634df..b7cf4ba89b7c 100644
>>> --- a/drivers/net/ethernet/cavium/thunder/nic_main.c
>>> +++ b/drivers/net/ethernet/cavium/thunder/nic_main.c
>>> @@ -174,7 +174,7 @@ static void nic_mbx_send_ready(struct nicpf *nic, int vf)
>>>                 if (mac)
>>>                         ether_addr_copy((u8 *)&mbx.nic_cfg.mac_addr, mac);
>>>         }
>>> -       mbx.nic_cfg.sqs_mode = (vf >= nic->num_vf_en) ? true : false;
>>> +       mbx.nic_cfg.sqs_mode = vf >= nic->num_vf_en;
>>>         mbx.nic_cfg.node_id = nic->node;
>>>
>>>         mbx.nic_cfg.loopback_supported = vf < nic->num_vf_en;
>>> diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
>>> b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
>>> index a317feb8decb..9e467cecc33a 100644
>>> --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
>>> +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
>>> @@ -957,7 +957,7 @@ static void bgx_poll_for_sgmii_link(struct lmac *lmac)
>>>                 goto next_poll;
>>>         }
>>>
>>> -       lmac->link_up = ((pcs_link & PCS_MRX_STATUS_LINK) != 0) ? true : false;
>>> +       lmac->link_up = (pcs_link & PCS_MRX_STATUS_LINK) != 0;
>>
>> lmac->link_up = !!(pcs_link & PCS_MRX_STATUS_LINK);
> 
> Thank you! I'll improve it sooner.
> 

I personally find "!= 0" a bit more readable than '!!' but I suppose
thats personal taste and !! is pretty common in the kernel.

Thanks,
Jake
diff mbox series

Patch

diff --git a/drivers/net/ethernet/cavium/thunder/nic_main.c b/drivers/net/ethernet/cavium/thunder/nic_main.c
index 0ec65ec634df..b7cf4ba89b7c 100644
--- a/drivers/net/ethernet/cavium/thunder/nic_main.c
+++ b/drivers/net/ethernet/cavium/thunder/nic_main.c
@@ -174,7 +174,7 @@  static void nic_mbx_send_ready(struct nicpf *nic, int vf)
 		if (mac)
 			ether_addr_copy((u8 *)&mbx.nic_cfg.mac_addr, mac);
 	}
-	mbx.nic_cfg.sqs_mode = (vf >= nic->num_vf_en) ? true : false;
+	mbx.nic_cfg.sqs_mode = vf >= nic->num_vf_en;
 	mbx.nic_cfg.node_id = nic->node;
 
 	mbx.nic_cfg.loopback_supported = vf < nic->num_vf_en;
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index a317feb8decb..9e467cecc33a 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -957,7 +957,7 @@  static void bgx_poll_for_sgmii_link(struct lmac *lmac)
 		goto next_poll;
 	}
 
-	lmac->link_up = ((pcs_link & PCS_MRX_STATUS_LINK) != 0) ? true : false;
+	lmac->link_up = (pcs_link & PCS_MRX_STATUS_LINK) != 0;
 	an_result = bgx_reg_read(lmac->bgx, lmac->lmacid,
 				 BGX_GMP_PCS_ANX_AN_RESULTS);