On Fri, 15 Mar 2019 17:33:26 +0200 Slavomir Kaslev <kaslevs@xxxxxxxxxx> wrote: > 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) 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) {