Skip to content

Commit a9ab02e

Browse files
leitaokuba-moo
authored andcommitted
netpoll: Use rtnl_dereference() for npinfo pointer access
In the __netpoll_setup() function, when accessing the device's npinfo pointer, replace rcu_access_pointer() with rtnl_dereference(). This change is more appropriate, as suggested by Herbert Xu[1]. The function is called with the RTNL mutex held, and the pointer is being dereferenced later, so, dereference earlier and just reuse the pointer for the if/else. The replacement ensures correct pointer access while maintaining the existing locking and RCU semantics of the netpoll subsystem. Link: https://lore.kernel.org/lkml/[email protected]/ [1] Suggested-by: Herbert Xu <[email protected]> Signed-off-by: Breno Leitao <[email protected]> Reviewed-by: Jacob Keller <[email protected]> Acked-by: Herbert Xu <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent bb18265 commit a9ab02e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/core/netpoll.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,8 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
634634
goto out;
635635
}
636636

637-
if (!rcu_access_pointer(ndev->npinfo)) {
637+
npinfo = rtnl_dereference(ndev->npinfo);
638+
if (!npinfo) {
638639
npinfo = kmalloc(sizeof(*npinfo), GFP_KERNEL);
639640
if (!npinfo) {
640641
err = -ENOMEM;
@@ -654,7 +655,6 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
654655
goto free_npinfo;
655656
}
656657
} else {
657-
npinfo = rtnl_dereference(ndev->npinfo);
658658
refcount_inc(&npinfo->refcnt);
659659
}
660660

0 commit comments

Comments
 (0)