mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Tools: hv: use full nlmsghdr in netlink_send
@ 2013-08-07 13:45 Olaf Hering
  2013-08-07 13:49 ` KY Srinivasan
  0 siblings, 1 reply; 2+ messages in thread
From: Olaf Hering @ 2013-08-07 13:45 UTC (permalink / raw)
  To: kys, gregkh; +Cc: linux-kernel, Olaf Hering

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>
---
 tools/hv/hv_kvp_daemon.c | 15 +++++----------
 tools/hv/hv_vss_daemon.c | 15 +++++----------
 2 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 1bd1ad1..7c05f55 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -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;
diff --git a/tools/hv/hv_vss_daemon.c b/tools/hv/hv_vss_daemon.c
index 2f1f53f..8ac0ee7 100644
--- a/tools/hv/hv_vss_daemon.c
+++ b/tools/hv/hv_vss_daemon.c
@@ -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;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: [PATCH] Tools: hv: use full nlmsghdr in netlink_send
  2013-08-07 13:45 [PATCH] Tools: hv: use full nlmsghdr in netlink_send Olaf Hering
@ 2013-08-07 13:49 ` KY Srinivasan
  0 siblings, 0 replies; 2+ messages in thread
From: KY Srinivasan @ 2013-08-07 13:49 UTC (permalink / raw)
  To: Olaf Hering, gregkh; +Cc: linux-kernel



> -----Original Message-----
> From: Olaf Hering [mailto:olaf@aepfle.de]
> Sent: Wednesday, August 07, 2013 9:45 AM
> To: KY Srinivasan; gregkh@linuxfoundation.org
> Cc: linux-kernel@vger.kernel.org; Olaf Hering
> Subject: [PATCH] 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>
> ---
>  tools/hv/hv_kvp_daemon.c | 15 +++++----------
>  tools/hv/hv_vss_daemon.c | 15 +++++----------
>  2 files changed, 10 insertions(+), 20 deletions(-)
> 
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index 1bd1ad1..7c05f55 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -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;
> diff --git a/tools/hv/hv_vss_daemon.c b/tools/hv/hv_vss_daemon.c
> index 2f1f53f..8ac0ee7 100644
> --- a/tools/hv/hv_vss_daemon.c
> +++ b/tools/hv/hv_vss_daemon.c
> @@ -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;




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-08-07 13:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-07 13:45 [PATCH] Tools: hv: use full nlmsghdr in netlink_send Olaf Hering
2013-08-07 13:49 ` KY Srinivasan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®