crypto: sa2ul - Use bitfield helpers
authorGeert Uytterhoeven <geert+renesas@glider.be>
Mon, 22 Nov 2021 15:54:02 +0000 (16:54 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 3 Dec 2021 04:56:17 +0000 (15:56 +1100)
Use the FIELD_PREP() helper, instead of open-coding the same operation.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/sa2ul.c

index bcbc38d..51b58e5 100644 (file)
@@ -8,6 +8,7 @@
  *             Vitaly Andrianov
  *             Tero Kristo
  */
+#include <linux/bitfield.h>
 #include <linux/clk.h>
 #include <linux/dma-mapping.h>
 #include <linux/dmaengine.h>
@@ -646,8 +647,8 @@ static inline void sa_update_cmdl(struct sa_req *req, u32 *cmdl,
                cmdl[upd_info->enc_offset.index] &=
                                                ~SA_CMDL_SOP_BYPASS_LEN_MASK;
                cmdl[upd_info->enc_offset.index] |=
-                       ((u32)req->enc_offset <<
-                        __ffs(SA_CMDL_SOP_BYPASS_LEN_MASK));
+                       FIELD_PREP(SA_CMDL_SOP_BYPASS_LEN_MASK,
+                                  req->enc_offset);
 
                if (likely(upd_info->flags & SA_CMDL_UPD_ENC_IV)) {
                        __be32 *data = (__be32 *)&cmdl[upd_info->enc_iv.index];
@@ -666,8 +667,8 @@ static inline void sa_update_cmdl(struct sa_req *req, u32 *cmdl,
                cmdl[upd_info->auth_offset.index] &=
                        ~SA_CMDL_SOP_BYPASS_LEN_MASK;
                cmdl[upd_info->auth_offset.index] |=
-                       ((u32)req->auth_offset <<
-                        __ffs(SA_CMDL_SOP_BYPASS_LEN_MASK));
+                       FIELD_PREP(SA_CMDL_SOP_BYPASS_LEN_MASK,
+                                  req->auth_offset);
                if (upd_info->flags & SA_CMDL_UPD_AUTH_IV) {
                        sa_copy_iv((void *)&cmdl[upd_info->auth_iv.index],
                                   req->auth_iv,
@@ -689,16 +690,16 @@ void sa_set_swinfo(u8 eng_id, u16 sc_id, dma_addr_t sc_phys,
                   u8 hash_size, u32 *swinfo)
 {
        swinfo[0] = sc_id;
-       swinfo[0] |= (flags << __ffs(SA_SW0_FLAGS_MASK));
+       swinfo[0] |= FIELD_PREP(SA_SW0_FLAGS_MASK, flags);
        if (likely(cmdl_present))
-               swinfo[0] |= ((cmdl_offset | SA_SW0_CMDL_PRESENT) <<
-                                               __ffs(SA_SW0_CMDL_INFO_MASK));
-       swinfo[0] |= (eng_id << __ffs(SA_SW0_ENG_ID_MASK));
+               swinfo[0] |= FIELD_PREP(SA_SW0_CMDL_INFO_MASK,
+                                       cmdl_offset | SA_SW0_CMDL_PRESENT);
+       swinfo[0] |= FIELD_PREP(SA_SW0_ENG_ID_MASK, eng_id);
 
        swinfo[0] |= SA_SW0_DEST_INFO_PRESENT;
        swinfo[1] = (u32)(sc_phys & 0xFFFFFFFFULL);
        swinfo[2] = (u32)((sc_phys & 0xFFFFFFFF00000000ULL) >> 32);
-       swinfo[2] |= (hash_size << __ffs(SA_SW2_EGRESS_LENGTH));
+       swinfo[2] |= FIELD_PREP(SA_SW2_EGRESS_LENGTH, hash_size);
 }
 
 /* Dump the security context */