Commit 8f2ad3d7 authored by Devyn Liu's avatar Devyn Liu Committed by Xinghai Cen
Browse files

spi: hisi-kunpeng: Add verification for the max_frequency provided by the firmware

mainline inclusion
from mainline-v6.11-rc1
commit 5127c42c77de18651aa9e8e0a3ced190103b449c
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAMWY8
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git/commit/drivers/spi/spi-hisi-kunpeng.c?id=5127c42c77de18651aa9e8e0a3ced190103b449c



-------------------------------------------------

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: default avatarlujunhua <lujunhua7@h-partners.com>
Signed-off-by: default avatarDevyn Liu <liudingyuan@huawei.com>
Reviewed-by: default avatarJay Fang <f.fangjian@huawei.com>
Link: https://patch.msgid.link/20240730032040.3156393-3-liudingyuan@huawei.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 456a1a69
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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)