]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: core: failover: enforce mandatory ops and clean up redundant checks
authorZeeshan Ahmad <zeeshanahmad022019@gmail.com>
Mon, 2 Mar 2026 06:43:17 +0000 (11:43 +0500)
committerJakub Kicinski <kuba@kernel.org>
Wed, 4 Mar 2026 01:44:11 +0000 (17:44 -0800)
The failover framework requires 'ops' to be functional. Currently,
failover_register() allows an instance to be registered with NULL
ops, which leads to inconsistent NULL checks and potential NULL
pointer dereferences in the slave registration paths.

Harden the entry point by requiring non-NULL ops in
failover_register(). This ensures the 'fops' pointer is guaranteed
to be valid for any successfully registered failover instance.
Consequently, remove the now redundant NULL checks for 'fops'
throughout the module to simplify the logic.

Signed-off-by: Zeeshan Ahmad <zeeshanahmad022019@gmail.com>
Link: https://patch.msgid.link/20260302064317.9964-1-zeeshanahmad022019@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/failover.c

index 0eb2e0ec875b300ee558fbfc299249806f3e3ba3..11bb183c7a1bacf3466664a420a5276af9e225f0 100644 (file)
@@ -59,7 +59,7 @@ static int failover_slave_register(struct net_device *slave_dev)
        if (!failover_dev)
                goto done;
 
-       if (fops && fops->slave_pre_register &&
+       if (fops->slave_pre_register &&
            fops->slave_pre_register(slave_dev, failover_dev))
                goto done;
 
@@ -82,7 +82,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;
 
@@ -115,7 +115,7 @@ int failover_slave_unregister(struct net_device *slave_dev)
        if (!failover_dev)
                goto done;
 
-       if (fops && fops->slave_pre_unregister &&
+       if (fops->slave_pre_unregister &&
            fops->slave_pre_unregister(slave_dev, failover_dev))
                goto done;
 
@@ -123,7 +123,7 @@ int failover_slave_unregister(struct net_device *slave_dev)
        netdev_upper_dev_unlink(slave_dev, failover_dev);
        slave_dev->priv_flags &= ~(IFF_FAILOVER_SLAVE | IFF_NO_ADDRCONF);
 
-       if (fops && fops->slave_unregister &&
+       if (fops->slave_unregister &&
            !fops->slave_unregister(slave_dev, failover_dev))
                return NOTIFY_OK;
 
@@ -149,7 +149,7 @@ static int failover_slave_link_change(struct net_device *slave_dev)
        if (!netif_running(failover_dev))
                goto done;
 
-       if (fops && fops->slave_link_change &&
+       if (fops->slave_link_change &&
            !fops->slave_link_change(slave_dev, failover_dev))
                return NOTIFY_OK;
 
@@ -174,7 +174,7 @@ static int failover_slave_name_change(struct net_device *slave_dev)
        if (!netif_running(failover_dev))
                goto done;
 
-       if (fops && fops->slave_name_change &&
+       if (fops->slave_name_change &&
            !fops->slave_name_change(slave_dev, failover_dev))
                return NOTIFY_OK;
 
@@ -244,7 +244,7 @@ struct failover *failover_register(struct net_device *dev,
 {
        struct failover *failover;
 
-       if (dev->type != ARPHRD_ETHER)
+       if (dev->type != ARPHRD_ETHER || !ops)
                return ERR_PTR(-EINVAL);
 
        failover = kzalloc_obj(*failover);