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

mctp: replace mctp_address_ok with more fine-grained helpers

Currently, we have mctp_address_ok(), which checks if an EID is in the
"valid" range of 8-254 inclusive. However, 0 and 255 may also be valid
addresses, depending on context. 0 is the NULL EID, which may be set
when physical addressing is used. 255 is valid as a destination address
for broadcasts.

This change renames mctp_address_ok to mctp_address_unicast, and adds
similar helpers for broadcast and null EIDs, which will be used in an
upcoming commit.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Jeremy Kerr and committed by
Jakub Kicinski
cb196b72 47f0bd50

+14 -4
+11 -1
include/net/mctp.h
··· 40 40 41 41 #define MCTP_INITIAL_DEFAULT_NET 1 42 42 43 - static inline bool mctp_address_ok(mctp_eid_t eid) 43 + static inline bool mctp_address_unicast(mctp_eid_t eid) 44 44 { 45 45 return eid >= 8 && eid < 255; 46 + } 47 + 48 + static inline bool mctp_address_broadcast(mctp_eid_t eid) 49 + { 50 + return eid == 255; 51 + } 52 + 53 + static inline bool mctp_address_null(mctp_eid_t eid) 54 + { 55 + return eid == 0; 46 56 } 47 57 48 58 static inline bool mctp_address_matches(mctp_eid_t match, mctp_eid_t eid)
+1 -1
net/mctp/device.c
··· 209 209 if (!mdev) 210 210 return -ENODEV; 211 211 212 - if (!mctp_address_ok(addr->s_addr)) 212 + if (!mctp_address_unicast(addr->s_addr)) 213 213 return -EINVAL; 214 214 215 215 /* Prevent duplicates. Under RTNL so don't need to lock for reading */
+1 -1
net/mctp/neigh.c
··· 143 143 } 144 144 145 145 eid = nla_get_u8(tb[NDA_DST]); 146 - if (!mctp_address_ok(eid)) { 146 + if (!mctp_address_unicast(eid)) { 147 147 NL_SET_ERR_MSG(extack, "Invalid neighbour EID"); 148 148 return -EINVAL; 149 149 }
+1 -1
net/mctp/route.c
··· 962 962 struct net *net = dev_net(mdev->dev); 963 963 struct mctp_route *rt, *ert; 964 964 965 - if (!mctp_address_ok(daddr_start)) 965 + if (!mctp_address_unicast(daddr_start)) 966 966 return -EINVAL; 967 967 968 968 if (daddr_extent > 0xff || daddr_start + daddr_extent >= 255)