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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Factor out common code computing message buffer length in a function.

No changes in behavior intended.

Signed-off-by: Slavomir Kaslev <kaslevs@xxxxxxxxxx>
---
 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)
+{
+	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) {
-- 
2.19.1




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux