[v1,1/1] regmap: spi: Use spi_message_init_with_transfers()

Message ID 20230710142335.66598-1-andriy.shevchenko@linux.intel.com
State New
Headers
Series [v1,1/1] regmap: spi: Use spi_message_init_with_transfers() |

Commit Message

Andy Shevchenko July 10, 2023, 2:23 p.m. UTC
  Use spi_message_init_with_transfers() instead of open coded variants.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/base/regmap/regmap-spi.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
  

Comments

Cristian Ciocaltea July 10, 2023, 2:34 p.m. UTC | #1
On 7/10/23 17:23, Andy Shevchenko wrote:
> Use spi_message_init_with_transfers() instead of open coded variants.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
  
Mark Brown July 10, 2023, 2:38 p.m. UTC | #2
On Mon, Jul 10, 2023 at 05:23:35PM +0300, Andy Shevchenko wrote:

> @@ -66,10 +64,7 @@ static int regmap_spi_async_write(void *context,
>  	async->t[1].tx_buf = val;
>  	async->t[1].len = val_len;
>  
> -	spi_message_init(&async->m);
> -	spi_message_add_tail(&async->t[0], &async->m);
> -	if (val)
> -		spi_message_add_tail(&async->t[1], &async->m);
> +	spi_message_init_with_transfers(&async->m, async->t, val ? 2 : 1);

I'm not sure this is a legibility win.
  
Andy Shevchenko July 10, 2023, 3:01 p.m. UTC | #3
On Mon, Jul 10, 2023 at 03:38:55PM +0100, Mark Brown wrote:
> On Mon, Jul 10, 2023 at 05:23:35PM +0300, Andy Shevchenko wrote:

...

> > -	spi_message_init(&async->m);
> > -	spi_message_add_tail(&async->t[0], &async->m);
> > -	if (val)
> > -		spi_message_add_tail(&async->t[1], &async->m);
> > +	spi_message_init_with_transfers(&async->m, async->t, val ? 2 : 1);
> 
> I'm not sure this is a legibility win.

Fair enough. Since it's not an inlined call, ion x86_64 it gives +64 bytes
to the code.

Let's drop it.
  
Mark Brown July 10, 2023, 3:54 p.m. UTC | #4
On Mon, Jul 10, 2023 at 06:01:47PM +0300, Andy Shevchenko wrote:
> On Mon, Jul 10, 2023 at 03:38:55PM +0100, Mark Brown wrote:
> 
> > > +	spi_message_init_with_transfers(&async->m, async->t, val ? 2 : 1);

> > I'm not sure this is a legibility win.

> Fair enough. Since it's not an inlined call, ion x86_64 it gives +64 bytes
> to the code.

> Let's drop it.

Sure.  The ones without the ternery operator are fine.
  

Patch

diff --git a/drivers/base/regmap/regmap-spi.c b/drivers/base/regmap/regmap-spi.c
index 37ab23a9d034..65e8adac8d0e 100644
--- a/drivers/base/regmap/regmap-spi.c
+++ b/drivers/base/regmap/regmap-spi.c
@@ -43,9 +43,7 @@  static int regmap_spi_gather_write(void *context,
 	struct spi_transfer t[2] = { { .tx_buf = reg, .len = reg_len, },
 				     { .tx_buf = val, .len = val_len, }, };
 
-	spi_message_init(&m);
-	spi_message_add_tail(&t[0], &m);
-	spi_message_add_tail(&t[1], &m);
+	spi_message_init_with_transfers(&m, t, 2);
 
 	return spi_sync(spi, &m);
 }
@@ -66,10 +64,7 @@  static int regmap_spi_async_write(void *context,
 	async->t[1].tx_buf = val;
 	async->t[1].len = val_len;
 
-	spi_message_init(&async->m);
-	spi_message_add_tail(&async->t[0], &async->m);
-	if (val)
-		spi_message_add_tail(&async->t[1], &async->m);
+	spi_message_init_with_transfers(&async->m, async->t, val ? 2 : 1);
 
 	async->m.complete = regmap_spi_complete;
 	async->m.context = async;