Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

can: af_can: do not access proto_tab directly use rcu_access_pointer instead

"proto_tab" is a RCU protected array, when directly accessing the array,
sparse throws these warnings:

CHECK /srv/work/frogger/socketcan/linux/net/can/af_can.c
net/can/af_can.c:115:14: error: incompatible types in comparison expression (different address spaces)
net/can/af_can.c:795:17: error: incompatible types in comparison expression (different address spaces)
net/can/af_can.c:816:9: error: incompatible types in comparison expression (different address spaces)

This patch fixes the problem by using rcu_access_pointer() and
annotating "proto_tab" array as __rcu.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

+3 -3
+3 -3
net/can/af_can.c
··· 78 78 static struct kmem_cache *rcv_cache __read_mostly; 79 79 80 80 /* table of registered CAN protocols */ 81 - static const struct can_proto *proto_tab[CAN_NPROTO] __read_mostly; 81 + static const struct can_proto __rcu *proto_tab[CAN_NPROTO] __read_mostly; 82 82 static DEFINE_MUTEX(proto_tab_lock); 83 83 84 84 static atomic_t skbcounter = ATOMIC_INIT(0); ··· 788 788 789 789 mutex_lock(&proto_tab_lock); 790 790 791 - if (proto_tab[proto]) { 791 + if (rcu_access_pointer(proto_tab[proto])) { 792 792 pr_err("can: protocol %d already registered\n", proto); 793 793 err = -EBUSY; 794 794 } else ··· 812 812 int proto = cp->protocol; 813 813 814 814 mutex_lock(&proto_tab_lock); 815 - BUG_ON(proto_tab[proto] != cp); 815 + BUG_ON(rcu_access_pointer(proto_tab[proto]) != cp); 816 816 RCU_INIT_POINTER(proto_tab[proto], NULL); 817 817 mutex_unlock(&proto_tab_lock); 818 818