diff mbox series

[3/3] trace-cmd: Add msg_buf_len() function

Message ID 20190315153326.5602-4-kaslevs@vmware.com (mailing list archive)
State Accepted
Commit 22d39986959c3f97de08e17b84cac58362296072
Headers show
Series Switch V3 messages to text encoding of variable length buffer | expand

Commit Message

Slavomir Kaslev March 15, 2019, 3:33 p.m. UTC
Factor out common code computing message buffer length in a function.

No changes in behavior intended.

Signed-off-by: Slavomir Kaslev <kaslevs@vmware.com>
---
 tracecmd/trace-msg.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Steven Rostedt March 15, 2019, 7:08 p.m. UTC | #1
On Fri, 15 Mar 2019 17:33:26 +0200
Slavomir Kaslev <kaslevs@vmware.com> wrote:

> Factor out common code computing message buffer length in a function.
> 
> No changes in behavior intended.
> 
> Signed-off-by: Slavomir Kaslev <kaslevs@vmware.com>
> ---
>  tracecmd/trace-msg.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c
> index 48f1eac..a91b211 100644
> --- a/tracecmd/trace-msg.c
> +++ b/tracecmd/trace-msg.c
> @@ -107,6 +107,11 @@ struct tracecmd_msg {
>  	void					*buf;
>  } __attribute__((packed));
>  
> +static int msg_buf_len(struct tracecmd_msg *msg)

I changed this to:

static inline int msg_buf_len(...)

-- Steve

> +{
> +	return ntohl(msg->hdr.size) - MSG_HDR_LEN - ntohl(msg->hdr.cmd_size);
> +}
> +
>  static int msg_write(int fd, struct tracecmd_msg *msg)
>  {
>  	int cmd = ntohl(msg->hdr.cmd);
> @@ -425,7 +430,7 @@ int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle,
>  		goto error;
>  	}
>  
> -	buf_len = ntohl(msg.hdr.size) - MSG_HDR_LEN - ntohl(msg.hdr.cmd_size);
> +	buf_len = msg_buf_len(&msg);
>  	if (buf_len <= 0) {
>  		ret = -EINVAL;
>  		goto error;
> @@ -541,7 +546,7 @@ int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle)
>  		goto error;
>  	}
>  
> -	buf_len = ntohl(msg.hdr.size) - MSG_HDR_LEN - ntohl(msg.hdr.cmd_size);
> +	buf_len = msg_buf_len(&msg);
>  	if (buf_len < 0) {
>  		ret = -EINVAL;
>  		goto error;
> @@ -685,7 +690,7 @@ int tracecmd_msg_read_data(struct tracecmd_msg_handle *msg_handle, int ofd)
>  			goto next;
>  		}
>  
> -		n = ntohl(msg.hdr.size) - MSG_HDR_LEN - ntohl(msg.hdr.cmd_size);
> +		n = msg_buf_len(&msg);
>  		t = n;
>  		s = 0;
>  		while (t > 0) {
diff mbox series

Patch

diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c
index 48f1eac..a91b211 100644
--- a/tracecmd/trace-msg.c
+++ b/tracecmd/trace-msg.c
@@ -107,6 +107,11 @@  struct tracecmd_msg {
 	void					*buf;
 } __attribute__((packed));
 
+static int msg_buf_len(struct tracecmd_msg *msg)
+{
+	return ntohl(msg->hdr.size) - MSG_HDR_LEN - ntohl(msg->hdr.cmd_size);
+}
+
 static int msg_write(int fd, struct tracecmd_msg *msg)
 {
 	int cmd = ntohl(msg->hdr.cmd);
@@ -425,7 +430,7 @@  int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle,
 		goto error;
 	}
 
-	buf_len = ntohl(msg.hdr.size) - MSG_HDR_LEN - ntohl(msg.hdr.cmd_size);
+	buf_len = msg_buf_len(&msg);
 	if (buf_len <= 0) {
 		ret = -EINVAL;
 		goto error;
@@ -541,7 +546,7 @@  int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle)
 		goto error;
 	}
 
-	buf_len = ntohl(msg.hdr.size) - MSG_HDR_LEN - ntohl(msg.hdr.cmd_size);
+	buf_len = msg_buf_len(&msg);
 	if (buf_len < 0) {
 		ret = -EINVAL;
 		goto error;
@@ -685,7 +690,7 @@  int tracecmd_msg_read_data(struct tracecmd_msg_handle *msg_handle, int ofd)
 			goto next;
 		}
 
-		n = ntohl(msg.hdr.size) - MSG_HDR_LEN - ntohl(msg.hdr.cmd_size);
+		n = msg_buf_len(&msg);
 		t = n;
 		s = 0;
 		while (t > 0) {