ASoC: SOF: sof-client-probes-ipc4: add checks to prevent static analysis warnings
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Mon, 31 Jul 2023 21:37:41 +0000 (16:37 -0500)
committerMark Brown <broonie@kernel.org>
Mon, 31 Jul 2023 22:22:12 +0000 (23:22 +0100)
make KCFLAGS='-fanalyzer' sound/soc/sof/ reports several NULL pointer
dereference paths.

sof_ipc4_probe_get_module_info() can return a NULL value, but it's
only tested in the init state. Static analyzers cannot know the probe
state machine and hence flags a potential issue for all calls of that
function.

Squelch these errors by adding the same check consistently.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Rander Wang <rander.wang@intel.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: Yaochun Hung <yc.hung@mediatek.com>
Link: https://lore.kernel.org/r/20230731213748.440285-2-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/sof-client-probes-ipc4.c

index ea21ef1..c56a858 100644 (file)
@@ -146,6 +146,9 @@ static int ipc4_probes_deinit(struct sof_client_dev *cdev)
        struct sof_man4_module *mentry = sof_ipc4_probe_get_module_info(cdev);
        struct sof_ipc4_msg msg;
 
+       if (!mentry)
+               return -ENODEV;
+
        msg.primary = mentry->id;
        msg.primary |= SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_MOD_DELETE_INSTANCE);
        msg.primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
@@ -197,6 +200,9 @@ static int ipc4_probes_points_add(struct sof_client_dev *cdev,
        struct sof_ipc4_msg msg;
        int i, ret;
 
+       if (!mentry)
+               return -ENODEV;
+
        /* The sof_probe_point_desc and sof_ipc4_probe_point structs
         * are of same size and even the integers are the same in the
         * same order, and similar meaning, but since there is no
@@ -247,6 +253,9 @@ static int ipc4_probes_points_remove(struct sof_client_dev *cdev,
        u32 *probe_point_ids;
        int i, ret;
 
+       if (!mentry)
+               return -ENODEV;
+
        probe_point_ids = kcalloc(num_buffer_id, sizeof(*probe_point_ids),
                                  GFP_KERNEL);
        if (!probe_point_ids)