Skip to content

Commit b4fb0ca

Browse files
olafheringgregkh
authored andcommitted
Tools: hv: use full nlmsghdr in netlink_send
There is no need to have a nlmsghdr pointer to another temporary buffer. Instead use a full struct nlmsghdr. Signed-off-by: Olaf Hering <olaf@aepfle.de> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2bc41ea commit b4fb0ca

2 files changed

Lines changed: 10 additions & 20 deletions

File tree

‎tools/hv/hv_kvp_daemon.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,23 +1392,18 @@ kvp_get_domain_name(char *buffer, int length)
13921392
static int
13931393
netlink_send(int fd, struct cn_msg *msg)
13941394
{
1395-
struct nlmsghdr *nlh;
1395+
struct nlmsghdr nlh = { .nlmsg_type = NLMSG_DONE };
13961396
unsigned int size;
13971397
struct msghdr message;
1398-
char buffer[64];
13991398
struct iovec iov[2];
14001399

14011400
size = sizeof(struct cn_msg) + msg->len;
14021401

1403-
nlh = (struct nlmsghdr *)buffer;
1404-
nlh->nlmsg_seq = 0;
1405-
nlh->nlmsg_pid = getpid();
1406-
nlh->nlmsg_type = NLMSG_DONE;
1407-
nlh->nlmsg_len = NLMSG_LENGTH(size - sizeof(*nlh));
1408-
nlh->nlmsg_flags = 0;
1402+
nlh.nlmsg_pid = getpid();
1403+
nlh.nlmsg_len = NLMSG_LENGTH(size);
14091404

1410-
iov[0].iov_base = nlh;
1411-
iov[0].iov_len = sizeof(*nlh);
1405+
iov[0].iov_base = &nlh;
1406+
iov[0].iov_len = sizeof(nlh);
14121407

14131408
iov[1].iov_base = msg;
14141409
iov[1].iov_len = size;

‎tools/hv/hv_vss_daemon.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,18 @@ static int vss_operate(int operation)
105105

106106
static int netlink_send(int fd, struct cn_msg *msg)
107107
{
108-
struct nlmsghdr *nlh;
108+
struct nlmsghdr nlh = { .nlmsg_type = NLMSG_DONE };
109109
unsigned int size;
110110
struct msghdr message;
111-
char buffer[64];
112111
struct iovec iov[2];
113112

114113
size = sizeof(struct cn_msg) + msg->len;
115114

116-
nlh = (struct nlmsghdr *)buffer;
117-
nlh->nlmsg_seq = 0;
118-
nlh->nlmsg_pid = getpid();
119-
nlh->nlmsg_type = NLMSG_DONE;
120-
nlh->nlmsg_len = NLMSG_LENGTH(size - sizeof(*nlh));
121-
nlh->nlmsg_flags = 0;
115+
nlh.nlmsg_pid = getpid();
116+
nlh.nlmsg_len = NLMSG_LENGTH(size);
122117

123-
iov[0].iov_base = nlh;
124-
iov[0].iov_len = sizeof(*nlh);
118+
iov[0].iov_base = &nlh;
119+
iov[0].iov_len = sizeof(nlh);
125120

126121
iov[1].iov_base = msg;
127122
iov[1].iov_len = size;

0 commit comments

Comments
 (0)