examples/eventdev: Check for the NULL pointer after calling rte_zmalloc

Message ID tencent_E049786768575AD04105555B3D3730A17B0A@qq.com (mailing list archive)
State Changes Requested, archived
Delegated to: Jerin Jacob
Headers
Series examples/eventdev: Check for the NULL pointer after calling rte_zmalloc |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues
ci/github-robot: build fail github build: failed
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing fail Testing issues
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-abi-testing warning Testing issues

Commit Message

biggest dreamer July 6, 2022, 7:23 a.m. UTC
  From: Shiqi Liu <835703180@qq.com>

As the possible failure of the rte_zmalloc(), the not_checked and
checked could be NULL pointer.
Therefore, it should be better to check it in order to avoid
the dereference of the NULL pointer.

Fixes: fa8054c8c88 ("examples/eventdev: add thread safe Tx worker pipeline")
Signed-off-by: Shiqi Liu <835703180@qq.com>
---
 examples/eventdev_pipeline/pipeline_worker_tx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Jerin Jacob Sept. 13, 2022, 12:17 p.m. UTC | #1
On Wed, Jul 6, 2022 at 12:54 PM <835703180@qq.com> wrote:
>
> From: Shiqi Liu <835703180@qq.com>
>
> As the possible failure of the rte_zmalloc(), the not_checked and
> checked could be NULL pointer.
> Therefore, it should be better to check it in order to avoid
> the dereference of the NULL pointer.
>
> Fixes: fa8054c8c88 ("examples/eventdev: add thread safe Tx worker pipeline")
> Signed-off-by: Shiqi Liu <835703180@qq.com>
> ---
>  examples/eventdev_pipeline/pipeline_worker_tx.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/examples/eventdev_pipeline/pipeline_worker_tx.c b/examples/eventdev_pipeline/pipeline_worker_tx.c
> index a82e064c1c..6ea676c516 100644
> --- a/examples/eventdev_pipeline/pipeline_worker_tx.c
> +++ b/examples/eventdev_pipeline/pipeline_worker_tx.c
> @@ -764,7 +764,9 @@ init_adapters(uint16_t nb_ports)
>
>         ret = rte_event_dev_info_get(evdev_id, &dev_info);
>         adptr_services = rte_zmalloc(NULL, sizeof(struct rx_adptr_services), 0);
> -
> +       if (adptr_services == NULL) {
> +               return -ENOMEM;
> +       }

it does not look like you have tried to compile this patch. It is a
void return function.

CI: http://mails.dpdk.org/archives/test-report/2022-July/294780.html

Also, Please update the subject. Some suggestion to consider.
examples/eventdev: validate memory allocation




>         struct rte_event_port_conf adptr_p_conf = {
>                 .dequeue_depth = cdata.worker_cq_depth,
>                 .enqueue_depth = 64,
> --
> 2.35.1.windows.2
>
  

Patch

diff --git a/examples/eventdev_pipeline/pipeline_worker_tx.c b/examples/eventdev_pipeline/pipeline_worker_tx.c
index a82e064c1c..6ea676c516 100644
--- a/examples/eventdev_pipeline/pipeline_worker_tx.c
+++ b/examples/eventdev_pipeline/pipeline_worker_tx.c
@@ -764,7 +764,9 @@  init_adapters(uint16_t nb_ports)
 
 	ret = rte_event_dev_info_get(evdev_id, &dev_info);
 	adptr_services = rte_zmalloc(NULL, sizeof(struct rx_adptr_services), 0);
-
+	if (adptr_services == NULL) {
+		return -ENOMEM;
+	}
 	struct rte_event_port_conf adptr_p_conf = {
 		.dequeue_depth = cdata.worker_cq_depth,
 		.enqueue_depth = 64,