diff options
| author | Andrew Goodbody <[email protected]> | 2025-08-04 17:56:57 +0100 |
|---|---|---|
| committer | Peng Fan <[email protected]> | 2025-08-27 15:42:08 +0800 |
| commit | 9ca756cee7e8f9d6ecc0a69fa785caabd61f3f6a (patch) | |
| tree | c5e95b36f91a7176c71c6c8132969292de32549b | |
| parent | 756580d090e5dcb3c45d1f0147cc596ae4efd961 (diff) | |
net: fsl-mc: NULL check dflt_dpbp before dereference
In dpbp_exit there is a NULL check for dflt_dpbp after it is
dereferenced a number of times. Instead move the NULL check to early in
the function. Also assign NULL to dflt_dpbp after free in both dpbp_init
and dpbp_exit.
This issue was found by Smatch.
Signed-off-by: Andrew Goodbody <[email protected]>
Signed-off-by: Peng Fan <[email protected]>
| -rw-r--r-- | drivers/net/fsl-mc/mc.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/net/fsl-mc/mc.c b/drivers/net/fsl-mc/mc.c index 999a9912e2f..8c882c7fcf5 100644 --- a/drivers/net/fsl-mc/mc.c +++ b/drivers/net/fsl-mc/mc.c @@ -1438,6 +1438,7 @@ err_close: err_open: err_create: free(dflt_dpbp); + dflt_dpbp = NULL; err_calloc: return err; } @@ -1446,6 +1447,9 @@ static int dpbp_exit(void) { int err; + if (!dflt_dpbp) + return -ENODEV; + err = dpbp_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_id); if (err < 0) { @@ -1457,8 +1461,8 @@ static int dpbp_exit(void) printf("Exit: DPBP.%d\n", dflt_dpbp->dpbp_attr.id); #endif - if (dflt_dpbp) - free(dflt_dpbp); + free(dflt_dpbp); + dflt_dpbp = NULL; return 0; err: |
