* [PATCH net-next 1/2] net: microchip: sparx5: Use helper function IS_ERR_OR_NULL()
2023-08-17 7:19 [PATCH net-next 0/2] net: Use helper function IS_ERR_OR_NULL() Ruan Jinjie
@ 2023-08-17 7:19 ` Ruan Jinjie
2023-08-17 7:19 ` [PATCH net-next 2/2] net: stmmac: " Ruan Jinjie
2023-08-17 8:02 ` [PATCH net-next 0/2] net: " Leon Romanovsky
2 siblings, 0 replies; 6+ messages in thread
From: Ruan Jinjie @ 2023-08-17 7:19 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, lars.povlsen, Steen.Hegelund,
daniel.machon, alexandre.torgue, joabreu, mcoquelin.stm32,
horatiu.vultur, simon.horman, netdev, linux-arm-kernel,
linux-stm32, UNGLinuxDriver
Cc: ruanjinjie
Use IS_ERR_OR_NULL() instead of open-coding it
to simplify the code.
Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
---
drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c
index 906299ad8425..bc1b4498ed04 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c
@@ -1274,7 +1274,7 @@ static int sparx5_tc_free_rule_resources(struct net_device *ndev,
int ret = 0;
vrule = vcap_get_rule(vctrl, rule_id);
- if (!vrule || IS_ERR(vrule))
+ if (IS_ERR_OR_NULL(vrule))
return -EINVAL;
sparx5_tc_free_psfp_resources(sparx5, vrule);
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net-next 2/2] net: stmmac: Use helper function IS_ERR_OR_NULL()
2023-08-17 7:19 [PATCH net-next 0/2] net: Use helper function IS_ERR_OR_NULL() Ruan Jinjie
2023-08-17 7:19 ` [PATCH net-next 1/2] net: microchip: sparx5: " Ruan Jinjie
@ 2023-08-17 7:19 ` Ruan Jinjie
2023-08-17 10:07 ` Russell King (Oracle)
2023-08-17 8:02 ` [PATCH net-next 0/2] net: " Leon Romanovsky
2 siblings, 1 reply; 6+ messages in thread
From: Ruan Jinjie @ 2023-08-17 7:19 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, lars.povlsen, Steen.Hegelund,
daniel.machon, alexandre.torgue, joabreu, mcoquelin.stm32,
horatiu.vultur, simon.horman, netdev, linux-arm-kernel,
linux-stm32
Cc: ruanjinjie
Use IS_ERR_OR_NULL() instead of open-coding it
to simplify the code.
Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 733b5e900817..fe2452a70d23 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1165,7 +1165,7 @@ static int stmmac_init_phy(struct net_device *dev)
/* Some DT bindings do not set-up the PHY handle. Let's try to
* manually parse it
*/
- if (!phy_fwnode || IS_ERR(phy_fwnode)) {
+ if (IS_ERR_OR_NULL(phy_fwnode)) {
int addr = priv->plat->phy_addr;
struct phy_device *phydev;
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH net-next 2/2] net: stmmac: Use helper function IS_ERR_OR_NULL()
2023-08-17 7:19 ` [PATCH net-next 2/2] net: stmmac: " Ruan Jinjie
@ 2023-08-17 10:07 ` Russell King (Oracle)
0 siblings, 0 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2023-08-17 10:07 UTC (permalink / raw)
To: Ruan Jinjie
Cc: davem, edumazet, kuba, pabeni, lars.povlsen, Steen.Hegelund,
daniel.machon, alexandre.torgue, joabreu, mcoquelin.stm32,
horatiu.vultur, simon.horman, netdev, linux-arm-kernel,
linux-stm32
On Thu, Aug 17, 2023 at 03:19:41PM +0800, Ruan Jinjie wrote:
> Use IS_ERR_OR_NULL() instead of open-coding it
> to simplify the code.
>
> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> ---
> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 733b5e900817..fe2452a70d23 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -1165,7 +1165,7 @@ static int stmmac_init_phy(struct net_device *dev)
> /* Some DT bindings do not set-up the PHY handle. Let's try to
> * manually parse it
> */
> - if (!phy_fwnode || IS_ERR(phy_fwnode)) {
> + if (IS_ERR_OR_NULL(phy_fwnode)) {
> int addr = priv->plat->phy_addr;
> struct phy_device *phydev;
Up to the stmmac maintainers, but I have never been a fan of
"IS_ERR_OR_NULL" because it leads to programming errors such as
those I pointed out in your changes to I2C drivers. I would
much rather see IS_ERR_OR_NULL removed from the kernel entirely.
That is my personal opinion.
In this case, it doesn't matter because we're not returning the
phy_fwnode error, we're detecting it and taking some alternative
action - but given my inherent dislike of IS_ERR_OR_NULL, I
prefer the original.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 0/2] net: Use helper function IS_ERR_OR_NULL()
2023-08-17 7:19 [PATCH net-next 0/2] net: Use helper function IS_ERR_OR_NULL() Ruan Jinjie
2023-08-17 7:19 ` [PATCH net-next 1/2] net: microchip: sparx5: " Ruan Jinjie
2023-08-17 7:19 ` [PATCH net-next 2/2] net: stmmac: " Ruan Jinjie
@ 2023-08-17 8:02 ` Leon Romanovsky
2023-08-17 9:50 ` Ruan Jinjie
2 siblings, 1 reply; 6+ messages in thread
From: Leon Romanovsky @ 2023-08-17 8:02 UTC (permalink / raw)
To: Ruan Jinjie
Cc: davem, edumazet, kuba, pabeni, lars.povlsen, Steen.Hegelund,
daniel.machon, alexandre.torgue, joabreu, mcoquelin.stm32,
horatiu.vultur, simon.horman, netdev, linux-arm-kernel,
linux-stm32
On Thu, Aug 17, 2023 at 03:19:39PM +0800, Ruan Jinjie wrote:
> Use IS_ERR_OR_NULL() instead of open-coding it
> to simplify the code.
>
> Ruan Jinjie (2):
> net: microchip: sparx5: Use helper function IS_ERR_OR_NULL()
> net: stmmac: Use helper function IS_ERR_OR_NULL()
>
> drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c | 2 +-
> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
As a side note, grep of vcap_get_rule() shows that many callers don't
properly check return value and expect it to be or valid or NULL.
For example this code is not correct:
drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c
61 vrule = vcap_get_rule(lan966x->vcap_ctrl, rule_id);
62 if (vrule) {
63 u32 value, mask;
64
65 /* Just modify the ingress port mask and exit */
66 vcap_rule_get_key_u32(vrule, VCAP_KF_IF_IGR_PORT_MASK,
67 &value, &mask);
68 mask &= ~BIT(port->chip_port);
69 vcap_rule_mod_key_u32(vrule, VCAP_KF_IF_IGR_PORT_MASK,
70 value, mask);
71
72 err = vcap_mod_rule(vrule);
73 goto free_rule;
74 }
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH net-next 0/2] net: Use helper function IS_ERR_OR_NULL()
2023-08-17 8:02 ` [PATCH net-next 0/2] net: " Leon Romanovsky
@ 2023-08-17 9:50 ` Ruan Jinjie
0 siblings, 0 replies; 6+ messages in thread
From: Ruan Jinjie @ 2023-08-17 9:50 UTC (permalink / raw)
To: Leon Romanovsky
Cc: davem, edumazet, kuba, pabeni, lars.povlsen, Steen.Hegelund,
daniel.machon, alexandre.torgue, joabreu, mcoquelin.stm32,
horatiu.vultur, simon.horman, netdev, linux-arm-kernel,
linux-stm32
On 2023/8/17 16:02, Leon Romanovsky wrote:
> On Thu, Aug 17, 2023 at 03:19:39PM +0800, Ruan Jinjie wrote:
>> Use IS_ERR_OR_NULL() instead of open-coding it
>> to simplify the code.
>>
>> Ruan Jinjie (2):
>> net: microchip: sparx5: Use helper function IS_ERR_OR_NULL()
>> net: stmmac: Use helper function IS_ERR_OR_NULL()
>>
>> drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c | 2 +-
>> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
>> 2 files changed, 2 insertions(+), 2 deletions(-)
>>
>
> Thanks,
> Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
>
> As a side note, grep of vcap_get_rule() shows that many callers don't
> properly check return value and expect it to be or valid or NULL.
Right! I will try to fix these problems together by the way. Thank you!
>
> For example this code is not correct:
> drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c
> 61 vrule = vcap_get_rule(lan966x->vcap_ctrl, rule_id);
> 62 if (vrule) {
> 63 u32 value, mask;
> 64
> 65 /* Just modify the ingress port mask and exit */
> 66 vcap_rule_get_key_u32(vrule, VCAP_KF_IF_IGR_PORT_MASK,
> 67 &value, &mask);
> 68 mask &= ~BIT(port->chip_port);
> 69 vcap_rule_mod_key_u32(vrule, VCAP_KF_IF_IGR_PORT_MASK,
> 70 value, mask);
> 71
> 72 err = vcap_mod_rule(vrule);
> 73 goto free_rule;
> 74 }
>
^ permalink raw reply [flat|nested] 6+ messages in thread