From: <Conor.Dooley@microchip.com>
To: <yangyingliang@huawei.com>
Cc: <Daire.McNamara@microchip.com>, <broonie@kernel.org>,
<linux-spi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-riscv@lists.infradead.org>
Subject: Re: [PATCH -next 2/2] spi: microchip-core: switch to use devm_spi_alloc_master()
Date: Tue, 12 Jul 2022 14:03:33 +0000 [thread overview]
Message-ID: <87581e76-ceb7-9efa-d6dd-5ad4fe66111a@microchip.com> (raw)
In-Reply-To: <20220712135357.918997-2-yangyingliang@huawei.com>
On 12/07/2022 14:53, Yang Yingliang wrote:
> [Some people who received this message don't often get email from yangyingliang@huawei.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>
> Switch to use devm_spi_alloc_master() to simpify error path.
Hey Yang,
Thanks for trying to fix my mistakes!
Forgive my innocence here, but why is it okay to remove the
spi_master_put() in remove() but not the one in the error path of
the probe function?
If the devm_add_action_or_reset() in devm_spi_register_controller()
fails won't the same thing apply to the probe error path?
IOW, I think this patch needs a fixes tag too b/c it also fixes a
refcount underflow. Please correct me if I am misunderstanding.
One other comment below.
>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> drivers/spi/spi-microchip-core.c | 20 +++++++-------------
> 1 file changed, 7 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/spi/spi-microchip-core.c b/drivers/spi/spi-microchip-core.c
> index c26767343176..1a24e47f8305 100644
> --- a/drivers/spi/spi-microchip-core.c
> +++ b/drivers/spi/spi-microchip-core.c
> @@ -513,7 +513,7 @@ static int mchp_corespi_probe(struct platform_device *pdev)
> u32 num_cs;
> int ret = 0;
>
> - master = spi_alloc_master(&pdev->dev, sizeof(*spi));
> + master = devm_spi_alloc_master(&pdev->dev, sizeof(*spi));
> if (!master)
> return dev_err_probe(&pdev->dev, -ENOMEM,
> "unable to allocate master for SPI controller\n");
> @@ -535,36 +535,32 @@ static int mchp_corespi_probe(struct platform_device *pdev)
> spi = spi_master_get_devdata(master);
>
> spi->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
> - if (IS_ERR(spi->regs)) {
> - ret = PTR_ERR(spi->regs);
> - goto error_release_master;
> - }
> + if (IS_ERR(spi->regs))
> + return PTR_ERR(spi->regs);
>
> spi->irq = platform_get_irq(pdev, 0);
> if (spi->irq <= 0) {
> dev_err(&pdev->dev, "invalid IRQ %d for SPI controller\n", spi->irq);
> - ret = -ENXIO;
> - goto error_release_master;
> + return -ENXIO;
Also these can now become dev_err_probe for further simplification?
Thanks,
Conor.
> }
>
> ret = devm_request_irq(&pdev->dev, spi->irq, mchp_corespi_interrupt,
> IRQF_SHARED, dev_name(&pdev->dev), master);
> if (ret) {
> dev_err(&pdev->dev, "could not request irq: %d\n", ret);
> - goto error_release_master;
> + return ret;
> }
>
> spi->clk = devm_clk_get(&pdev->dev, NULL);
> if (IS_ERR(spi->clk)) {
> - ret = PTR_ERR(spi->clk);
> dev_err(&pdev->dev, "could not get clk: %d\n", ret);
> - goto error_release_master;
> + return PTR_ERR(spi->clk);
> }
>
> ret = clk_prepare_enable(spi->clk);
> if (ret) {
> dev_err(&pdev->dev, "failed to enable clock\n");
> - goto error_release_master;
> + return ret;
> }
>
> mchp_corespi_init(master, spi);
> @@ -583,8 +579,6 @@ static int mchp_corespi_probe(struct platform_device *pdev)
> error_release_hardware:
> mchp_corespi_disable(spi);
> clk_disable_unprepare(spi->clk);
> -error_release_master:
> - spi_master_put(master);
>
> return ret;
> }
> --
> 2.25.1
>
next prev parent reply other threads:[~2022-07-12 14:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-12 13:53 [PATCH -next 1/2] spi: microchip-core: fix UAF in mchp_corespi_remove() Yang Yingliang
2022-07-12 13:53 ` [PATCH -next 2/2] spi: microchip-core: switch to use devm_spi_alloc_master() Yang Yingliang
2022-07-12 14:03 ` Conor.Dooley [this message]
2022-07-12 20:50 ` Conor.Dooley
2022-07-13 2:14 ` Yang Yingliang
2022-07-12 20:52 ` [PATCH -next 1/2] spi: microchip-core: fix UAF in mchp_corespi_remove() Conor.Dooley
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=87581e76-ceb7-9efa-d6dd-5ad4fe66111a@microchip.com \
--to=conor.dooley@microchip.com \
--cc=Daire.McNamara@microchip.com \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=yangyingliang@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®