Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da9eb43b authored by Daniel Hellstrom's avatar Daniel Hellstrom Committed by Greg Kroah-Hartman
Browse files

can: grcan: use ofdev->dev when allocating DMA memory

commit 101da4268626b00d16356a6bf284d66e44c46ff9 upstream.

Use the device of the device tree node should be rather than the
device of the struct net_device when allocating DMA buffers.

The driver got away with it on sparc32 until commit 53b7670e
("sparc: factor the dma coherent mapping into helper") after which the
driver oopses.

Fixes: 6cec9b07 ("can: grcan: Add device driver for GRCAN and GRHCAN cores")
Link: https://lore.kernel.org/all/20220429084656.29788-2-andreas@gaisler.com


Cc: stable@vger.kernel.org
Signed-off-by: default avatarDaniel Hellstrom <daniel@gaisler.com>
Signed-off-by: default avatarAndreas Larsson <andreas@gaisler.com>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8b451b7d
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -248,6 +248,7 @@ struct grcan_device_config {
struct grcan_priv {
struct grcan_priv {
	struct can_priv can;	/* must be the first member */
	struct can_priv can;	/* must be the first member */
	struct net_device *dev;
	struct net_device *dev;
	struct device *ofdev_dev;
	struct napi_struct napi;
	struct napi_struct napi;


	struct grcan_registers __iomem *regs;	/* ioremap'ed registers */
	struct grcan_registers __iomem *regs;	/* ioremap'ed registers */
@@ -924,7 +925,7 @@ static void grcan_free_dma_buffers(struct net_device *dev)
	struct grcan_priv *priv = netdev_priv(dev);
	struct grcan_priv *priv = netdev_priv(dev);
	struct grcan_dma *dma = &priv->dma;
	struct grcan_dma *dma = &priv->dma;


	dma_free_coherent(&dev->dev, dma->base_size, dma->base_buf,
	dma_free_coherent(priv->ofdev_dev, dma->base_size, dma->base_buf,
			  dma->base_handle);
			  dma->base_handle);
	memset(dma, 0, sizeof(*dma));
	memset(dma, 0, sizeof(*dma));
}
}
@@ -949,7 +950,7 @@ static int grcan_allocate_dma_buffers(struct net_device *dev,


	/* Extra GRCAN_BUFFER_ALIGNMENT to allow for alignment */
	/* Extra GRCAN_BUFFER_ALIGNMENT to allow for alignment */
	dma->base_size = lsize + ssize + GRCAN_BUFFER_ALIGNMENT;
	dma->base_size = lsize + ssize + GRCAN_BUFFER_ALIGNMENT;
	dma->base_buf = dma_alloc_coherent(&dev->dev,
	dma->base_buf = dma_alloc_coherent(priv->ofdev_dev,
					   dma->base_size,
					   dma->base_size,
					   &dma->base_handle,
					   &dma->base_handle,
					   GFP_KERNEL);
					   GFP_KERNEL);
@@ -1602,6 +1603,7 @@ static int grcan_setup_netdev(struct platform_device *ofdev,
	memcpy(&priv->config, &grcan_module_config,
	memcpy(&priv->config, &grcan_module_config,
	       sizeof(struct grcan_device_config));
	       sizeof(struct grcan_device_config));
	priv->dev = dev;
	priv->dev = dev;
	priv->ofdev_dev = &ofdev->dev;
	priv->regs = base;
	priv->regs = base;
	priv->can.bittiming_const = &grcan_bittiming_const;
	priv->can.bittiming_const = &grcan_bittiming_const;
	priv->can.do_set_bittiming = grcan_set_bittiming;
	priv->can.do_set_bittiming = grcan_set_bittiming;