All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: xiaoning.wang@nxp.com
Cc: linux-spi@vger.kernel.org
Subject: [bug report] spi: imx: add a check for speed_hz before calculating the clock
Date: Thu, 25 Nov 2021 11:21:06 +0300	[thread overview]
Message-ID: <20211125082105.GA5023@kili> (raw)

Hello Clark Wang,

The patch 4df2f5e1372e: "spi: imx: add a check for speed_hz before
calculating the clock" from Apr 8, 2021, leads to the following
Smatch static checker warning:

	drivers/spi/spi-imx.c:628 mx51_ecspi_prepare_transfer()
	error: uninitialized symbol 'clk'.

drivers/spi/spi-imx.c
    609 static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
    610                                        struct spi_device *spi)
    611 {
    612         u32 ctrl = readl(spi_imx->base + MX51_ECSPI_CTRL);
    613         u32 clk;
                ^^^^^^^^
This use to be "clk = t->speed_hz"

    614 
    615         /* Clear BL field and set the right value */
    616         ctrl &= ~MX51_ECSPI_CTRL_BL_MASK;
    617         if (spi_imx->slave_mode && is_imx53_ecspi(spi_imx))
    618                 ctrl |= (spi_imx->slave_burst * 8 - 1)
    619                         << MX51_ECSPI_CTRL_BL_OFFSET;
    620         else
    621                 ctrl |= (spi_imx->bits_per_word - 1)
    622                         << MX51_ECSPI_CTRL_BL_OFFSET;
    623 
    624         /* set clock speed */
    625         ctrl &= ~(0xf << MX51_ECSPI_CTRL_POSTDIV_OFFSET |
    626                   0xf << MX51_ECSPI_CTRL_PREDIV_OFFSET);
    627         ctrl |= mx51_ecspi_clkdiv(spi_imx, spi_imx->spi_bus_clk, &clk);
                                                                         ^^^^
And then fixed here on the success path

--> 628         spi_imx->spi_bus_clk = clk;

Now if mx51_ecspi_clkdiv() fails it's uninitialized

    629 
    630         /*
    631          * ERR009165: work in XHC mode instead of SMC as PIO on the chips
    632          * before i.mx6ul.
    633          */
    634         if (spi_imx->usedma && spi_imx->devtype_data->tx_glitch_fixed)
    635                 ctrl |= MX51_ECSPI_CTRL_SMC;
    636         else
    637                 ctrl &= ~MX51_ECSPI_CTRL_SMC;
    638 
    639         writel(ctrl, spi_imx->base + MX51_ECSPI_CTRL);
    640 
    641         return 0;
    642 }

regards,
dan carpenter

                 reply	other threads:[~2021-11-25  8:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211125082105.GA5023@kili \
    --to=dan.carpenter@oracle.com \
    --cc=linux-spi@vger.kernel.org \
    --cc=xiaoning.wang@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.