From: <Conor.Dooley@microchip.com>
To: <dan.carpenter@oracle.com>
Cc: <linux-spi@vger.kernel.org>
Subject: Re: [bug report] spi: add support for microchip fpga spi controllers
Date: Wed, 15 Jun 2022 08:58:53 +0000 [thread overview]
Message-ID: <f8829b05-12f0-58c0-80af-1e164f142324@microchip.com> (raw)
In-Reply-To: <20220615084042.GH2168@kadam>
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?
>
>>
>> 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
>
next prev parent reply other threads:[~2022-06-15 8:59 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 [this message]
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=f8829b05-12f0-58c0-80af-1e164f142324@microchip.com \
--to=conor.dooley@microchip.com \
--cc=dan.carpenter@oracle.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;
as well as URLs for NNTP newsgroup(s).