linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] spi: xtensa-xtfpga: Switch to use devm_spi_alloc_master()
@ 2022-09-20 11:44 Yang Yingliang
  2022-09-21  3:53 ` Max Filippov
  2022-09-22 17:54 ` Mark Brown
  0 siblings, 2 replies; 5+ messages in thread
From: Yang Yingliang @ 2022-09-20 11:44 UTC (permalink / raw)
  To: linux-xtensa, linux-spi; +Cc: jcmvbkbc, broonie, yangyingliang

Switch to use devm_spi_alloc_master() to simpify error path.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/spi/spi-xtensa-xtfpga.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/spi/spi-xtensa-xtfpga.c b/drivers/spi/spi-xtensa-xtfpga.c
index fc2b5eb7d614..2fa7608f94cd 100644
--- a/drivers/spi/spi-xtensa-xtfpga.c
+++ b/drivers/spi/spi-xtensa-xtfpga.c
@@ -83,7 +83,7 @@ static int xtfpga_spi_probe(struct platform_device *pdev)
 	int ret;
 	struct spi_master *master;
 
-	master = spi_alloc_master(&pdev->dev, sizeof(struct xtfpga_spi));
+	master = devm_spi_alloc_master(&pdev->dev, sizeof(struct xtfpga_spi));
 	if (!master)
 		return -ENOMEM;
 
@@ -97,30 +97,24 @@ static int xtfpga_spi_probe(struct platform_device *pdev)
 	xspi->bitbang.chipselect = xtfpga_spi_chipselect;
 	xspi->bitbang.txrx_word[SPI_MODE_0] = xtfpga_spi_txrx_word;
 	xspi->regs = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(xspi->regs)) {
-		ret = PTR_ERR(xspi->regs);
-		goto err;
-	}
+	if (IS_ERR(xspi->regs))
+		return PTR_ERR(xspi->regs);
 
 	xtfpga_spi_write32(xspi, XTFPGA_SPI_START, 0);
 	usleep_range(1000, 2000);
 	if (xtfpga_spi_read32(xspi, XTFPGA_SPI_BUSY)) {
 		dev_err(&pdev->dev, "Device stuck in busy state\n");
-		ret = -EBUSY;
-		goto err;
+		return -EBUSY;
 	}
 
 	ret = spi_bitbang_start(&xspi->bitbang);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "spi_bitbang_start failed\n");
-		goto err;
+		return ret;
 	}
 
 	platform_set_drvdata(pdev, master);
 	return 0;
-err:
-	spi_master_put(master);
-	return ret;
 }
 
 static int xtfpga_spi_remove(struct platform_device *pdev)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH -next] spi: xtensa-xtfpga: Switch to use devm_spi_alloc_master()
  2022-09-20 11:44 [PATCH -next] spi: xtensa-xtfpga: Switch to use devm_spi_alloc_master() Yang Yingliang
@ 2022-09-21  3:53 ` Max Filippov
  2022-09-21  6:18   ` Yang Yingliang
  2022-09-22 17:54 ` Mark Brown
  1 sibling, 1 reply; 5+ messages in thread
From: Max Filippov @ 2022-09-21  3:53 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: linux-xtensa, linux-spi, broonie

On Tue, Sep 20, 2022 at 4:37 AM Yang Yingliang <yangyingliang@huawei.com> wrote:
>
> Switch to use devm_spi_alloc_master() to simpify error path.

Typo: simplify.

> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>  drivers/spi/spi-xtensa-xtfpga.c | 16 +++++-----------
>  1 file changed, 5 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/spi/spi-xtensa-xtfpga.c b/drivers/spi/spi-xtensa-xtfpga.c
> index fc2b5eb7d614..2fa7608f94cd 100644
> --- a/drivers/spi/spi-xtensa-xtfpga.c
> +++ b/drivers/spi/spi-xtensa-xtfpga.c
> @@ -83,7 +83,7 @@ static int xtfpga_spi_probe(struct platform_device *pdev)
>         int ret;
>         struct spi_master *master;
>
> -       master = spi_alloc_master(&pdev->dev, sizeof(struct xtfpga_spi));
> +       master = devm_spi_alloc_master(&pdev->dev, sizeof(struct xtfpga_spi));
>         if (!master)
>                 return -ENOMEM;
>
> @@ -97,30 +97,24 @@ static int xtfpga_spi_probe(struct platform_device *pdev)
>         xspi->bitbang.chipselect = xtfpga_spi_chipselect;
>         xspi->bitbang.txrx_word[SPI_MODE_0] = xtfpga_spi_txrx_word;
>         xspi->regs = devm_platform_ioremap_resource(pdev, 0);
> -       if (IS_ERR(xspi->regs)) {
> -               ret = PTR_ERR(xspi->regs);
> -               goto err;
> -       }
> +       if (IS_ERR(xspi->regs))
> +               return PTR_ERR(xspi->regs);
>
>         xtfpga_spi_write32(xspi, XTFPGA_SPI_START, 0);
>         usleep_range(1000, 2000);
>         if (xtfpga_spi_read32(xspi, XTFPGA_SPI_BUSY)) {
>                 dev_err(&pdev->dev, "Device stuck in busy state\n");
> -               ret = -EBUSY;
> -               goto err;
> +               return -EBUSY;
>         }
>
>         ret = spi_bitbang_start(&xspi->bitbang);
>         if (ret < 0) {
>                 dev_err(&pdev->dev, "spi_bitbang_start failed\n");
> -               goto err;
> +               return ret;
>         }
>
>         platform_set_drvdata(pdev, master);
>         return 0;
> -err:
> -       spi_master_put(master);
> -       return ret;
>  }
>
>  static int xtfpga_spi_remove(struct platform_device *pdev)

There's a call to spi_master_put in the xtfpga_spi_remove,
IIUC this call must be dropped too.

-- 
Thanks.
-- Max

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -next] spi: xtensa-xtfpga: Switch to use devm_spi_alloc_master()
  2022-09-21  3:53 ` Max Filippov
@ 2022-09-21  6:18   ` Yang Yingliang
  2022-09-22  2:26     ` Max Filippov
  0 siblings, 1 reply; 5+ messages in thread
From: Yang Yingliang @ 2022-09-21  6:18 UTC (permalink / raw)
  To: Max Filippov; +Cc: linux-xtensa, linux-spi, broonie

Hi,

On 2022/9/21 11:53, Max Filippov wrote:
> On Tue, Sep 20, 2022 at 4:37 AM Yang Yingliang <yangyingliang@huawei.com> wrote:
>> Switch to use devm_spi_alloc_master() to simpify error path.
> Typo: simplify.
OK, will fix it in v2.
>
>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>> ---
>>   drivers/spi/spi-xtensa-xtfpga.c | 16 +++++-----------
>>   1 file changed, 5 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/spi/spi-xtensa-xtfpga.c b/drivers/spi/spi-xtensa-xtfpga.c
>> index fc2b5eb7d614..2fa7608f94cd 100644
>> --- a/drivers/spi/spi-xtensa-xtfpga.c
>> +++ b/drivers/spi/spi-xtensa-xtfpga.c
>> @@ -83,7 +83,7 @@ static int xtfpga_spi_probe(struct platform_device *pdev)
>>          int ret;
>>          struct spi_master *master;
>>
>> -       master = spi_alloc_master(&pdev->dev, sizeof(struct xtfpga_spi));
>> +       master = devm_spi_alloc_master(&pdev->dev, sizeof(struct xtfpga_spi));
>>          if (!master)
>>                  return -ENOMEM;
>>
>> @@ -97,30 +97,24 @@ static int xtfpga_spi_probe(struct platform_device *pdev)
>>          xspi->bitbang.chipselect = xtfpga_spi_chipselect;
>>          xspi->bitbang.txrx_word[SPI_MODE_0] = xtfpga_spi_txrx_word;
>>          xspi->regs = devm_platform_ioremap_resource(pdev, 0);
>> -       if (IS_ERR(xspi->regs)) {
>> -               ret = PTR_ERR(xspi->regs);
>> -               goto err;
>> -       }
>> +       if (IS_ERR(xspi->regs))
>> +               return PTR_ERR(xspi->regs);
>>
>>          xtfpga_spi_write32(xspi, XTFPGA_SPI_START, 0);
>>          usleep_range(1000, 2000);
>>          if (xtfpga_spi_read32(xspi, XTFPGA_SPI_BUSY)) {
>>                  dev_err(&pdev->dev, "Device stuck in busy state\n");
>> -               ret = -EBUSY;
>> -               goto err;
>> +               return -EBUSY;
>>          }
>>
>>          ret = spi_bitbang_start(&xspi->bitbang);
>>          if (ret < 0) {
>>                  dev_err(&pdev->dev, "spi_bitbang_start failed\n");
>> -               goto err;
>> +               return ret;
>>          }
>>
>>          platform_set_drvdata(pdev, master);
>>          return 0;
>> -err:
>> -       spi_master_put(master);
>> -       return ret;
>>   }
>>
>>   static int xtfpga_spi_remove(struct platform_device *pdev)
> There's a call to spi_master_put in the xtfpga_spi_remove,
> IIUC this call must be dropped too.
It can not be dropped, the controller is get in spi_bitbang_start(), it 
need be put in remove().

Thanks,
Yang
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -next] spi: xtensa-xtfpga: Switch to use devm_spi_alloc_master()
  2022-09-21  6:18   ` Yang Yingliang
@ 2022-09-22  2:26     ` Max Filippov
  0 siblings, 0 replies; 5+ messages in thread
From: Max Filippov @ 2022-09-22  2:26 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: linux-xtensa, linux-spi, broonie

On Tue, Sep 20, 2022 at 11:18 PM Yang Yingliang
<yangyingliang@huawei.com> wrote:
> On 2022/9/21 11:53, Max Filippov wrote:
> > On Tue, Sep 20, 2022 at 4:37 AM Yang Yingliang <yangyingliang@huawei.com> wrote:
> >>   static int xtfpga_spi_remove(struct platform_device *pdev)
> > There's a call to spi_master_put in the xtfpga_spi_remove,
> > IIUC this call must be dropped too.
> It can not be dropped, the controller is get in spi_bitbang_start(), it
> need be put in remove().

Oh, I see, spi_bitbang_stop doesn't do it for controllers allocated with devres.

Tested-by: Max Filippov <jcmvbkbc@gmail.com>
Acked-by: Max Filippov <jcmvbkbc@gmail.com>

-- 
Thanks.
-- Max

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -next] spi: xtensa-xtfpga: Switch to use devm_spi_alloc_master()
  2022-09-20 11:44 [PATCH -next] spi: xtensa-xtfpga: Switch to use devm_spi_alloc_master() Yang Yingliang
  2022-09-21  3:53 ` Max Filippov
@ 2022-09-22 17:54 ` Mark Brown
  1 sibling, 0 replies; 5+ messages in thread
From: Mark Brown @ 2022-09-22 17:54 UTC (permalink / raw)
  To: Yang Yingliang, linux-xtensa, linux-spi; +Cc: jcmvbkbc

On Tue, 20 Sep 2022 19:44:48 +0800, Yang Yingliang wrote:
> Switch to use devm_spi_alloc_master() to simpify error path.
> 
> 

Applied to

   broonie/spi.git for-next

Thanks!

[1/1] spi: xtensa-xtfpga: Switch to use devm_spi_alloc_master()
      commit: 478cc2fc3dd782f7935bc0ab84c198691ea83fa3

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-22 17:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-20 11:44 [PATCH -next] spi: xtensa-xtfpga: Switch to use devm_spi_alloc_master() Yang Yingliang
2022-09-21  3:53 ` Max Filippov
2022-09-21  6:18   ` Yang Yingliang
2022-09-22  2:26     ` Max Filippov
2022-09-22 17:54 ` Mark Brown

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).