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 12:16:33 +0300 [thread overview]
Message-ID: <20220615091633.GI2168@kadam> (raw)
In-Reply-To: <f8829b05-12f0-58c0-80af-1e164f142324@microchip.com>
On Wed, Jun 15, 2022 at 08:58:53AM +0000, Conor.Dooley@microchip.com wrote:
> On 15/06/2022 09:40, Dan Carpenter wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> >
> > 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.
>
> Ehh I guess it is /possible/ that CONFIG_HAVE_CLK could be off
> if someone is accessing the FPGA from another device.
> In that case, neither option really particularly appeals to me.
> Just return -ENODEV I guess?
>
To be honest, I always prefer just accepting the NULL check and adding
the checks but also philosophical debates are kind of a waste of time.
Do whatever is easiest. :)
regards,
dan carpenter
prev parent reply other threads:[~2022-06-15 9:17 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
2022-06-15 8:58 ` Conor.Dooley
2022-06-15 9:16 ` Dan Carpenter [this message]
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=20220615091633.GI2168@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