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>
dflt_dpio->dpio_id);
err_create:
free(dflt_dpio);
+ dflt_dpio = NULL;
err_calloc:
return err;
}
{
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);
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: