mbox series

[-next,0/6] spi: Switch to use devm_spi_alloc_master() in some drivers

Message ID 20220920134819.2981033-1-yangyingliang@huawei.com (mailing list archive)
Headers show
Series spi: Switch to use devm_spi_alloc_master() in some drivers | expand

Message

Yang Yingliang Sept. 20, 2022, 1:48 p.m. UTC
This patchset is trying to replace spi_alloc_master() with
devm_spi_alloc_master() in some spi drivers. With this helper,
spi_master_put() is called in devres_release_all() whenever
the device is unbound, so the spi_master_put() in error path
can be removed.

Yang Yingliang (6):
  spi: oc-tiny: Switch to use devm_spi_alloc_master()
  spi: ath79: Switch to use devm_spi_alloc_master()
  spi: omap-uwire: Switch to use devm_spi_alloc_master()
  spi: ppc4xx: Switch to use devm_spi_alloc_master()
  spi: sh-sci: Switch to use devm_spi_alloc_master()
  spi: altera: Switch to use devm_spi_alloc_master()

 drivers/spi/spi-altera-platform.c | 23 ++++++++-------------
 drivers/spi/spi-ath79.c           | 18 ++++++----------
 drivers/spi/spi-oc-tiny.c         | 18 ++++++----------
 drivers/spi/spi-omap-uwire.c      |  6 ++----
 drivers/spi/spi-ppc4xx.c          | 17 ++++++----------
 drivers/spi/spi-sh-sci.c          | 34 ++++++++++++-------------------
 6 files changed, 41 insertions(+), 75 deletions(-)

Comments

Mark Brown Sept. 20, 2022, 6:33 p.m. UTC | #1
On Tue, Sep 20, 2022 at 09:48:13PM +0800, Yang Yingliang wrote:
> This patchset is trying to replace spi_alloc_master() with
> devm_spi_alloc_master() in some spi drivers. With this helper,
> spi_master_put() is called in devres_release_all() whenever
> the device is unbound, so the spi_master_put() in error path
> can be removed.

If we're switching please update to the modern naming and use
"controller" rather than the old name.
Yang Yingliang Sept. 21, 2022, 2:02 a.m. UTC | #2
Hi Mark,

On 2022/9/21 2:33, Mark Brown wrote:
> On Tue, Sep 20, 2022 at 09:48:13PM +0800, Yang Yingliang wrote:
>> This patchset is trying to replace spi_alloc_master() with
>> devm_spi_alloc_master() in some spi drivers. With this helper,
>> spi_master_put() is called in devres_release_all() whenever
>> the device is unbound, so the spi_master_put() in error path
>> can be removed.
> If we're switching please update to the modern naming and use
> "controller" rather than the old name.
Do you mean to use spi_controller instead of spi_master? Something like 
this:
'struct spi_controller * ctlr = devm_spi_alloc_master();'
Dose spi_master_get_devdata()  need be changed to 
spi_controller_get_devdata() ?

Thanks,
Yang
Mark Brown Sept. 21, 2022, 12:37 p.m. UTC | #3
On Wed, Sep 21, 2022 at 10:02:25AM +0800, Yang Yingliang wrote:
> On 2022/9/21 2:33, Mark Brown wrote:

> > If we're switching please update to the modern naming and use
> > "controller" rather than the old name.

> Do you mean to use spi_controller instead of spi_master? Something like
> this:
> 'struct spi_controller * ctlr = devm_spi_alloc_master();'

Or just use devm_spi_alloc_controller() directly.

> Dose spi_master_get_devdata()  need be changed to
> spi_controller_get_devdata() ?

Ideally.
Yang Yingliang Sept. 21, 2022, 1:19 p.m. UTC | #4
On 2022/9/21 20:37, Mark Brown wrote:
> On Wed, Sep 21, 2022 at 10:02:25AM +0800, Yang Yingliang wrote:
>> On 2022/9/21 2:33, Mark Brown wrote:
>>> If we're switching please update to the modern naming and use
>>> "controller" rather than the old name.
>> Do you mean to use spi_controller instead of spi_master? Something like
>> this:
>> 'struct spi_controller * ctlr = devm_spi_alloc_master();'
> Or just use devm_spi_alloc_controller() directly.
Does __devm_spi_alloc_controller() need be changed to 
devm_spi_alloc_controller(), then use
it, or just use __devm_spi_alloc_controller() directly.

Thanks,
Yang
>
>> Dose spi_master_get_devdata()  need be changed to
>> spi_controller_get_devdata() ?
> Ideally.
Lukas Wunner Sept. 23, 2022, 4:42 a.m. UTC | #5
On Wed, Sep 21, 2022 at 01:37:49PM +0100, Mark Brown wrote:
> On Wed, Sep 21, 2022 at 10:02:25AM +0800, Yang Yingliang wrote:
> > On 2022/9/21 2:33, Mark Brown wrote:
> > > If we're switching please update to the modern naming and use
> > > "controller" rather than the old name.
> 
> > Do you mean to use spi_controller instead of spi_master? Something like
> > this:
> > 'struct spi_controller * ctlr = devm_spi_alloc_master();'
> 
> Or just use devm_spi_alloc_controller() directly.

There's no such thing.  The driver needs to explicitly allocate a
master or slave and that will result in the slave bit being set
correctly in struct spi_controller.

Yang's v2 series now calls __devm_spi_alloc_controller()
but drivers should never call that directly.

Thanks,

Lukas
Lukas Wunner Sept. 23, 2022, 5:33 a.m. UTC | #6
On Tue, Sep 20, 2022 at 09:48:13PM +0800, Yang Yingliang wrote:
> This patchset is trying to replace spi_alloc_master() with
> devm_spi_alloc_master() in some spi drivers. With this helper,
> spi_master_put() is called in devres_release_all() whenever
> the device is unbound, so the spi_master_put() in error path
> can be removed.
> 
> Yang Yingliang (6):
>   spi: oc-tiny: Switch to use devm_spi_alloc_master()
>   spi: ath79: Switch to use devm_spi_alloc_master()
>   spi: omap-uwire: Switch to use devm_spi_alloc_master()
>   spi: ppc4xx: Switch to use devm_spi_alloc_master()
>   spi: sh-sci: Switch to use devm_spi_alloc_master()
>   spi: altera: Switch to use devm_spi_alloc_master()

I'm withdrawing my objections to patches 1, 2 and 3:
I failed to appreciate that these drivers use spi_bitbang_start(),
which takes an extra reference on the controller.  Sorry for the noise.

Whole series is
Reviewed-by: Lukas Wunner <lukas@wunner.de>

This pertains to v1 of the series, not v2 (which incorrectly uses
__devm_spi_alloc_controller()).

Thanks,

Lukas
Lukas Wunner Sept. 23, 2022, 5:39 a.m. UTC | #7
On Wed, Sep 21, 2022 at 09:19:35PM +0800, Yang Yingliang wrote:
> On 2022/9/21 20:37, Mark Brown wrote:
> > On Wed, Sep 21, 2022 at 10:02:25AM +0800, Yang Yingliang wrote:
> > > On 2022/9/21 2:33, Mark Brown wrote:
> > > > If we're switching please update to the modern naming and use
> > > > "controller" rather than the old name.
> > > Do you mean to use spi_controller instead of spi_master? Something like
> > > this:
> > > 'struct spi_controller * ctlr = devm_spi_alloc_master();'
> > 
> > Or just use devm_spi_alloc_controller() directly.
> 
> Does __devm_spi_alloc_controller() need be changed to
> devm_spi_alloc_controller(), then use
> it, or just use __devm_spi_alloc_controller() directly.

Modern drivers only differentiate between master and slave on
allocation.  They use struct spi_controller instead of spi_master
and generally only call the spi_controller_*() functions (again,
except on allocation).  I think Mark wanted you to convert the
drivers so that they use struct spi_controller everywhere,
but that can be done in separate patches.

Thanks,

Lukas
Mark Brown Sept. 23, 2022, 10:12 a.m. UTC | #8
On Fri, Sep 23, 2022 at 06:42:58AM +0200, Lukas Wunner wrote:
> On Wed, Sep 21, 2022 at 01:37:49PM +0100, Mark Brown wrote:

> > Or just use devm_spi_alloc_controller() directly.

> There's no such thing.  The driver needs to explicitly allocate a
> master or slave and that will result in the slave bit being set
> correctly in struct spi_controller.

> Yang's v2 series now calls __devm_spi_alloc_controller()
> but drivers should never call that directly.

Right, we should probably make the actual function to wrap that though -
I'd misremembered that that hadn't been created.
Yang Yingliang Sept. 23, 2022, 2:48 p.m. UTC | #9
On 2022/9/23 18:12, Mark Brown wrote:
> On Fri, Sep 23, 2022 at 06:42:58AM +0200, Lukas Wunner wrote:
>> On Wed, Sep 21, 2022 at 01:37:49PM +0100, Mark Brown wrote:
>>> Or just use devm_spi_alloc_controller() directly.
>> There's no such thing.  The driver needs to explicitly allocate a
>> master or slave and that will result in the slave bit being set
>> correctly in struct spi_controller.
>> Yang's v2 series now calls __devm_spi_alloc_controller()
>> but drivers should never call that directly.
> Right, we should probably make the actual function to wrap that though -
> I'd misremembered that that hadn't been created.
How about introduce devm_spi_alloc_controller() like this:

diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index f089ee1ead58..67e510c8d15e 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -763,6 +763,8 @@ struct spi_controller 
*__devm_spi_alloc_controller(struct device *dev,
                                                    unsigned int size,
                                                    bool slave);

+#define devm_spi_alloc_controller devm_spi_alloc_master
+
Thanks,
Yang