Skip to contentSkip to conversation

net: davinci_emac: fix oops caused by uninitialized ndev->dev

PATCH Applied Sekhar Nori 5 participants 5 messages May 20, 2014 – May 22, 2014

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

PATCH 1/1 net: davinci_emac: fix oops caused by uninitialized ndev->dev

Commit e194312854edc22a2faf1931b3c0608fe20cb969 (drivers: net:
davinci_cpdma: Convert kzalloc() to devm_kzalloc()) triggered a bug in emac_probe() wherein dev member of net_device is used for devres allocations even before it is initialized.

This patch fixes that by using the struct device in platform_device instead.

While at it, use &pdev->dev consistently for console messages instead of using ndev->dev for just one case and remove an unnecessary line continuation.

---
This patch fixes a bug in linux-next so it can wait for v3.16

 drivers/net/ethernet/ti/davinci_emac.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/ti/davinci_emac.c +2 -4
index e76eae5..f32d730 100644
@@ -1865,7 +1865,6 @@ static int davinci_emac_probe(struct platform_device *pdev)
 	struct emac_priv *priv;
 	unsigned long hw_ram_addr;
 	struct emac_platform_data *pdata;
-	struct device *emac_dev;
 	struct cpdma_params dma_params;
 	struct clk *emac_clk;
 	unsigned long emac_bus_frequency;
@@ -1911,7 +1910,6 @@ static int davinci_emac_probe(struct platform_device *pdev)
 	priv->coal_intvl = 0;
 	priv->bus_freq_mhz = (u32)(emac_bus_frequency / 1000000);
 
-	emac_dev = &ndev->dev;
 	/* Get EMAC platform data */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	priv->emac_base_phys = res->start + pdata->ctrl_reg_offset;
@@ -1930,7 +1928,7 @@ static int davinci_emac_probe(struct platform_device *pdev)
 		hw_ram_addr = (u32 __force)res->start + pdata->ctrl_ram_offset;
 
 	memset(&dma_params, 0, sizeof(dma_params));
-	dma_params.dev			= emac_dev;
+	dma_params.dev			= &pdev->dev;
 	dma_params.dmaregs		= priv->emac_base;
 	dma_params.rxthresh		= priv->emac_base + 0x120;
 	dma_params.rxfree		= priv->emac_base + 0x140;
@@ -1994,7 +1992,7 @@ static int davinci_emac_probe(struct platform_device *pdev)
 
 
 	if (netif_msg_probe(priv)) {
-		dev_notice(emac_dev, "DaVinci EMAC Probe found device "\
+		dev_notice(&pdev->dev, "DaVinci EMAC Probe found device "
 			   "(regs: %p, irq: %d)\n",
 			   (void *)priv->emac_base_phys, ndev->irq);
 	}
Signature · 1 line
1.7.10.1
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Sekhar Nori

Commit e194312854edc22a2faf1931b3c0608fe20cb969 (drivers: net:
davinci_cpdma: Convert kzalloc() to devm_kzalloc()) triggered a bug in emac_probe() wherein dev member of net_device is used for devres allocations even before it is initialized.

This patch fixes that by using the struct device in platform_device instead.

Quoted 8 lines

While at it, use &pdev->dev consistently for console messages instead of using ndev->dev for just one case and remove an unnecessary line continuation.

---

Regards
Mugunthan V N

Tested-by on v1 1/1
#2 lore raw
In reply to Sekhar Nori
Quoted 8 lines · Sekhar Nori

Commit e194312854edc22a2faf1931b3c0608fe20cb969 (drivers: net:
davinci_cpdma: Convert kzalloc() to devm_kzalloc()) triggered a bug in emac_probe() wherein dev member of net_device is used for devres allocations even before it is initialized.

This patch fixes that by using the struct device in platform_device instead.

Quoted 7 lines

While at it, use &pdev->dev consistently for console messages instead of using ndev->dev for just one case and remove an unnecessary line continuation.

Regards,
--Prabhakar Lad

Quoted 48 lines

---
This patch fixes a bug in linux-next so it can wait for v3.16

 drivers/net/ethernet/ti/davinci_emac.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/ti/davinci_emac.c +2 -5
index e76eae5..f32d730 100644
@@ -1865,7 +1865,6 @@ static int davinci_emac_probe(struct platform_device *pdev)
        struct emac_priv *priv;
        unsigned long hw_ram_addr;
        struct emac_platform_data *pdata;
-       struct device *emac_dev;
        struct cpdma_params dma_params;
        struct clk *emac_clk;
        unsigned long emac_bus_frequency;
@@ -1911,7 +1910,6 @@ static int davinci_emac_probe(struct platform_device *pdev)
        priv->coal_intvl = 0;
        priv->bus_freq_mhz = (u32)(emac_bus_frequency / 1000000);
 
-       emac_dev = &ndev->dev;
        /* Get EMAC platform data */
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        priv->emac_base_phys = res->start + pdata->ctrl_reg_offset;
@@ -1930,7 +1928,7 @@ static int davinci_emac_probe(struct platform_device *pdev)
                hw_ram_addr = (u32 __force)res->start + pdata->ctrl_ram_offset;
 
        memset(&dma_params, 0, sizeof(dma_params));
-       dma_params.dev                  = emac_dev;
+       dma_params.dev                  = &pdev->dev;
        dma_params.dmaregs              = priv->emac_base;
        dma_params.rxthresh             = priv->emac_base + 0x120;
        dma_params.rxfree               = priv->emac_base + 0x140;
@@ -1994,7 +1992,7 @@ static int davinci_emac_probe(struct platform_device *pdev)
 
 
        if (netif_msg_probe(priv)) {
-               dev_notice(emac_dev, "DaVinci EMAC Probe found device "\
+               dev_notice(&pdev->dev, "DaVinci EMAC Probe found device "
                           "(regs: %p, irq: %d)\n",
                           (void *)priv->emac_base_phys, ndev->irq);
        }
--

1.7.10.1

Tested-by on v1 1/1
#3 lore raw
In reply to Sekhar Nori
Quoted 8 lines · Sekhar Nori

Commit e194312854edc22a2faf1931b3c0608fe20cb969 (drivers: net:
davinci_cpdma: Convert kzalloc() to devm_kzalloc()) triggered a bug in emac_probe() wherein dev member of net_device is used for devres allocations even before it is initialized.

This patch fixes that by using the struct device in platform_device instead.

Quoted 7 lines

While at it, use &pdev->dev consistently for console messages instead of using ndev->dev for just one case and remove an unnecessary line continuation.

I verified this patch fixes the boot on dm365-evm (legacy boot) and da850-evm (DT boot).

Thanks,

Kevin

maintainer Applied
#4 lore raw
In reply to Sekhar Nori

From: Sekhar Nori <[email protected]>
Date: Tue, 20 May 2014 15:41:37 +0530

Quoted 12 lines

Commit e194312854edc22a2faf1931b3c0608fe20cb969 (drivers: net:
davinci_cpdma: Convert kzalloc() to devm_kzalloc()) triggered a bug in emac_probe() wherein dev member of net_device is used for devres allocations even before it is initialized.

This patch fixes that by using the struct device in platform_device instead.

While at it, use &pdev->dev consistently for console messages instead of using ndev->dev for just one case and remove an unnecessary line continuation.

Quoted 6 lines

---
This patch fixes a bug in linux-next so it can wait for v3.16

Applied to net-next, thanks.