Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: SOF: Intel: Check the bar size before remapping

The driver should use the pci_resource_len() to get the actual length of
pci bar, and compare it with the expect value. If the bar size is too
small (such as a broken device), the driver should return an error.

Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
Link: https://lore.kernel.org/r/20220409143950.2570186-1-zheyuma97@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Zheyu Ma and committed by
Mark Brown
5947b272 90b76a3c

+5 -1
+5 -1
sound/soc/sof/intel/pci-tng.c
··· 75 75 76 76 /* LPE base */ 77 77 base = pci_resource_start(pci, desc->resindex_lpe_base) - IRAM_OFFSET; 78 - size = PCI_BAR_SIZE; 78 + size = pci_resource_len(pci, desc->resindex_lpe_base); 79 + if (size < PCI_BAR_SIZE) { 80 + dev_err(sdev->dev, "error: I/O region is too small.\n"); 81 + return -ENODEV; 82 + } 79 83 80 84 dev_dbg(sdev->dev, "LPE PHY base at 0x%x size 0x%x", base, size); 81 85 sdev->bar[DSP_BAR] = devm_ioremap(sdev->dev, base, size);