]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
spi: hisi-kunpeng: Add verification for the max_frequency provided by the firmware
authorDevyn Liu <liudingyuan@huawei.com>
Tue, 30 Jul 2024 03:20:40 +0000 (11:20 +0800)
committerMark Brown <broonie@kernel.org>
Tue, 30 Jul 2024 12:27:38 +0000 (13:27 +0100)
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>
drivers/spi/spi-hisi-kunpeng.c

index 6910b4d4c427bfe6394224e79ea34fc112a3577b..16054695bdb04abf03a232f3ffb6ca12ff434eb7 100644 (file)
@@ -481,6 +481,9 @@ static int hisi_spi_probe(struct platform_device *pdev)
                return -EINVAL;
        }
 
+       if (host->max_speed_hz == 0)
+               return dev_err_probe(dev, -EINVAL, "spi-max-frequency can't be 0\n");
+
        ret = device_property_read_u16(dev, "num-cs",
                                        &host->num_chipselect);
        if (ret)