soundwire: cadence_master: check the number of bidir PDIs
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Wed, 22 May 2019 19:47:28 +0000 (14:47 -0500)
committerVinod Koul <vkoul@kernel.org>
Mon, 27 May 2019 05:23:00 +0000 (10:53 +0530)
There is an assumption that the first two PDIs are reserved for Bulk,
so we need to make sure the number of bidir PDIs is indeed larger than
two. If the configuration provided is incorrect, this could lead to
allocating a huge amount of memory.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/soundwire/cadence_master.c

index d76dd24..ff4badc 100644 (file)
@@ -718,6 +718,8 @@ int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
        stream = &cdns->pcm;
 
        /* First two PDIs are reserved for bulk transfers */
+       if (stream->num_bd < CDNS_PCM_PDI_OFFSET)
+               return -EINVAL;
        stream->num_bd -= CDNS_PCM_PDI_OFFSET;
        offset = CDNS_PCM_PDI_OFFSET;