Skip to content

Commit b20d9a7

Browse files
committed
crypto: nx - Fix numerous sparse byte-order warnings
The nx driver started out its life as a BE-only driver. However, somewhere along the way LE support was partially added. This never seems to have been extended all the way but it does trigger numerous warnings during build. This patch fixes all those warnings, but it doesn't mean that the driver will work on LE. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 2a96726 commit b20d9a7

8 files changed

Lines changed: 32 additions & 22 deletions

File tree

drivers/crypto/nx/nx-aes-cbc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static int cbc_aes_nx_crypt(struct skcipher_request *req,
8888

8989
memcpy(req->iv, csbcpb->cpb.aes_cbc.cv, AES_BLOCK_SIZE);
9090
atomic_inc(&(nx_ctx->stats->aes_ops));
91-
atomic64_add(csbcpb->csb.processed_byte_count,
91+
atomic64_add(be32_to_cpu(csbcpb->csb.processed_byte_count),
9292
&(nx_ctx->stats->aes_bytes));
9393

9494
processed += to_process;

drivers/crypto/nx/nx-aes-ccm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ static int ccm_nx_decrypt(struct aead_request *req,
391391

392392
/* update stats */
393393
atomic_inc(&(nx_ctx->stats->aes_ops));
394-
atomic64_add(csbcpb->csb.processed_byte_count,
394+
atomic64_add(be32_to_cpu(csbcpb->csb.processed_byte_count),
395395
&(nx_ctx->stats->aes_bytes));
396396

397397
processed += to_process;
@@ -460,7 +460,7 @@ static int ccm_nx_encrypt(struct aead_request *req,
460460

461461
/* update stats */
462462
atomic_inc(&(nx_ctx->stats->aes_ops));
463-
atomic64_add(csbcpb->csb.processed_byte_count,
463+
atomic64_add(be32_to_cpu(csbcpb->csb.processed_byte_count),
464464
&(nx_ctx->stats->aes_bytes));
465465

466466
processed += to_process;

drivers/crypto/nx/nx-aes-ctr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static int ctr_aes_nx_crypt(struct skcipher_request *req, u8 *iv)
102102
memcpy(iv, csbcpb->cpb.aes_cbc.cv, AES_BLOCK_SIZE);
103103

104104
atomic_inc(&(nx_ctx->stats->aes_ops));
105-
atomic64_add(csbcpb->csb.processed_byte_count,
105+
atomic64_add(be32_to_cpu(csbcpb->csb.processed_byte_count),
106106
&(nx_ctx->stats->aes_bytes));
107107

108108
processed += to_process;

drivers/crypto/nx/nx-aes-ecb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static int ecb_aes_nx_crypt(struct skcipher_request *req,
8686
goto out;
8787

8888
atomic_inc(&(nx_ctx->stats->aes_ops));
89-
atomic64_add(csbcpb->csb.processed_byte_count,
89+
atomic64_add(be32_to_cpu(csbcpb->csb.processed_byte_count),
9090
&(nx_ctx->stats->aes_bytes));
9191

9292
processed += to_process;

drivers/crypto/nx/nx-aes-gcm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static int gcm_aes_nx_crypt(struct aead_request *req, int enc,
382382
NX_CPB_FDM(csbcpb) |= NX_FDM_CONTINUATION;
383383

384384
atomic_inc(&(nx_ctx->stats->aes_ops));
385-
atomic64_add(csbcpb->csb.processed_byte_count,
385+
atomic64_add(be32_to_cpu(csbcpb->csb.processed_byte_count),
386386
&(nx_ctx->stats->aes_bytes));
387387

388388
processed += to_process;

drivers/crypto/nx/nx-sha256.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
#include "nx_csbcpb.h"
1717
#include "nx.h"
1818

19+
struct sha256_state_be {
20+
__be32 state[SHA256_DIGEST_SIZE / 4];
21+
u64 count;
22+
u8 buf[SHA256_BLOCK_SIZE];
23+
};
1924

2025
static int nx_crypto_ctx_sha256_init(struct crypto_tfm *tfm)
2126
{
@@ -36,7 +41,7 @@ static int nx_crypto_ctx_sha256_init(struct crypto_tfm *tfm)
3641
}
3742

3843
static int nx_sha256_init(struct shash_desc *desc) {
39-
struct sha256_state *sctx = shash_desc_ctx(desc);
44+
struct sha256_state_be *sctx = shash_desc_ctx(desc);
4045

4146
memset(sctx, 0, sizeof *sctx);
4247

@@ -56,7 +61,7 @@ static int nx_sha256_init(struct shash_desc *desc) {
5661
static int nx_sha256_update(struct shash_desc *desc, const u8 *data,
5762
unsigned int len)
5863
{
59-
struct sha256_state *sctx = shash_desc_ctx(desc);
64+
struct sha256_state_be *sctx = shash_desc_ctx(desc);
6065
struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(&desc->tfm->base);
6166
struct nx_csbcpb *csbcpb = (struct nx_csbcpb *)nx_ctx->csbcpb;
6267
struct nx_sg *out_sg;
@@ -175,7 +180,7 @@ static int nx_sha256_update(struct shash_desc *desc, const u8 *data,
175180

176181
static int nx_sha256_final(struct shash_desc *desc, u8 *out)
177182
{
178-
struct sha256_state *sctx = shash_desc_ctx(desc);
183+
struct sha256_state_be *sctx = shash_desc_ctx(desc);
179184
struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(&desc->tfm->base);
180185
struct nx_csbcpb *csbcpb = (struct nx_csbcpb *)nx_ctx->csbcpb;
181186
struct nx_sg *in_sg, *out_sg;
@@ -245,7 +250,7 @@ static int nx_sha256_final(struct shash_desc *desc, u8 *out)
245250

246251
static int nx_sha256_export(struct shash_desc *desc, void *out)
247252
{
248-
struct sha256_state *sctx = shash_desc_ctx(desc);
253+
struct sha256_state_be *sctx = shash_desc_ctx(desc);
249254

250255
memcpy(out, sctx, sizeof(*sctx));
251256

@@ -254,7 +259,7 @@ static int nx_sha256_export(struct shash_desc *desc, void *out)
254259

255260
static int nx_sha256_import(struct shash_desc *desc, const void *in)
256261
{
257-
struct sha256_state *sctx = shash_desc_ctx(desc);
262+
struct sha256_state_be *sctx = shash_desc_ctx(desc);
258263

259264
memcpy(sctx, in, sizeof(*sctx));
260265

@@ -268,8 +273,8 @@ struct shash_alg nx_shash_sha256_alg = {
268273
.final = nx_sha256_final,
269274
.export = nx_sha256_export,
270275
.import = nx_sha256_import,
271-
.descsize = sizeof(struct sha256_state),
272-
.statesize = sizeof(struct sha256_state),
276+
.descsize = sizeof(struct sha256_state_be),
277+
.statesize = sizeof(struct sha256_state_be),
273278
.base = {
274279
.cra_name = "sha256",
275280
.cra_driver_name = "sha256-nx",

drivers/crypto/nx/nx-sha512.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
#include "nx_csbcpb.h"
1616
#include "nx.h"
1717

18+
struct sha512_state_be {
19+
__be64 state[SHA512_DIGEST_SIZE / 8];
20+
u64 count[2];
21+
u8 buf[SHA512_BLOCK_SIZE];
22+
};
1823

1924
static int nx_crypto_ctx_sha512_init(struct crypto_tfm *tfm)
2025
{
@@ -36,7 +41,7 @@ static int nx_crypto_ctx_sha512_init(struct crypto_tfm *tfm)
3641

3742
static int nx_sha512_init(struct shash_desc *desc)
3843
{
39-
struct sha512_state *sctx = shash_desc_ctx(desc);
44+
struct sha512_state_be *sctx = shash_desc_ctx(desc);
4045

4146
memset(sctx, 0, sizeof *sctx);
4247

@@ -56,7 +61,7 @@ static int nx_sha512_init(struct shash_desc *desc)
5661
static int nx_sha512_update(struct shash_desc *desc, const u8 *data,
5762
unsigned int len)
5863
{
59-
struct sha512_state *sctx = shash_desc_ctx(desc);
64+
struct sha512_state_be *sctx = shash_desc_ctx(desc);
6065
struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(&desc->tfm->base);
6166
struct nx_csbcpb *csbcpb = (struct nx_csbcpb *)nx_ctx->csbcpb;
6267
struct nx_sg *out_sg;
@@ -178,7 +183,7 @@ static int nx_sha512_update(struct shash_desc *desc, const u8 *data,
178183

179184
static int nx_sha512_final(struct shash_desc *desc, u8 *out)
180185
{
181-
struct sha512_state *sctx = shash_desc_ctx(desc);
186+
struct sha512_state_be *sctx = shash_desc_ctx(desc);
182187
struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(&desc->tfm->base);
183188
struct nx_csbcpb *csbcpb = (struct nx_csbcpb *)nx_ctx->csbcpb;
184189
struct nx_sg *in_sg, *out_sg;
@@ -251,7 +256,7 @@ static int nx_sha512_final(struct shash_desc *desc, u8 *out)
251256

252257
static int nx_sha512_export(struct shash_desc *desc, void *out)
253258
{
254-
struct sha512_state *sctx = shash_desc_ctx(desc);
259+
struct sha512_state_be *sctx = shash_desc_ctx(desc);
255260

256261
memcpy(out, sctx, sizeof(*sctx));
257262

@@ -260,7 +265,7 @@ static int nx_sha512_export(struct shash_desc *desc, void *out)
260265

261266
static int nx_sha512_import(struct shash_desc *desc, const void *in)
262267
{
263-
struct sha512_state *sctx = shash_desc_ctx(desc);
268+
struct sha512_state_be *sctx = shash_desc_ctx(desc);
264269

265270
memcpy(sctx, in, sizeof(*sctx));
266271

@@ -274,8 +279,8 @@ struct shash_alg nx_shash_sha512_alg = {
274279
.final = nx_sha512_final,
275280
.export = nx_sha512_export,
276281
.import = nx_sha512_import,
277-
.descsize = sizeof(struct sha512_state),
278-
.statesize = sizeof(struct sha512_state),
282+
.descsize = sizeof(struct sha512_state_be),
283+
.statesize = sizeof(struct sha512_state_be),
279284
.base = {
280285
.cra_name = "sha512",
281286
.cra_driver_name = "sha512-nx",

drivers/crypto/nx/nx_csbcpb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ struct cop_status_block {
140140
u8 crb_seq_number;
141141
u8 completion_code;
142142
u8 completion_extension;
143-
u32 processed_byte_count;
144-
u64 address;
143+
__be32 processed_byte_count;
144+
__be64 address;
145145
} __packed;
146146

147147
/* Nest accelerator workbook section 4.4 */

0 commit comments

Comments
 (0)