Smatch warns that 'fops' is dereferenced without a NULL check. While other callbacks in this function properly check 'fops', the rx_handler registration does not. Consolidate the NULL check for 'fops' at the beginning of the function, before it is first used in slave_pre_register(). This ensures 'fops' is valid for the entire function scope and allows the removal of redundant NULL checks later in the function, as suggested by Dan Carpenter. Fixes: 30c8bd5aa8b2 ("net: Introduce generic failover module") Signed-off-by: Zeeshan Ahmad --- v3: - Move the fops NULL check to the top of the function before any dereferences occur and remove subsequent redundant NULL checks, as suggested by Dan Carpenter. v2: - Target 'net' tree as this is a bug fix. - Change logic from an early return (v1) to WARN_ON_ONCE() and abort registration, as discussed with Simon Horman. net/core/failover.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/core/failover.c b/net/core/failover.c index 2a140b3ea669..47e4a91dcaa6 100644 --- a/net/core/failover.c +++ b/net/core/failover.c @@ -59,7 +59,10 @@ static int failover_slave_register(struct net_device *slave_dev) if (!failover_dev) goto done; - if (fops && fops->slave_pre_register && + if (WARN_ON_ONCE(!fops)) + goto done; + + if (fops->slave_pre_register && fops->slave_pre_register(slave_dev, failover_dev)) goto done; @@ -82,7 +85,7 @@ static int failover_slave_register(struct net_device *slave_dev) slave_dev->priv_flags |= (IFF_FAILOVER_SLAVE | IFF_NO_ADDRCONF); - if (fops && fops->slave_register && + if (fops->slave_register && !fops->slave_register(slave_dev, failover_dev)) return NOTIFY_OK; -- 2.43.0