net: fsl-mc: NULL check dflt_dpni before dereference

In dpni_exit there is a NULL check for dflt_dpni after it is
dereferenced a number of times. Instead move the NULL check to early in
the function. Also assign NULL to dflt_dpni after free in both dpni_init
and dpni_exit.

This issue was found by Smatch.

Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
This commit is contained in:
Andrew Goodbody 2025-08-04 17:56:58 +01:00 committed by Peng Fan
parent 9ca756cee7
commit 010a4c5c55

View File

@ -1539,6 +1539,7 @@ err_get_version:
dflt_dpni->dpni_id); dflt_dpni->dpni_id);
err_create: err_create:
free(dflt_dpni); free(dflt_dpni);
dflt_dpni = NULL;
err_calloc: err_calloc:
return err; return err;
} }
@ -1547,6 +1548,9 @@ static int dpni_exit(void)
{ {
int err; int err;
if (!dflt_dpni)
return -ENODEV;
err = dpni_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS, err = dpni_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
dflt_dpni->dpni_id); dflt_dpni->dpni_id);
if (err < 0) { if (err < 0) {
@ -1558,8 +1562,8 @@ static int dpni_exit(void)
printf("Exit: DPNI.%d\n", dflt_dpni->dpni_id); printf("Exit: DPNI.%d\n", dflt_dpni->dpni_id);
#endif #endif
if (dflt_dpni)
free(dflt_dpni); free(dflt_dpni);
dflt_dpni = NULL;
return 0; return 0;
err: err: