linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/3] can: m_can: pci: add missing m_can_class_free_dev() in probe/remove methods
@ 2022-11-11 12:11 Zhang Changzhong
  2022-11-14 14:57 ` Jarkko Nikula
  2022-11-24 15:02 ` Marc Kleine-Budde
  0 siblings, 2 replies; 3+ messages in thread
From: Zhang Changzhong @ 2022-11-11 12:11 UTC (permalink / raw)
  To: Wolfgang Grandegger, Marc Kleine-Budde, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Raymond Tan,
	Felipe Balbi (Intel),
	Jarkko Nikula
  Cc: Zhang Changzhong, linux-can, netdev, linux-kernel

In m_can_pci_remove() and error handling path of m_can_pci_probe(),
m_can_class_free_dev() should be called to free resource allocated by
m_can_class_allocate_dev(), otherwise there will be memleak.

Fixes: cab7ffc0324f ("can: m_can: add PCI glue driver for Intel Elkhart Lake")
Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
---
 drivers/net/can/m_can/m_can_pci.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/m_can/m_can_pci.c b/drivers/net/can/m_can/m_can_pci.c
index 8f184a8..f2219aa 100644
--- a/drivers/net/can/m_can/m_can_pci.c
+++ b/drivers/net/can/m_can/m_can_pci.c
@@ -120,7 +120,7 @@ static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
 
 	ret = pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_ALL_TYPES);
 	if (ret < 0)
-		return ret;
+		goto err_free_dev;
 
 	mcan_class->dev = &pci->dev;
 	mcan_class->net->irq = pci_irq_vector(pci, 0);
@@ -132,7 +132,7 @@ static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
 
 	ret = m_can_class_register(mcan_class);
 	if (ret)
-		goto err;
+		goto err_free_irq;
 
 	/* Enable interrupt control at CAN wrapper IP */
 	writel(0x1, base + CTL_CSR_INT_CTL_OFFSET);
@@ -144,8 +144,10 @@ static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
 
 	return 0;
 
-err:
+err_free_irq:
 	pci_free_irq_vectors(pci);
+err_free_dev:
+	m_can_class_free_dev(mcan_class->net);
 	return ret;
 }
 
@@ -161,6 +163,7 @@ static void m_can_pci_remove(struct pci_dev *pci)
 	writel(0x0, priv->base + CTL_CSR_INT_CTL_OFFSET);
 
 	m_can_class_unregister(mcan_class);
+	m_can_class_free_dev(mcan_class->net);
 	pci_free_irq_vectors(pci);
 }
 
-- 
2.9.5


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

* Re: [PATCH 3/3] can: m_can: pci: add missing m_can_class_free_dev() in probe/remove methods
  2022-11-11 12:11 [PATCH 3/3] can: m_can: pci: add missing m_can_class_free_dev() in probe/remove methods Zhang Changzhong
@ 2022-11-14 14:57 ` Jarkko Nikula
  2022-11-24 15:02 ` Marc Kleine-Budde
  1 sibling, 0 replies; 3+ messages in thread
From: Jarkko Nikula @ 2022-11-14 14:57 UTC (permalink / raw)
  To: Zhang Changzhong, Wolfgang Grandegger, Marc Kleine-Budde,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Raymond Tan, Felipe Balbi (Intel)
  Cc: linux-can, netdev, linux-kernel

On 11/11/22 14:11, Zhang Changzhong wrote:
> In m_can_pci_remove() and error handling path of m_can_pci_probe(),
> m_can_class_free_dev() should be called to free resource allocated by
> m_can_class_allocate_dev(), otherwise there will be memleak.
> 
> Fixes: cab7ffc0324f ("can: m_can: add PCI glue driver for Intel Elkhart Lake")
> Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
> ---
>   drivers/net/can/m_can/m_can_pci.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
> 
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

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

* Re: [PATCH 3/3] can: m_can: pci: add missing m_can_class_free_dev() in probe/remove methods
  2022-11-11 12:11 [PATCH 3/3] can: m_can: pci: add missing m_can_class_free_dev() in probe/remove methods Zhang Changzhong
  2022-11-14 14:57 ` Jarkko Nikula
@ 2022-11-24 15:02 ` Marc Kleine-Budde
  1 sibling, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2022-11-24 15:02 UTC (permalink / raw)
  To: Zhang Changzhong
  Cc: Wolfgang Grandegger, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Raymond Tan, Felipe Balbi (Intel),
	Jarkko Nikula, linux-can, netdev, linux-kernel

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

On 11.11.2022 20:11:23, Zhang Changzhong wrote:
> In m_can_pci_remove() and error handling path of m_can_pci_probe(),
> m_can_class_free_dev() should be called to free resource allocated by
> m_can_class_allocate_dev(), otherwise there will be memleak.
> 
> Fixes: cab7ffc0324f ("can: m_can: add PCI glue driver for Intel Elkhart Lake")
> Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>

Applied to linux-can.

regards,
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] 3+ messages in thread

end of thread, other threads:[~2022-11-24 15:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-11 12:11 [PATCH 3/3] can: m_can: pci: add missing m_can_class_free_dev() in probe/remove methods Zhang Changzhong
2022-11-14 14:57 ` Jarkko Nikula
2022-11-24 15:02 ` Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).