Message ID | 20230817123726.1885512-1-ruanjinjie@huawei.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net-next] net: lan966x: Fix return value check for vcap_get_rule() | expand |
On Thu, Aug 17, 2023 at 08:37:26PM +0800, Ruan Jinjie wrote: > Since vcap_get_rule() return NULL or ERR_PTR(), just check NULL > is not correct. So use IS_ERR_OR_NULL() to fix the issue. > > Fixes: 72df3489fb10 ("net: lan966x: Add ptp trap rules") > Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com> > --- > drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) Hi Ruan Jinjie, Could we consider updating vcap_get_rule() to always return an ERR_PTR() and update the error detection conditions to use IS_ERR()? It seems to me that would be somewhat cleaner in this case.
On 2023/8/18 2:34, Simon Horman wrote: > On Thu, Aug 17, 2023 at 08:37:26PM +0800, Ruan Jinjie wrote: >> Since vcap_get_rule() return NULL or ERR_PTR(), just check NULL >> is not correct. So use IS_ERR_OR_NULL() to fix the issue. >> >> Fixes: 72df3489fb10 ("net: lan966x: Add ptp trap rules") >> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com> >> --- >> drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) > > Hi Ruan Jinjie, > > Could we consider updating vcap_get_rule() to always return an ERR_PTR() > and update the error detection conditions to use IS_ERR()? > It seems to me that would be somewhat cleaner in this case. Sure, I'll try to do it. Thank you!
diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c b/drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c index 60bd0cff6677..0aa87ea6c324 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c @@ -59,7 +59,7 @@ static int lan966x_ptp_add_trap(struct lan966x_port *port, int err; vrule = vcap_get_rule(lan966x->vcap_ctrl, rule_id); - if (vrule) { + if (!IS_ERR_OR_NULL(vrule)) { u32 value, mask; /* Just modify the ingress port mask and exit */ @@ -106,7 +106,7 @@ static int lan966x_ptp_del_trap(struct lan966x_port *port, int err; vrule = vcap_get_rule(lan966x->vcap_ctrl, rule_id); - if (!vrule) + if (IS_ERR_OR_NULL(vrule)) return -EEXIST; vcap_rule_get_key_u32(vrule, VCAP_KF_IF_IGR_PORT_MASK, &value, &mask);
Since vcap_get_rule() return NULL or ERR_PTR(), just check NULL is not correct. So use IS_ERR_OR_NULL() to fix the issue. Fixes: 72df3489fb10 ("net: lan966x: Add ptp trap rules") Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com> --- drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)