diff mbox series

[v2,21/37] baseband/acc100: check for unlikely operation vals

Message ID 20220820023157.189047-22-hernan.vargas@intel.com (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers show
Series baseband/acc100: changes for 22.11 | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Hernan Vargas Aug. 20, 2022, 2:31 a.m. UTC
Add unlikely checks for NULL operation values.

Signed-off-by: Hernan Vargas <hernan.vargas@intel.com>
---
 drivers/baseband/acc100/rte_acc100_pmd.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Maxime Coquelin Sept. 15, 2022, 10:02 a.m. UTC | #1
On 8/20/22 04:31, Hernan Vargas wrote:
> Add unlikely checks for NULL operation values.

Same as for patch 20, this is a fix.

> Signed-off-by: Hernan Vargas <hernan.vargas@intel.com>
> ---
>   drivers/baseband/acc100/rte_acc100_pmd.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/baseband/acc100/rte_acc100_pmd.c b/drivers/baseband/acc100/rte_acc100_pmd.c
> index 70a29f92a1..ea850e2d7f 100644
> --- a/drivers/baseband/acc100/rte_acc100_pmd.c
> +++ b/drivers/baseband/acc100/rte_acc100_pmd.c
> @@ -3148,6 +3148,10 @@ enqueue_enc_one_op_tb(struct acc100_queue *q, struct rte_bbdev_enc_op *op,
>   	r = op->turbo_enc.tb_params.r;
>   
>   	while (mbuf_total_left > 0 && r < c) {
> +		if (unlikely(input == 0)) {
> +			rte_bbdev_log(ERR, "Not enough input segment");
> +			return -EINVAL;
> +		}
>   		seg_total_left = rte_pktmbuf_data_len(input) - in_offset;
>   		/* Set up DMA descriptor */
>   		desc = q->ring_addr + ((q->sw_ring_head + total_enqueued_cbs)
> @@ -4491,6 +4495,8 @@ acc100_enqueue_ldpc_dec_tb(struct rte_bbdev_queue_data *q_data,
>   		}
>   		enqueued_cbs += ret;
>   	}
> +	if (unlikely(enqueued_cbs == 0))
> +		return 0; /* Nothing to enqueue */
>   
>   	acc100_dma_enqueue(q, enqueued_cbs, &q_data->queue_stats);
>   
> @@ -5051,6 +5057,8 @@ acc100_dequeue_dec(struct rte_bbdev_queue_data *q_data,
>   	for (i = 0; i < dequeue_num; ++i) {
>   		op = (q->ring_addr + ((q->sw_ring_tail + dequeued_cbs)
>   			& q->sw_ring_wrap_mask))->req.op_addr;
> +		if (unlikely(op == NULL))
> +			break;
>   		if (op->turbo_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
>   			ret = dequeue_dec_one_op_tb(q, &ops[i], dequeued_cbs,
>   					&aq_dequeued);
> @@ -5096,6 +5104,8 @@ acc100_dequeue_ldpc_dec(struct rte_bbdev_queue_data *q_data,
>   	for (i = 0; i < dequeue_num; ++i) {
>   		op = (q->ring_addr + ((q->sw_ring_tail + dequeued_cbs)
>   			& q->sw_ring_wrap_mask))->req.op_addr;
> +		if (unlikely(op == NULL))
> +			break;
>   		if (op->ldpc_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
>   			ret = dequeue_dec_one_op_tb(q, &ops[i], dequeued_cbs,
>   					&aq_dequeued);

With commit message ammended:
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
diff mbox series

Patch

diff --git a/drivers/baseband/acc100/rte_acc100_pmd.c b/drivers/baseband/acc100/rte_acc100_pmd.c
index 70a29f92a1..ea850e2d7f 100644
--- a/drivers/baseband/acc100/rte_acc100_pmd.c
+++ b/drivers/baseband/acc100/rte_acc100_pmd.c
@@ -3148,6 +3148,10 @@  enqueue_enc_one_op_tb(struct acc100_queue *q, struct rte_bbdev_enc_op *op,
 	r = op->turbo_enc.tb_params.r;
 
 	while (mbuf_total_left > 0 && r < c) {
+		if (unlikely(input == 0)) {
+			rte_bbdev_log(ERR, "Not enough input segment");
+			return -EINVAL;
+		}
 		seg_total_left = rte_pktmbuf_data_len(input) - in_offset;
 		/* Set up DMA descriptor */
 		desc = q->ring_addr + ((q->sw_ring_head + total_enqueued_cbs)
@@ -4491,6 +4495,8 @@  acc100_enqueue_ldpc_dec_tb(struct rte_bbdev_queue_data *q_data,
 		}
 		enqueued_cbs += ret;
 	}
+	if (unlikely(enqueued_cbs == 0))
+		return 0; /* Nothing to enqueue */
 
 	acc100_dma_enqueue(q, enqueued_cbs, &q_data->queue_stats);
 
@@ -5051,6 +5057,8 @@  acc100_dequeue_dec(struct rte_bbdev_queue_data *q_data,
 	for (i = 0; i < dequeue_num; ++i) {
 		op = (q->ring_addr + ((q->sw_ring_tail + dequeued_cbs)
 			& q->sw_ring_wrap_mask))->req.op_addr;
+		if (unlikely(op == NULL))
+			break;
 		if (op->turbo_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
 			ret = dequeue_dec_one_op_tb(q, &ops[i], dequeued_cbs,
 					&aq_dequeued);
@@ -5096,6 +5104,8 @@  acc100_dequeue_ldpc_dec(struct rte_bbdev_queue_data *q_data,
 	for (i = 0; i < dequeue_num; ++i) {
 		op = (q->ring_addr + ((q->sw_ring_tail + dequeued_cbs)
 			& q->sw_ring_wrap_mask))->req.op_addr;
+		if (unlikely(op == NULL))
+			break;
 		if (op->ldpc_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
 			ret = dequeue_dec_one_op_tb(q, &ops[i], dequeued_cbs,
 					&aq_dequeued);