]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
net: fsl-mc: NULL check dflt_dpio before dereference
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Mon, 4 Aug 2025 16:56:56 +0000 (17:56 +0100)
committerPeng Fan <peng.fan@nxp.com>
Wed, 27 Aug 2025 07:42:08 +0000 (15:42 +0800)
In dpio_exit there is a NULL check for dflt_dpio but it happens after
dpio_dflt has been dereferenced a number of times already. Instead move
the NULL check to first thing in the function. Also assign NULL to
dflt_dpio after free in both dpio_init and dpio_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>
drivers/net/fsl-mc/mc.c

index 86daf0fb2bb8bc7045443d778d2b4f8735b4e762..999a9912e2f7488eefc13580bec4fa04b635cff6 100644 (file)
@@ -1178,6 +1178,7 @@ err_get_api_ver:
                     dflt_dpio->dpio_id);
 err_create:
        free(dflt_dpio);
+       dflt_dpio = NULL;
 err_calloc:
        return err;
 }
@@ -1186,6 +1187,9 @@ static int dpio_exit(void)
 {
        int err;
 
+       if (!dflt_dpio)
+               return -ENODEV;
+
        err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
        if (err < 0) {
                printf("dpio_disable() failed: %d\n", err);
@@ -1211,8 +1215,8 @@ static int dpio_exit(void)
        printf("Exit: DPIO.%d\n", dflt_dpio->dpio_id);
 #endif
 
-       if (dflt_dpio)
-               free(dflt_dpio);
+       free(dflt_dpio);
+       dflt_dpio = NULL;
 
        return 0;
 err: