LF-1723: spi: lpspi: run transfer speed_hz sanity check
authorClark Wang <xiaoning.wang@nxp.com>
Mon, 31 May 2021 02:34:49 +0000 (10:34 +0800)
committerJason Liu <jason.hui.liu@nxp.com>
Fri, 4 Jun 2021 03:45:35 +0000 (11:45 +0800)
Coverity reports Division or modulo by zero potential issue(CWE-369)
about the provided transfer speed_hz. Run sanity check first to avoid this
problem.

Signed-off-by: Han Xu <han.xu@nxp.com>
Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Reviewed-by: Jun Li <jun.li@nxp.com>
Acked-by: Jason Liu <jason.hui.liu@nxp.com>
drivers/spi/spi-fsl-lpspi.c

index 6c716e4..9216cc6 100644 (file)
@@ -302,6 +302,12 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi)
 
        perclk_rate = clk_get_rate(fsl_lpspi->clk_per);
 
+       if (!config.speed_hz) {
+               dev_err(fsl_lpspi->dev,
+                       "error: the transmission speed provided is 0!\n");
+               return -EINVAL;
+       }
+
        if (config.speed_hz > perclk_rate / 2) {
                dev_err(fsl_lpspi->dev,
                      "per-clk should be at least two times of transfer speed");