All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] can: mcp251xfd: replace sizeof(u32) with val_bytes in regmap
@ 2021-01-22  8:13 Su Yanjun
  2021-01-22  8:31 ` Marc Kleine-Budde
  0 siblings, 1 reply; 2+ messages in thread
From: Su Yanjun @ 2021-01-22  8:13 UTC (permalink / raw)
  To: mkl, manivannan.sadhasivam, thomas.kopp, wg, davem, kuba,
	lgirdwood, broonie
  Cc: linux-can, netdev, linux-kernel, Su Yanjun

The sizeof(u32) is hardcoded. It's better to use the config value in
regmap.

It increases the size of target object, but it's flexible when new mcp chip
need other val_bytes.

Signed-off-by: Su Yanjun <suyanjun218@gmail.com>
---
 drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
index f07e8b737d31..3dde52669343 100644
--- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
+++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
@@ -1308,6 +1308,7 @@ mcp251xfd_tef_obj_read(const struct mcp251xfd_priv *priv,
 		       const u8 offset, const u8 len)
 {
 	const struct mcp251xfd_tx_ring *tx_ring = priv->tx;
+	int val_bytes = regmap_get_val_bytes(priv->map_rx);
 
 	if (IS_ENABLED(CONFIG_CAN_MCP251XFD_SANITY) &&
 	    (offset > tx_ring->obj_num ||
@@ -1322,7 +1323,7 @@ mcp251xfd_tef_obj_read(const struct mcp251xfd_priv *priv,
 	return regmap_bulk_read(priv->map_rx,
 				mcp251xfd_get_tef_obj_addr(offset),
 				hw_tef_obj,
-				sizeof(*hw_tef_obj) / sizeof(u32) * len);
+				sizeof(*hw_tef_obj) / val_bytes * len);
 }
 
 static int mcp251xfd_handle_tefif(struct mcp251xfd_priv *priv)
@@ -1511,11 +1512,12 @@ mcp251xfd_rx_obj_read(const struct mcp251xfd_priv *priv,
 		      const u8 offset, const u8 len)
 {
 	int err;
+	int val_bytes = regmap_get_val_bytes(priv->map_rx);
 
 	err = regmap_bulk_read(priv->map_rx,
 			       mcp251xfd_get_rx_obj_addr(ring, offset),
 			       hw_rx_obj,
-			       len * ring->obj_size / sizeof(u32));
+			       len * ring->obj_size / val_bytes);
 
 	return err;
 }
@@ -2139,6 +2141,7 @@ static irqreturn_t mcp251xfd_irq(int irq, void *dev_id)
 	struct mcp251xfd_priv *priv = dev_id;
 	irqreturn_t handled = IRQ_NONE;
 	int err;
+	int val_bytes = regmap_get_val_bytes(priv->map_reg);
 
 	if (priv->rx_int)
 		do {
@@ -2162,7 +2165,7 @@ static irqreturn_t mcp251xfd_irq(int irq, void *dev_id)
 		err = regmap_bulk_read(priv->map_reg, MCP251XFD_REG_INT,
 				       &priv->regs_status,
 				       sizeof(priv->regs_status) /
-				       sizeof(u32));
+				       val_bytes);
 		if (err)
 			goto out_fail;
 
-- 
2.25.1


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

* Re: [PATCH v4] can: mcp251xfd: replace sizeof(u32) with val_bytes in regmap
  2021-01-22  8:13 [PATCH v4] can: mcp251xfd: replace sizeof(u32) with val_bytes in regmap Su Yanjun
@ 2021-01-22  8:31 ` Marc Kleine-Budde
  0 siblings, 0 replies; 2+ messages in thread
From: Marc Kleine-Budde @ 2021-01-22  8:31 UTC (permalink / raw)
  To: Su Yanjun
  Cc: manivannan.sadhasivam, thomas.kopp, wg, davem, kuba, linux-can,
	netdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 633 bytes --]

On Fri, Jan 22, 2021 at 04:13:34PM +0800, Su Yanjun wrote:
> The sizeof(u32) is hardcoded. It's better to use the config value in
> regmap.
> 
> It increases the size of target object, but it's flexible when new mcp chip
> need other val_bytes.
> 
> Signed-off-by: Su Yanjun <suyanjun218@gmail.com>

Applied to linux-can-next/testing.

Thanks,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2021-01-22  8:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-22  8:13 [PATCH v4] can: mcp251xfd: replace sizeof(u32) with val_bytes in regmap Su Yanjun
2021-01-22  8:31 ` Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.