mbox series

[net-next,0/2] net: Use helper function IS_ERR_OR_NULL()

Message ID 20230817071941.346590-1-ruanjinjie@huawei.com (mailing list archive)
Headers show
Series net: Use helper function IS_ERR_OR_NULL() | expand

Message

Jinjie Ruan Aug. 17, 2023, 7:19 a.m. UTC
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(-)

Comments

Leon Romanovsky Aug. 17, 2023, 8:02 a.m. UTC | #1
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         }
Jinjie Ruan Aug. 17, 2023, 9:50 a.m. UTC | #2
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         }
>