]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bnxt_en: Fix netdev locking in ULP IRQ functions
authorMichael Chan <michael.chan@broadcom.com>
Mon, 19 May 2025 20:41:28 +0000 (13:41 -0700)
committerJakub Kicinski <kuba@kernel.org>
Wed, 21 May 2025 01:52:11 +0000 (18:52 -0700)
netdev_lock is already held when calling bnxt_ulp_irq_stop() and
bnxt_ulp_irq_restart().  When converting rtnl_lock to netdev_lock,
the original code was rtnl_dereference() to indicate that rtnl_lock
was already held.  rcu_dereference_protected() is the correct
conversion after replacing rtnl_lock with netdev_lock.

Add a new helper netdev_lock_dereference() similar to
rtnl_dereference().

Fixes: 004b5008016a ("eth: bnxt: remove most dependencies on RTNL")
Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com>
Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250519204130.3097027-2-michael.chan@broadcom.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
include/net/netdev_lock.h

index a8e930d5dbb09f33e4b2afbea96d4f8bb299ba98..7564705d64783ebc91bc9cdf0b74201eb2b6a6ee 100644 (file)
@@ -20,6 +20,7 @@
 #include <asm/byteorder.h>
 #include <linux/bitmap.h>
 #include <linux/auxiliary_bus.h>
+#include <net/netdev_lock.h>
 
 #include "bnxt_hsi.h"
 #include "bnxt.h"
@@ -309,14 +310,12 @@ void bnxt_ulp_irq_stop(struct bnxt *bp)
                if (!ulp->msix_requested)
                        return;
 
-               netdev_lock(bp->dev);
-               ops = rcu_dereference(ulp->ulp_ops);
+               ops = netdev_lock_dereference(ulp->ulp_ops, bp->dev);
                if (!ops || !ops->ulp_irq_stop)
                        return;
                if (test_bit(BNXT_STATE_FW_RESET_DET, &bp->state))
                        reset = true;
                ops->ulp_irq_stop(ulp->handle, reset);
-               netdev_unlock(bp->dev);
        }
 }
 
@@ -335,8 +334,7 @@ void bnxt_ulp_irq_restart(struct bnxt *bp, int err)
                if (!ulp->msix_requested)
                        return;
 
-               netdev_lock(bp->dev);
-               ops = rcu_dereference(ulp->ulp_ops);
+               ops = netdev_lock_dereference(ulp->ulp_ops, bp->dev);
                if (!ops || !ops->ulp_irq_restart)
                        return;
 
@@ -348,7 +346,6 @@ void bnxt_ulp_irq_restart(struct bnxt *bp, int err)
                        bnxt_fill_msix_vecs(bp, ent);
                }
                ops->ulp_irq_restart(ulp->handle, ent);
-               netdev_unlock(bp->dev);
                kfree(ent);
        }
 }
index c316b551df8d61b748a9489e40225cea667cf5ac..0ee5bc7668103b6e84b6666cb9d84e62daa1080e 100644 (file)
@@ -98,6 +98,9 @@ static inline int netdev_lock_cmp_fn(const struct lockdep_map *a,
                                  &qdisc_xmit_lock_key);        \
 }
 
+#define netdev_lock_dereference(p, dev)                                \
+       rcu_dereference_protected(p, lockdep_is_held(&(dev)->lock))
+
 int netdev_debug_event(struct notifier_block *nb, unsigned long event,
                       void *ptr);