Subject: Re: [PATCH] stmmac: fix sleep inside atomic

From: Peppe CAVALLARO <[email-masked]>
Date: Tue, 7 Sep 2010 07:55:55 +0200

Hi David,
On 9/6/2010 10:11 PM, David Miller wrote:
>
> From: Giuseppe CAVALLARO <[email-masked]>
> Date: Mon,  6 Sep 2010 05:06:19 +0200
>
> > We cannot use spinlock when kmalloc is invoked with
> > GFP_KERNEL flag because it can sleep.
> > So this patch reviews the usage of spinlock within the
> > stmmac_resume function avoing this bug.
> >
> > Signed-off-by: Giuseppe Cavallaro <[email-masked]>
>
> Applied, but you are extremely guilty of the sin of omission
> here.
>
> Why in the world did you not at least CC: Jiri, the person
> who reported this problem?  You should do that at a minimum
> when someone reports a problem with code you are fixing.
>
You are right and I'm awfully sorry for this (sorry Jiri!).
>
> And in this case he definitely deserves a
>
> Reported-by:
>
> tag in the commit message as well.
>
> Please don't fail to acknowledge a reporter's efforts like
> this ever again.
>

This will never happen.
I've attached the patch reviewed as well.

I hope this has not hurt Jiri.

Regards,
Peppe

P.S. I'm waiting for my third baby so I'm quite stressed and busy in
these days.
I wanted fixed the issue spotted by Jiri but I was too fast to send the
patch.
I hope this can help to save me ;-)
From 88f4ac7e90bfe4c54316a7ac5e064264e1acf6a4 Mon Sep 17 00:00:00 2001
From: Giuseppe Cavallaro <[email-masked]>
Date: Mon, 6 Sep 2010 05:02:11 +0200
Subject: [PATCH] stmmac: fix sleep inside atomic

We cannot use spinlock when kmalloc is invoked with
GFP_KERNEL flag because it can sleep.
So this patch reviews the usage of spinlock within the
stmmac_resume function avoing this bug.

Signed-off-by: Giuseppe Cavallaro <[email-masked]>
Reported-by: Jiri Slaby <[email-masked]>
---
 drivers/net/stmmac/stmmac_main.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/net/stmmac/stmmac_main.c b/drivers/net/stmmac/stmmac_main.c
index bbb7951..a9befd6 100644
--- a/drivers/net/stmmac/stmmac_main.c
+++ b/drivers/net/stmmac/stmmac_main.c
@@ -1865,15 +1865,15 @@ static int stmmac_resume(struct platform_device *pdev)
 	if (!netif_running(dev))
 		return 0;
 
-	spin_lock(&priv->lock);
-
 	if (priv->shutdown) {
 		/* Re-open the interface and re-init the MAC/DMA
-		   and the rings. */
+		   and the rings (i.e. on hibernation stage) */
 		stmmac_open(dev);
-		goto out_resume;
+		return 0;
 	}
 
+	spin_lock(&priv->lock);
+
 	/* Power Down bit, into the PM register, is cleared
 	 * automatically as soon as a magic packet or a Wake-up frame
 	 * is received. Anyway, it's better to manually clear
@@ -1901,7 +1901,6 @@ static int stmmac_resume(struct platform_device *pdev)
 
 	netif_start_queue(dev);
 
-out_resume:
 	spin_unlock(&priv->lock);
 	return 0;
 }
-- 
1.5.5.6