Skip to contentSkip to conversation

regmap: spi: Use spi_message_init_with_transfers()

PATCH In review Andy Shevchenko 3 participants 5 messages Jul 10, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regmap: spi: Use spi_message_init_with_transfers()

Use spi_message_init_with_transfers() instead of open coded variants.

---
 drivers/base/regmap/regmap-spi.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/base/regmap/regmap-spi.c +2 -7
index 37ab23a9d034..65e8adac8d0e 100644
@@ -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;
Signature · 1 line
2.40.0.1.gaa8946217a0b
maintainer
#2 lore raw
In reply to Andy Shevchenko

drivers/base/regmap/regmap-spi.c static int regmap_spi_async_write(void *context, · line 67

Quoted 9 lines · Andy Shevchenko
drivers/base/regmap/regmap-spi.c +1 -4
@@ -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.

#3 lore raw
Quoted 1 line · Mark Brown

On Mon, Jul 10, 2023 at 05:23:35PM +0300, Andy Shevchenko wrote:

...

Quoted 7 lines

drivers/base/regmap/regmap-spi.c static int regmap_spi_async_write(void *context, · line 67

Quoted 5 lines
drivers/base/regmap/regmap-spi.c +1 -4
-	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.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#4 lore raw
Quoted 10 lines · Andy Shevchenko
Quoted 3 lines · Mark Brown

drivers/base/regmap/regmap-spi.c static int regmap_spi_async_write(void *context, · line 67

Quoted 1 line
drivers/base/regmap/regmap-spi.c +1 -0
+	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.