Skip to content

Commit 7c9e1c3

Browse files
jk-ozlabsNipaLocal
authored and
NipaLocal
committed
net: mctp: use nlmsg_payload() for netlink message data extraction
Jakub suggests: > I have a different request :) Matt, once this ends up in net-next > (end of this week) could you refactor it to use nlmsg_payload() ? > It doesn't exist in net but this is exactly why it was added. This refactors the additions to both mctp_dump_addrinfo(), and mctp_rtm_getneigh() - two cases where we're calling nlh_data() on an an incoming netlink message, without a prior nlmsg_parse(). Signed-off-by: Jeremy Kerr <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent 4b96948 commit 7c9e1c3

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

net/mctp/device.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ static int mctp_dump_addrinfo(struct sk_buff *skb, struct netlink_callback *cb)
120120
int ifindex = 0, rc;
121121

122122
/* Filter by ifindex if a header is provided */
123-
if (cb->nlh->nlmsg_len >= nlmsg_msg_size(sizeof(*hdr))) {
124-
hdr = nlmsg_data(cb->nlh);
123+
hdr = nlmsg_payload(cb->nlh, sizeof(*hdr));
124+
if (hdr) {
125125
ifindex = hdr->ifa_index;
126126
} else {
127127
if (cb->strict_check) {

net/mctp/neigh.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,10 @@ static int mctp_rtm_getneigh(struct sk_buff *skb, struct netlink_callback *cb)
250250
int idx;
251251
} *cbctx = (void *)cb->ctx;
252252

253-
ndmsg = nlmsg_data(cb->nlh);
253+
ndmsg = nlmsg_payload(cb->nlh, sizeof(*ndmsg));
254+
if (!ndmsg)
255+
return -EINVAL;
256+
254257
req_ifindex = ndmsg->ndm_ifindex;
255258

256259
idx = 0;

0 commit comments

Comments
 (0)