Skip to content

Commit 0fab5ee

Browse files
gcabidduherbertx
authored andcommitted
crypto: qat - refactor ring-related debug functions
Refactor the functions `adf_ring_start()` and `adf_ring_next()` to improve readability. This does not introduce any functional change. Signed-off-by: Giovanni Cabiddu <[email protected]> Reviewed-by: Ahsan Atta <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 6908c5f commit 0fab5ee

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

drivers/crypto/intel/qat/qat_common/adf_transport_debug.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@
1010
static DEFINE_MUTEX(ring_read_lock);
1111
static DEFINE_MUTEX(bank_read_lock);
1212

13+
#define ADF_RING_NUM_MSGS(ring) \
14+
(ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size) / \
15+
ADF_MSG_SIZE_TO_BYTES(ring->msg_size))
16+
1317
static void *adf_ring_start(struct seq_file *sfile, loff_t *pos)
1418
{
1519
struct adf_etr_ring_data *ring = sfile->private;
20+
unsigned int num_msg = ADF_RING_NUM_MSGS(ring);
21+
loff_t val = *pos;
1622

1723
mutex_lock(&ring_read_lock);
18-
if (*pos == 0)
24+
if (val == 0)
1925
return SEQ_START_TOKEN;
2026

21-
if (*pos >= (ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size) /
22-
ADF_MSG_SIZE_TO_BYTES(ring->msg_size)))
27+
if (val >= num_msg)
2328
return NULL;
2429

2530
return ring->base_addr +
@@ -29,15 +34,15 @@ static void *adf_ring_start(struct seq_file *sfile, loff_t *pos)
2934
static void *adf_ring_next(struct seq_file *sfile, void *v, loff_t *pos)
3035
{
3136
struct adf_etr_ring_data *ring = sfile->private;
37+
unsigned int num_msg = ADF_RING_NUM_MSGS(ring);
38+
loff_t val = *pos;
39+
40+
(*pos)++;
3241

33-
if (*pos >= (ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size) /
34-
ADF_MSG_SIZE_TO_BYTES(ring->msg_size))) {
35-
(*pos)++;
42+
if (val >= num_msg)
3643
return NULL;
37-
}
3844

39-
return ring->base_addr +
40-
(ADF_MSG_SIZE_TO_BYTES(ring->msg_size) * (*pos)++);
45+
return ring->base_addr + (ADF_MSG_SIZE_TO_BYTES(ring->msg_size) * val);
4146
}
4247

4348
static int adf_ring_show(struct seq_file *sfile, void *v)

0 commit comments

Comments
 (0)