Tools: hv: use full nlmsghdr in netlink_send
PATCH 1/1 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 <[email protected]>
--- tools/hv/hv_kvp_daemon.c | 15 +++++---------- tools/hv/hv_vss_daemon.c | 15 +++++---------- 2 files changed, 10 insertions(+), 20 deletions(-)
tools/hv/hv_kvp_daemon.c +5 -10
@@ -1393,23 +1393,18 @@ kvp_get_domain_name(char *buffer, int length)static int netlink_send (int fd,struct cn_msg *msg) { -struct nlmsghdr *nlh; +struct nlmsghdr nlh = { .nlmsg_type =NLMSG_DONE };unsigned int size;struct msghdr message; -char buffer[64 ];struct iovec iov[2 ]; size =sizeof (struct cn_msg ) + msg->len; - nlh = (struct nlmsghdr *)buffer; - nlh->nlmsg_seq =0 ; - nlh->nlmsg_pid =getpid (); - nlh->nlmsg_type =NLMSG_DONE ; - nlh->nlmsg_len =NLMSG_LENGTH (size -sizeof (*nlh)); - nlh->nlmsg_flags =0 ; + nlh.nlmsg_pid =getpid (); + nlh.nlmsg_len =NLMSG_LENGTH (size); - iov[0 ].iov_base = nlh; - iov[0 ].iov_len =sizeof (*nlh); + iov[0 ].iov_base = &nlh; + iov[0 ].iov_len =sizeof (nlh); iov[1 ].iov_base = msg; iov[1 ].iov_len = size;
tools/hv/hv_vss_daemon.c +5 -10
@@ -105,23 +105,18 @@ static int vss_operate(int operation)static int netlink_send (int fd,struct cn_msg *msg) { -struct nlmsghdr *nlh; +struct nlmsghdr nlh = { .nlmsg_type =NLMSG_DONE };unsigned int size;struct msghdr message; -char buffer[64 ];struct iovec iov[2 ]; size =sizeof (struct cn_msg ) + msg->len; - nlh = (struct nlmsghdr *)buffer; - nlh->nlmsg_seq =0 ; - nlh->nlmsg_pid =getpid (); - nlh->nlmsg_type =NLMSG_DONE ; - nlh->nlmsg_len =NLMSG_LENGTH (size -sizeof (*nlh)); - nlh->nlmsg_flags =0 ; + nlh.nlmsg_pid =getpid (); + nlh.nlmsg_len =NLMSG_LENGTH (size); - iov[0 ].iov_base = nlh; - iov[0 ].iov_len =sizeof (*nlh); + iov[0 ].iov_base = &nlh; + iov[0 ].iov_len =sizeof (nlh); iov[1 ].iov_base = msg; iov[1 ].iov_len = size;
Quoted 9 lines
-----Original Message-----
From: Olaf Hering [mailto:[email protected]]
Sent: Wednesday, August 07, 2013 9:45 AM
To: KY Srinivasan; [email protected]
Cc: [email protected]; Olaf Hering
Subject: [PATCH] Tools: hv: use full nlmsghdr innetlink_send
Quoted 4 lines
There is no need to have a nlmsghdr pointer to another temporary buffer. Instead use a full struct nlmsghdr.
Signed-off-by Olaf Hering <[email protected]>
Signed-off-by K. Y. Srinivasan <[email protected]>
Quoted 71 lines
--- tools/hv/hv_kvp_daemon.c | 15 +++++---------- tools/hv/hv_vss_daemon.c | 15 +++++---------- 2 files changed, 10 insertions(+), 20 deletions(-)tools/hv/hv_kvp_daemon.c +5
-10@@ -1393,23 +1393,18 @@ kvp_get_domain_name(char *buffer, int length)static int netlink_send (int fd,struct cn_msg *msg) { -struct nlmsghdr *nlh; +struct nlmsghdr nlh = { .nlmsg_type =NLMSG_DONE };unsigned int size;struct msghdr message; -char buffer[64 ];struct iovec iov[2 ]; size =sizeof (struct cn_msg ) + msg->len; - nlh = (struct nlmsghdr *)buffer; - nlh->nlmsg_seq =0 ; - nlh->nlmsg_pid =getpid (); - nlh->nlmsg_type =NLMSG_DONE ; - nlh->nlmsg_len =NLMSG_LENGTH (size -sizeof (*nlh)); - nlh->nlmsg_flags =0 ; + nlh.nlmsg_pid =getpid (); + nlh.nlmsg_len =NLMSG_LENGTH (size); - iov[0 ].iov_base = nlh; - iov[0 ].iov_len =sizeof (*nlh); + iov[0 ].iov_base = &nlh; + iov[0 ].iov_len =sizeof (nlh); iov[1 ].iov_base = msg; iov[1 ].iov_len = size;tools/hv/hv_vss_daemon.c +5
-10@@ -105,23 +105,18 @@ static int vss_operate(int operation)static int netlink_send (int fd,struct cn_msg *msg) { -struct nlmsghdr *nlh; +struct nlmsghdr nlh = { .nlmsg_type =NLMSG_DONE };unsigned int size;struct msghdr message; -char buffer[64 ];struct iovec iov[2 ]; size =sizeof (struct cn_msg ) + msg->len; - nlh = (struct nlmsghdr *)buffer; - nlh->nlmsg_seq =0 ; - nlh->nlmsg_pid =getpid (); - nlh->nlmsg_type =NLMSG_DONE ; - nlh->nlmsg_len =NLMSG_LENGTH (size -sizeof (*nlh)); - nlh->nlmsg_flags =0 ; + nlh.nlmsg_pid =getpid (); + nlh.nlmsg_len =NLMSG_LENGTH (size); - iov[0 ].iov_base = nlh; - iov[0 ].iov_len =sizeof (*nlh); + iov[0 ].iov_base = &nlh; + iov[0 ].iov_len =sizeof (nlh); iov[1 ].iov_base = msg; iov[1 ].iov_len = size;