soundwire: intel: prevent possible dereference in hw_params
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Tue, 6 Aug 2019 00:55:06 +0000 (19:55 -0500)
committerVinod Koul <vkoul@kernel.org>
Wed, 21 Aug 2019 09:06:01 +0000 (14:36 +0530)
This should not happen in production systems but we should test for
all callback arguments before invoking the config_stream callback.

Update the prototype to clarify that the first argument is mandatory.

Also use local variable instead of multiple dereferences to improve
readability.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20190806005522.22642-2-pierre-louis.bossart@linux.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/soundwire/intel.c
include/linux/soundwire/sdw_intel.h

index c82ca4e..97e3205 100644 (file)
@@ -397,8 +397,10 @@ static int intel_config_stream(struct sdw_intel *sdw,
                               struct snd_soc_dai *dai,
                               struct snd_pcm_hw_params *hw_params, int link_id)
 {
-       if (sdw->res->ops && sdw->res->ops->config_stream)
-               return sdw->res->ops->config_stream(sdw->res->arg,
+       struct sdw_intel_link_res *res = sdw->res;
+
+       if (res->ops && res->ops->config_stream && res->arg)
+               return res->ops->config_stream(res->arg,
                                substream, dai, hw_params, link_id);
 
        return -EIO;
index 4d70da4..c9427cb 100644 (file)
@@ -8,6 +8,7 @@
  * struct sdw_intel_ops: Intel audio driver callback ops
  *
  * @config_stream: configure the stream with the hw_params
+ * the first argument containing the context is mandatory
  */
 struct sdw_intel_ops {
        int (*config_stream)(void *arg, void *substream,