Skip to content

Commit 5127c42

Browse files
Devyn Liubroonie
authored andcommitted
spi: hisi-kunpeng: Add verification for the max_frequency provided by the firmware
If the value of max_speed_hz is 0, it may cause a division by zero error in hisi_calc_effective_speed(). The value of max_speed_hz is provided by firmware. Firmware is generally considered as a trusted domain. However, as division by zero errors can cause system failure, for defense measure, the value of max_speed is validated here. So 0 is regarded as invalid and an error code is returned. Signed-off-by: Devyn Liu <liudingyuan@huawei.com> Reviewed-by: Jay Fang <f.fangjian@huawei.com> Link: https://patch.msgid.link/20240730032040.3156393-3-liudingyuan@huawei.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent c3c4f22 commit 5127c42

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/spi/spi-hisi-kunpeng.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ static int hisi_spi_probe(struct platform_device *pdev)
481481
return -EINVAL;
482482
}
483483

484+
if (host->max_speed_hz == 0)
485+
return dev_err_probe(dev, -EINVAL, "spi-max-frequency can't be 0\n");
486+
484487
ret = device_property_read_u16(dev, "num-cs",
485488
&host->num_chipselect);
486489
if (ret)

0 commit comments

Comments
 (0)