Skip to content

Commit 1e8f6f9

Browse files
committed
mctpd: use helper to init cmds from a typed request
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
1 parent 28137d4 commit 1e8f6f9

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

src/mctpd.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ struct mctp_ctrl_cmd {
333333
struct sockaddr_mctp_ext resp_addr;
334334
};
335335

336+
#define mctp_ctrl_cmd_init_from_req_type(cmd, req) \
337+
do { \
338+
(cmd)->req = &req; \
339+
(cmd)->req_len = sizeof(req); \
340+
} while (0)
341+
336342
/* frees response data, but not cmd itself, as this will typically be on the
337343
* stack
338344
*/
@@ -1873,8 +1879,7 @@ static int endpoint_send_set_endpoint_id(const struct peer *peer,
18731879
mctp_ctrl_cmd_set_eid_set_eid; // TODO: do we want Force?
18741880
req.eid = peer->eid;
18751881

1876-
cmd.req = &req;
1877-
cmd.req_len = sizeof(req);
1882+
mctp_ctrl_cmd_init_from_req_type(&cmd, req);
18781883
rc = endpoint_query_phys(peer->ctx, dest, &cmd);
18791884
if (rc < 0)
18801885
goto out;
@@ -2489,8 +2494,7 @@ static int query_get_endpoint_id(struct ctx *ctx, const dest_phys *dest,
24892494

24902495
mctp_ctrl_msg_hdr_init_req(&req.ctrl_hdr, iid,
24912496
MCTP_CTRL_CMD_GET_ENDPOINT_ID);
2492-
cmd.req = &req;
2493-
cmd.req_len = sizeof(req);
2497+
mctp_ctrl_cmd_init_from_req_type(&cmd, req);
24942498

24952499
if (peer)
24962500
rc = endpoint_query_peer(peer, &cmd);
@@ -2598,8 +2602,7 @@ static int query_get_peer_msgtypes(struct peer *peer)
25982602

25992603
mctp_ctrl_msg_hdr_init_req(&req.ctrl_hdr, iid,
26002604
MCTP_CTRL_CMD_GET_MESSAGE_TYPE_SUPPORT);
2601-
cmd.req = &req;
2602-
cmd.req_len = sizeof(req);
2605+
mctp_ctrl_cmd_init_from_req_type(&cmd, req);
26032606

26042607
rc = endpoint_query_peer(peer, &cmd);
26052608
if (rc < 0)
@@ -2657,8 +2660,7 @@ static int query_get_peer_vdm_types(struct peer *peer)
26572660
MCTP_CTRL_CMD_GET_VENDOR_MESSAGE_SUPPORT);
26582661

26592662
memset(&cmd, 0, sizeof(cmd));
2660-
cmd.req = &req;
2661-
cmd.req_len = sizeof(req);
2663+
mctp_ctrl_cmd_init_from_req_type(&cmd, req);
26622664
rc = endpoint_query_peer(peer, &cmd);
26632665
if (rc < 0)
26642666
break;
@@ -2764,8 +2766,7 @@ static int query_get_peer_uuid_by_phys(struct ctx *ctx, const dest_phys *dest,
27642766

27652767
mctp_ctrl_msg_hdr_init_req(&req.ctrl_hdr, iid,
27662768
MCTP_CTRL_CMD_GET_ENDPOINT_UUID);
2767-
cmd.req = &req;
2768-
cmd.req_len = sizeof(req);
2769+
mctp_ctrl_cmd_init_from_req_type(&cmd, req);
27692770

27702771
rc = endpoint_query_phys(ctx, dest, &cmd);
27712772
if (rc < 0)
@@ -2803,8 +2804,7 @@ static int query_get_peer_uuid(struct peer *peer)
28032804

28042805
mctp_ctrl_msg_hdr_init_req(&req.ctrl_hdr, iid,
28052806
MCTP_CTRL_CMD_GET_ENDPOINT_UUID);
2806-
cmd.req = &req;
2807-
cmd.req_len = sizeof(req);
2807+
mctp_ctrl_cmd_init_from_req_type(&cmd, req);
28082808

28092809
rc = endpoint_query_peer(peer, &cmd);
28102810
if (rc < 0)
@@ -5832,8 +5832,7 @@ static int endpoint_send_allocate_endpoint_ids(
58325832
req.alloc_eid_op = (uint8_t)(op & 0x03);
58335833
req.pool_size = eid_pool_size;
58345834
req.start_eid = eid_start;
5835-
cmd.req = &req;
5836-
cmd.req_len = sizeof(req);
5835+
mctp_ctrl_cmd_init_from_req_type(&cmd, req);
58375836
rc = endpoint_query_peer(peer, &cmd);
58385837
if (rc < 0)
58395838
goto out;
@@ -5964,8 +5963,7 @@ static int peer_endpoint_poll(sd_event_source *s, uint64_t usec, void *userdata)
59645963
mctp_ctrl_msg_hdr_init_req(&req.ctrl_hdr, iid,
59655964
MCTP_CTRL_CMD_GET_ENDPOINT_ID);
59665965

5967-
cmd.req = &req;
5968-
cmd.req_len = sizeof(req);
5966+
mctp_ctrl_cmd_init_from_req_type(&cmd, req);
59695967

59705968
rc = endpoint_query_addr(bridge->ctx, &req_addr, false, &cmd);
59715969
if (rc < 0) {

0 commit comments

Comments
 (0)