* [PATCH 1/2] spi: hisi-kunpeng: Add validation for the minimum value of speed_hz
2024-07-30 3:20 [PATCH 0/2] spi: hisi-kunpeng: Set verification for speed_hz and max_frequency Devyn Liu
@ 2024-07-30 3:20 ` Devyn Liu
2024-07-30 3:20 ` [PATCH 2/2] spi: hisi-kunpeng: Add verification for the max_frequency provided by the firmware Devyn Liu
2024-07-30 16:03 ` [PATCH 0/2] spi: hisi-kunpeng: Set verification for speed_hz and max_frequency Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Devyn Liu @ 2024-07-30 3:20 UTC (permalink / raw)
To: f.fangjian, broonie
Cc: linux-spi, linux-kernel, jonathan.cameron, salil.mehta,
shameerali.kolothum.thodi, shiju.jose, liuyonglong, yangyicong,
yisen.zhuang, kong.kongxinwei, liudingyuan
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: Devyn Liu <liudingyuan@huawei.com>
Reviewed-by: Jay Fang <f.fangjian@huawei.com>
---
drivers/spi/spi-hisi-kunpeng.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/spi/spi-hisi-kunpeng.c b/drivers/spi/spi-hisi-kunpeng.c
index 77e9738e42f6..6910b4d4c427 100644
--- a/drivers/spi/spi-hisi-kunpeng.c
+++ b/drivers/spi/spi-hisi-kunpeng.c
@@ -495,6 +495,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);
--
2.33.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] spi: hisi-kunpeng: Add verification for the max_frequency provided by the firmware
2024-07-30 3:20 [PATCH 0/2] spi: hisi-kunpeng: Set verification for speed_hz and max_frequency Devyn Liu
2024-07-30 3:20 ` [PATCH 1/2] spi: hisi-kunpeng: Add validation for the minimum value of speed_hz Devyn Liu
@ 2024-07-30 3:20 ` Devyn Liu
2024-07-30 16:03 ` [PATCH 0/2] spi: hisi-kunpeng: Set verification for speed_hz and max_frequency Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Devyn Liu @ 2024-07-30 3:20 UTC (permalink / raw)
To: f.fangjian, broonie
Cc: linux-spi, linux-kernel, jonathan.cameron, salil.mehta,
shameerali.kolothum.thodi, shiju.jose, liuyonglong, yangyicong,
yisen.zhuang, kong.kongxinwei, liudingyuan
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>
---
drivers/spi/spi-hisi-kunpeng.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/spi/spi-hisi-kunpeng.c b/drivers/spi/spi-hisi-kunpeng.c
index 6910b4d4c427..16054695bdb0 100644
--- a/drivers/spi/spi-hisi-kunpeng.c
+++ b/drivers/spi/spi-hisi-kunpeng.c
@@ -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)
--
2.33.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] spi: hisi-kunpeng: Set verification for speed_hz and max_frequency
2024-07-30 3:20 [PATCH 0/2] spi: hisi-kunpeng: Set verification for speed_hz and max_frequency Devyn Liu
2024-07-30 3:20 ` [PATCH 1/2] spi: hisi-kunpeng: Add validation for the minimum value of speed_hz Devyn Liu
2024-07-30 3:20 ` [PATCH 2/2] spi: hisi-kunpeng: Add verification for the max_frequency provided by the firmware Devyn Liu
@ 2024-07-30 16:03 ` Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2024-07-30 16:03 UTC (permalink / raw)
To: f.fangjian, Devyn Liu
Cc: linux-spi, linux-kernel, jonathan.cameron, salil.mehta,
shameerali.kolothum.thodi, shiju.jose, liuyonglong, yangyicong,
yisen.zhuang, kong.kongxinwei
On Tue, 30 Jul 2024 11:20:38 +0800, Devyn Liu wrote:
> The speed_hz is specified by user, while the max_frequency is a
> firmware-provided parameter for the SPI controller. Both are used
> in the calculation of clk_div. To avoid calculation results outside
> of a reasonable range and to prevent division by zero errors,
> configuration for validation of speed_hz and max_frequency is added
> in the code.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/2] spi: hisi-kunpeng: Add validation for the minimum value of speed_hz
commit: c3c4f22b7c814a6ee485ce294065836f8ede30fa
[2/2] spi: hisi-kunpeng: Add verification for the max_frequency provided by the firmware
commit: 5127c42c77de18651aa9e8e0a3ced190103b449c
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 4+ messages in thread