Commit 56a766fd authored by Devyn Liu's avatar Devyn Liu Committed by Xinghai Cen
Browse files

spi: hisi-kunpeng: Add validation for the minimum value of speed_hz

mainline inclusion
from mainline-v6.11-rc1
commit c3c4f22b7c814a6ee485ce294065836f8ede30fa
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=c3c4f22b7c814a6ee485ce294065836f8ede30fa



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

The speed specified by the user is used to calculate the clk_div based
on the max_speed_hz in hisi_calc_effective_speed.  A very low speed
value can lead to a clk_div larger than the variable range. Avoid this
by setting the min_speed_hz so that such a small speed value is
rejected.  __spi_validate() in spi.c will return -EINVAL for the
specified speed_hz lower than min_speed_hz.

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-2-liudingyuan@huawei.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 5e2226fe
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -498,6 +498,7 @@ static int hisi_spi_probe(struct platform_device *pdev)
	host->transfer_one = hisi_spi_transfer_one;
	host->handle_err = hisi_spi_handle_err;
	host->dev.fwnode = dev->fwnode;
	host->min_speed_hz = DIV_ROUND_UP(host->max_speed_hz, CLK_DIV_MAX);

	hisi_spi_hw_init(hs);