Linux SPI subsystem development
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Conor.Dooley@microchip.com
Cc: linux-spi@vger.kernel.org
Subject: Re: [bug report] spi: add support for microchip fpga spi controllers
Date: Wed, 15 Jun 2022 11:40:42 +0300	[thread overview]
Message-ID: <20220615084042.GH2168@kadam> (raw)
In-Reply-To: <70502137-6c04-4206-382d-2731a2205875@microchip.com>

On Wed, Jun 15, 2022 at 08:33:35AM +0000, Conor.Dooley@microchip.com wrote:
> >      541         spi->irq = platform_get_irq(pdev, 0);
> >      542         if (spi->irq <= 0) {
> >      543                 dev_err(&pdev->dev, "invalid IRQ %d for SPI controller\n", spi->irq);
> >      544                 ret = spi->irq;
> >      545                 goto error_release_master;
> >      546         }
> >      547
> >      548         ret = devm_request_irq(&pdev->dev, spi->irq, mchp_corespi_interrupt,
> >      549                                IRQF_SHARED, dev_name(&pdev->dev), master);
> >      550         if (ret) {
> >      551                 dev_err(&pdev->dev, "could not request irq: %d\n", ret);
> >      552                 goto error_release_master;
> >      553         }
> >      554
> >      555         spi->clk = devm_clk_get(&pdev->dev, NULL);
> >      556         if (!spi->clk || IS_ERR(spi->clk)) {
> >                       ^^^^^^^^
> > NULL
> > 
> > --> 557                 ret = PTR_ERR(spi->clk);
> > 
> > ret is 0/success.
> > 
> > Normally when functions like this return NULL, you're supposed to just
> > accept the NULL and add tests for it to avoid NULL related bugs.  In
> > this driver if spi->clk is NULL then it leads to spi_hz == 0 which leads
> > to a divide by zero bug.  So it's not clear which way to go on this?
> > Fix the error code or add more checks for NULL?
> 
> Am I being dumb here, or should the null check just be removed like
> every other driver? As in, devm_clk_get will only return a valid
> clk or an IS_ERR() condition.

It can return NULL if CONFIG_HAVE_CLK is disabled.  I don't know the
hardware or if that CONFIG_ is essential for booting.

> 
> The correct solution seems to me to be remove the !spi->clk check?

That's the normal solution, yes.  But if you do that, then please add a
check to prevent the divide by zero:
`grep -w clk drivers/spi/spi-microchip-core.c`

regards,
dan carpenter


  reply	other threads:[~2022-06-15  8:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-15  8:09 [bug report] spi: add support for microchip fpga spi controllers Dan Carpenter
2022-06-15  8:33 ` Conor.Dooley
2022-06-15  8:40   ` Dan Carpenter [this message]
2022-06-15  8:58     ` Conor.Dooley
2022-06-15  9:16       ` Dan Carpenter

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=20220615084042.GH2168@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=Conor.Dooley@microchip.com \
    --cc=linux-spi@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox