Skip to content

Commit 9b20cbf

Browse files
committed
crypto: sun4i-ss - Fix sparse endianness markers
This patch also fixes the incorrect endianness markings in the sun4i-ss driver. It should have no effect in the genereated code. Instead of using cpu_to_Xe32 followed by a memcpy, this patch converts the final hash write to use put_unaligned_X instead. Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Tested-by: Corentin Labbe <clabbe.montjoie@gmail.com> Acked-by: Corentin Labbe <clabbe.montjoie@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 2ca7319 commit 9b20cbf

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* You could find the datasheet in Documentation/arm/sunxi.rst
1010
*/
1111
#include "sun4i-ss.h"
12+
#include <asm/unaligned.h>
1213
#include <linux/scatterlist.h>
1314

1415
/* This is a totally arbitrary value */
@@ -196,7 +197,7 @@ static int sun4i_hash(struct ahash_request *areq)
196197
struct sg_mapping_iter mi;
197198
int in_r, err = 0;
198199
size_t copied = 0;
199-
__le32 wb = 0;
200+
u32 wb = 0;
200201

201202
dev_dbg(ss->dev, "%s %s bc=%llu len=%u mode=%x wl=%u h0=%0x",
202203
__func__, crypto_tfm_alg_name(areq->base.tfm),
@@ -408,7 +409,7 @@ static int sun4i_hash(struct ahash_request *areq)
408409

409410
nbw = op->len - 4 * nwait;
410411
if (nbw) {
411-
wb = cpu_to_le32(*(u32 *)(op->buf + nwait * 4));
412+
wb = le32_to_cpup((__le32 *)(op->buf + nwait * 4));
412413
wb &= GENMASK((nbw * 8) - 1, 0);
413414

414415
op->byte_count += nbw;
@@ -417,7 +418,7 @@ static int sun4i_hash(struct ahash_request *areq)
417418

418419
/* write the remaining bytes of the nbw buffer */
419420
wb |= ((1 << 7) << (nbw * 8));
420-
bf[j++] = le32_to_cpu(wb);
421+
((__le32 *)bf)[j++] = cpu_to_le32(wb);
421422

422423
/*
423424
* number of space to pad to obtain 64o minus 8(size) minus 4 (final 1)
@@ -479,16 +480,16 @@ static int sun4i_hash(struct ahash_request *areq)
479480
/* Get the hash from the device */
480481
if (op->mode == SS_OP_SHA1) {
481482
for (i = 0; i < 5; i++) {
483+
v = readl(ss->base + SS_MD0 + i * 4);
482484
if (ss->variant->sha1_in_be)
483-
v = cpu_to_le32(readl(ss->base + SS_MD0 + i * 4));
485+
put_unaligned_le32(v, areq->result + i * 4);
484486
else
485-
v = cpu_to_be32(readl(ss->base + SS_MD0 + i * 4));
486-
memcpy(areq->result + i * 4, &v, 4);
487+
put_unaligned_be32(v, areq->result + i * 4);
487488
}
488489
} else {
489490
for (i = 0; i < 4; i++) {
490-
v = cpu_to_le32(readl(ss->base + SS_MD0 + i * 4));
491-
memcpy(areq->result + i * 4, &v, 4);
491+
v = readl(ss->base + SS_MD0 + i * 4);
492+
put_unaligned_le32(v, areq->result + i * 4);
492493
}
493494
}
494495

0 commit comments

Comments
 (0)