Commit 2f11cf2 KCM: Introduce kcm_input_get_payload_len()

1 file Authored by fidencio 2 months ago , Committed by jhrozek 2 months ago ,
KCM: Introduce kcm_input_get_payload_len()

As this piece of code will be useful for us in the future patches of
this series, let's move it to a new function.

Signed-off-by: Fabiano FidĂȘncio <fidencio@redhat.com>

Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>

    
 1 @@ -129,23 +129,27 @@
 2       struct kcm_iovec v_msg;
 3   };
 4   
 5 + static uint32_t kcm_input_get_payload_len(struct kcm_iovec *v)
 6 + {
 7 +     size_t lc = 0;
 8 +     uint32_t len_be = 0;
 9 + 
10 +     /* The first 4 bytes before the payload is message length */
11 +     SAFEALIGN_COPY_UINT32_CHECK(&len_be, v->kiov_base, v->kiov_len, &lc);
12 + 
13 +     return be32toh(len_be);
14 + }
15 + 
16   static errno_t kcm_input_parse(struct kcm_reqbuf *reqbuf,
17                                  struct kcm_op_io *op_io)
18   {
19 -     size_t lc = 0;
20       size_t mc = 0;
21       uint16_t opcode_be = 0;
22 -     uint32_t len_be = 0;
23       uint32_t msglen;
24       uint8_t proto_maj = 0;
25       uint8_t proto_min = 0;
26   
27 -     /* The first 4 bytes before the payload is message length */
28 -     SAFEALIGN_COPY_UINT32_CHECK(&len_be,
29 -                                 reqbuf->v_len.kiov_base,
30 -                                 reqbuf->v_len.kiov_len,
31 -                                 &lc);
32 -     msglen = be32toh(len_be);
33 +     msglen = kcm_input_get_payload_len(&reqbuf->v_len);
34       DEBUG(SSSDBG_TRACE_LIBS,
35             "Received message with length %"PRIu32"\n", msglen);
36