Skip to content

Commit 42c5675

Browse files
ebiggersherbertx
authored andcommitted
crypto: omap - switch from scatter_walk to plain offset
The omap driver was using struct scatter_walk, but only to maintain an offset, rather than iterating through the virtual addresses of the data contained in the scatterlist which is what scatter_walk is intended for. Make it just use a plain offset instead. This is simpler and avoids using struct scatter_walk in a way that is not well supported. Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent ee3c9c7 commit 42c5675

File tree

3 files changed

+32
-48
lines changed

3 files changed

+32
-48
lines changed

drivers/crypto/omap-aes.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <crypto/internal/aead.h>
1919
#include <crypto/internal/engine.h>
2020
#include <crypto/internal/skcipher.h>
21-
#include <crypto/scatterwalk.h>
2221
#include <linux/dma-mapping.h>
2322
#include <linux/dmaengine.h>
2423
#include <linux/err.h>
@@ -272,9 +271,9 @@ static int omap_aes_crypt_dma(struct omap_aes_dev *dd,
272271
int ret;
273272

274273
if (dd->pio_only) {
275-
scatterwalk_start(&dd->in_walk, dd->in_sg);
274+
dd->in_sg_offset = 0;
276275
if (out_sg_len)
277-
scatterwalk_start(&dd->out_walk, dd->out_sg);
276+
dd->out_sg_offset = 0;
278277

279278
/* Enable DATAIN interrupt and let it take
280279
care of the rest */
@@ -871,21 +870,18 @@ static irqreturn_t omap_aes_irq(int irq, void *dev_id)
871870

872871
BUG_ON(!dd->in_sg);
873872

874-
BUG_ON(_calc_walked(in) > dd->in_sg->length);
873+
BUG_ON(dd->in_sg_offset > dd->in_sg->length);
875874

876-
src = sg_virt(dd->in_sg) + _calc_walked(in);
875+
src = sg_virt(dd->in_sg) + dd->in_sg_offset;
877876

878877
for (i = 0; i < AES_BLOCK_WORDS; i++) {
879878
omap_aes_write(dd, AES_REG_DATA_N(dd, i), *src);
880-
881-
scatterwalk_advance(&dd->in_walk, 4);
882-
if (dd->in_sg->length == _calc_walked(in)) {
879+
dd->in_sg_offset += 4;
880+
if (dd->in_sg_offset == dd->in_sg->length) {
883881
dd->in_sg = sg_next(dd->in_sg);
884882
if (dd->in_sg) {
885-
scatterwalk_start(&dd->in_walk,
886-
dd->in_sg);
887-
src = sg_virt(dd->in_sg) +
888-
_calc_walked(in);
883+
dd->in_sg_offset = 0;
884+
src = sg_virt(dd->in_sg);
889885
}
890886
} else {
891887
src++;
@@ -904,20 +900,18 @@ static irqreturn_t omap_aes_irq(int irq, void *dev_id)
904900

905901
BUG_ON(!dd->out_sg);
906902

907-
BUG_ON(_calc_walked(out) > dd->out_sg->length);
903+
BUG_ON(dd->out_sg_offset > dd->out_sg->length);
908904

909-
dst = sg_virt(dd->out_sg) + _calc_walked(out);
905+
dst = sg_virt(dd->out_sg) + dd->out_sg_offset;
910906

911907
for (i = 0; i < AES_BLOCK_WORDS; i++) {
912908
*dst = omap_aes_read(dd, AES_REG_DATA_N(dd, i));
913-
scatterwalk_advance(&dd->out_walk, 4);
914-
if (dd->out_sg->length == _calc_walked(out)) {
909+
dd->out_sg_offset += 4;
910+
if (dd->out_sg_offset == dd->out_sg->length) {
915911
dd->out_sg = sg_next(dd->out_sg);
916912
if (dd->out_sg) {
917-
scatterwalk_start(&dd->out_walk,
918-
dd->out_sg);
919-
dst = sg_virt(dd->out_sg) +
920-
_calc_walked(out);
913+
dd->out_sg_offset = 0;
914+
dst = sg_virt(dd->out_sg);
921915
}
922916
} else {
923917
dst++;

drivers/crypto/omap-aes.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#define DST_MAXBURST 4
1515
#define DMA_MIN (DST_MAXBURST * sizeof(u32))
1616

17-
#define _calc_walked(inout) (dd->inout##_walk.offset - dd->inout##_sg->offset)
18-
1917
/*
2018
* OMAP TRM gives bitfields as start:end, where start is the higher bit
2119
* number. For example 7:0
@@ -186,8 +184,8 @@ struct omap_aes_dev {
186184
struct scatterlist out_sgl;
187185
struct scatterlist *orig_out;
188186

189-
struct scatter_walk in_walk;
190-
struct scatter_walk out_walk;
187+
unsigned int in_sg_offset;
188+
unsigned int out_sg_offset;
191189
struct dma_chan *dma_lch_in;
192190
struct dma_chan *dma_lch_out;
193191
int in_sg_len;

drivers/crypto/omap-des.c

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <crypto/engine.h>
2020
#include <crypto/internal/des.h>
2121
#include <crypto/internal/skcipher.h>
22-
#include <crypto/scatterwalk.h>
2322
#include <linux/dma-mapping.h>
2423
#include <linux/dmaengine.h>
2524
#include <linux/err.h>
@@ -40,8 +39,6 @@
4039

4140
#define DES_BLOCK_WORDS (DES_BLOCK_SIZE >> 2)
4241

43-
#define _calc_walked(inout) (dd->inout##_walk.offset - dd->inout##_sg->offset)
44-
4542
#define DES_REG_KEY(dd, x) ((dd)->pdata->key_ofs - \
4643
((x ^ 0x01) * 0x04))
4744

@@ -152,8 +149,8 @@ struct omap_des_dev {
152149
struct scatterlist out_sgl;
153150
struct scatterlist *orig_out;
154151

155-
struct scatter_walk in_walk;
156-
struct scatter_walk out_walk;
152+
unsigned int in_sg_offset;
153+
unsigned int out_sg_offset;
157154
struct dma_chan *dma_lch_in;
158155
struct dma_chan *dma_lch_out;
159156
int in_sg_len;
@@ -379,8 +376,8 @@ static int omap_des_crypt_dma(struct crypto_tfm *tfm,
379376
int ret;
380377

381378
if (dd->pio_only) {
382-
scatterwalk_start(&dd->in_walk, dd->in_sg);
383-
scatterwalk_start(&dd->out_walk, dd->out_sg);
379+
dd->in_sg_offset = 0;
380+
dd->out_sg_offset = 0;
384381

385382
/* Enable DATAIN interrupt and let it take
386383
care of the rest */
@@ -836,21 +833,18 @@ static irqreturn_t omap_des_irq(int irq, void *dev_id)
836833

837834
BUG_ON(!dd->in_sg);
838835

839-
BUG_ON(_calc_walked(in) > dd->in_sg->length);
836+
BUG_ON(dd->in_sg_offset > dd->in_sg->length);
840837

841-
src = sg_virt(dd->in_sg) + _calc_walked(in);
838+
src = sg_virt(dd->in_sg) + dd->in_sg_offset;
842839

843840
for (i = 0; i < DES_BLOCK_WORDS; i++) {
844841
omap_des_write(dd, DES_REG_DATA_N(dd, i), *src);
845-
846-
scatterwalk_advance(&dd->in_walk, 4);
847-
if (dd->in_sg->length == _calc_walked(in)) {
842+
dd->in_sg_offset += 4;
843+
if (dd->in_sg_offset == dd->in_sg->length) {
848844
dd->in_sg = sg_next(dd->in_sg);
849845
if (dd->in_sg) {
850-
scatterwalk_start(&dd->in_walk,
851-
dd->in_sg);
852-
src = sg_virt(dd->in_sg) +
853-
_calc_walked(in);
846+
dd->in_sg_offset = 0;
847+
src = sg_virt(dd->in_sg);
854848
}
855849
} else {
856850
src++;
@@ -869,20 +863,18 @@ static irqreturn_t omap_des_irq(int irq, void *dev_id)
869863

870864
BUG_ON(!dd->out_sg);
871865

872-
BUG_ON(_calc_walked(out) > dd->out_sg->length);
866+
BUG_ON(dd->out_sg_offset > dd->out_sg->length);
873867

874-
dst = sg_virt(dd->out_sg) + _calc_walked(out);
868+
dst = sg_virt(dd->out_sg) + dd->out_sg_offset;
875869

876870
for (i = 0; i < DES_BLOCK_WORDS; i++) {
877871
*dst = omap_des_read(dd, DES_REG_DATA_N(dd, i));
878-
scatterwalk_advance(&dd->out_walk, 4);
879-
if (dd->out_sg->length == _calc_walked(out)) {
872+
dd->out_sg_offset += 4;
873+
if (dd->out_sg_offset == dd->out_sg->length) {
880874
dd->out_sg = sg_next(dd->out_sg);
881875
if (dd->out_sg) {
882-
scatterwalk_start(&dd->out_walk,
883-
dd->out_sg);
884-
dst = sg_virt(dd->out_sg) +
885-
_calc_walked(out);
876+
dd->out_sg_offset = 0;
877+
dst = sg_virt(dd->out_sg);
886878
}
887879
} else {
888880
dst++;

0 commit comments

Comments
 (0)