mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH] cli()/sti() fix for drivers/net/ewrk3.c
  2002-10-03  0:59 [PATCH] cli()/sti() fix for drivers/net/ewrk3.c Denis Vlasenko
@ 2002-10-02 20:45 ` Francois Romieu
  2002-10-03 13:08   ` Denis Vlasenko
  0 siblings, 1 reply; 4+ messages in thread
From: Francois Romieu @ 2002-10-02 20:45 UTC (permalink / raw)
  To: linux-kernel

Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua> :
[...]
> diff -u --recursive linux-2.5.38orig/drivers/net/ewrk3.c linux-2.5.38/drivers/net/ewrk3.c
> --- linux-2.5.38orig/drivers/net/ewrk3.c	Sun Sep 22 04:25:09 2002
> +++ linux-2.5.38/drivers/net/ewrk3.c	Wed Oct  2 01:29:31 2002
[...]

The remarks done for drivers/net/depca.c patch apply equally as well.

-- 
Ueimor

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

* [PATCH] cli()/sti() fix for drivers/net/ewrk3.c
@ 2002-10-03  0:59 Denis Vlasenko
  2002-10-02 20:45 ` Francois Romieu
  0 siblings, 1 reply; 4+ messages in thread
From: Denis Vlasenko @ 2002-10-03  0:59 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton, Jeff Garzik, David S. Miller

These are my first patches for network drivers.
Please comment if I'm doing something wrong.
Compile tested. Testers with hw wanted.
--
vda

diff -u --recursive linux-2.5.38orig/drivers/net/ewrk3.c linux-2.5.38/drivers/net/ewrk3.c
--- linux-2.5.38orig/drivers/net/ewrk3.c	Sun Sep 22 04:25:09 2002
+++ linux-2.5.38/drivers/net/ewrk3.c	Wed Oct  2 01:29:31 2002
@@ -1631,6 +1631,7 @@
 	u_long iobase = dev->base_addr;
 	int i, j, status = 0;
 	u_char csr;
+	unsigned long flags;
 	union ewrk3_addr {
 		u_char addr[HASH_TABLE_LEN * ETH_ALEN];
 		u_short val[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
@@ -1746,18 +1747,18 @@

 		break;
 	case EWRK3_GET_STATS:	/* Get the driver statistics */
-		cli();
+		spin_lock_irqsave(&lp->hw_lock, flags);
 		ioc->len = sizeof(lp->pktStats);
 		if (copy_to_user(ioc->data, &lp->pktStats, ioc->len))
 			status = -EFAULT;
-		sti();
+		spin_unlock_irqrestore(&lp->hw_lock,flags);

 		break;
 	case EWRK3_CLR_STATS:	/* Zero out the driver statistics */
 		if (capable(CAP_NET_ADMIN)) {
-			cli();
+			spin_lock_irqsave(&lp->hw_lock, flags);
 			memset(&lp->pktStats, 0, sizeof(lp->pktStats));
-			sti();
+			spin_unlock_irqrestore(&lp->hw_lock,flags);
 		} else {
 			status = -EPERM;
 		}

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

* Re: [PATCH] cli()/sti() fix for drivers/net/ewrk3.c
  2002-10-02 20:45 ` Francois Romieu
@ 2002-10-03 13:08   ` Denis Vlasenko
  2002-10-03 14:14     ` Denis Vlasenko
  0 siblings, 1 reply; 4+ messages in thread
From: Denis Vlasenko @ 2002-10-03 13:08 UTC (permalink / raw)
  To: Francois Romieu, linux-kernel; +Cc: acme, davies

On 2 October 2002 18:45, Francois Romieu wrote:
> Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua> :
> [...]
>
> > diff -u --recursive linux-2.5.38orig/drivers/net/ewrk3.c
> > linux-2.5.38/drivers/net/ewrk3.c ---
> > linux-2.5.38orig/drivers/net/ewrk3.c	Sun Sep 22 04:25:09 2002 +++
> > linux-2.5.38/drivers/net/ewrk3.c	Wed Oct  2 01:29:31 2002
>
> [...]
>
> The remarks done for drivers/net/depca.c patch apply equally as well.

Fixes similar to depca.c applied :-)
Testers with hardware, anyone?
--
vda

diff -u --recursive linux-2.5.40org/drivers/net/ewrk3.c linux-2.5.40/drivers/net/ewrk3.c
--- linux-2.5.40org/drivers/net/ewrk3.c	Tue Oct  1 05:06:58 2002
+++ linux-2.5.40/drivers/net/ewrk3.c	Thu Oct  3 11:04:33 2002
@@ -930,6 +930,7 @@
 	spin_unlock(&lp->hw_lock);
 }
 
+/* Called with lp->lock held */
 static int ewrk3_rx(struct net_device *dev)
 {
 	struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
@@ -1055,8 +1056,9 @@
 }
 
 /*
-   ** Buffer sent - check for TX buffer errors.
- */
+** Buffer sent - check for TX buffer errors.
+** Called with lp->lock held
+*/
 static int ewrk3_tx(struct net_device *dev)
 {
 	struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
@@ -1631,6 +1633,7 @@
 	u_long iobase = dev->base_addr;
 	int i, j, status = 0;
 	u_char csr;
+	unsigned long flags;
 	union ewrk3_addr {
 		u_char addr[HASH_TABLE_LEN * ETH_ALEN];
 		u_short val[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
@@ -1745,19 +1748,26 @@
 		}
 
 		break;
-	case EWRK3_GET_STATS:	/* Get the driver statistics */
-		cli();
-		ioc->len = sizeof(lp->pktStats);
-		if (copy_to_user(ioc->data, &lp->pktStats, ioc->len))
-			status = -EFAULT;
-		sti();
+	case EWRK3_GET_STATS: { /* Get the driver statistics */
+		typeof(lp->pktStats) *tmp_stats =
+        		kmalloc(sizeof(lp->pktStats), GFP_KERNEL);
+		if (!tmp_stats) return -ENOMEM;
+
+		spin_lock_irqsave(&lp->lock, flags);
+		memcpy(tmp_stats, &lp->pktStats, sizeof(lp->pktStats));
+		spin_unlock_irqrestore(&lp->lock, flags);
 
+		ioc->len = sizeof(lp->pktStats);
+		if (copy_to_user(ioc->data, tmp_stats, sizeof(lp->pktStats)))
+    			status = -EFAULT;
+		kfree(tmp_stats);
 		break;
+	}
 	case EWRK3_CLR_STATS:	/* Zero out the driver statistics */
 		if (capable(CAP_NET_ADMIN)) {
-			cli();
+			spin_lock_irqsave(&lp->hw_lock, flags);
 			memset(&lp->pktStats, 0, sizeof(lp->pktStats));
-			sti();
+			spin_unlock_irqrestore(&lp->hw_lock,flags);
 		} else {
 			status = -EPERM;
 		}

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

* Re: [PATCH] cli()/sti() fix for drivers/net/ewrk3.c
  2002-10-03 13:08   ` Denis Vlasenko
@ 2002-10-03 14:14     ` Denis Vlasenko
  0 siblings, 0 replies; 4+ messages in thread
From: Denis Vlasenko @ 2002-10-03 14:14 UTC (permalink / raw)
  To: Francois Romieu, linux-kernel; +Cc: acme, davies

On 3 October 2002 11:08, Denis Vlasenko wrote:
> On 2 October 2002 18:45, Francois Romieu wrote:
> > Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua> :
> > [...]
> >
> > > diff -u --recursive linux-2.5.38orig/drivers/net/ewrk3.c
> > > linux-2.5.38/drivers/net/ewrk3.c ---
> > > linux-2.5.38orig/drivers/net/ewrk3.c	Sun Sep 22 04:25:09 2002 +++
> > > linux-2.5.38/drivers/net/ewrk3.c	Wed Oct  2 01:29:31 2002
> >
> > [...]
> >
> > The remarks done for drivers/net/depca.c patch apply equally as
> > well.
>
> Fixes similar to depca.c applied :-)
> Testers with hardware, anyone?

It's not ->lock, it's ->hw_lock, stupid!
Denis "can't compile" Vlasenko :-(
--
vda

diff -u --recursive linux-2.5.40org/drivers/net/ewrk3.c linux-2.5.40/drivers/net/ewrk3.c
--- linux-2.5.40org/drivers/net/ewrk3.c	Tue Oct  1 05:06:58 2002
+++ linux-2.5.40/drivers/net/ewrk3.c	Thu Oct  3 12:09:46 2002
@@ -930,6 +930,7 @@
 	spin_unlock(&lp->hw_lock);
 }

+/* Called with lp->hw_lock held */
 static int ewrk3_rx(struct net_device *dev)
 {
 	struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
@@ -1055,8 +1056,9 @@
 }

 /*
-   ** Buffer sent - check for TX buffer errors.
- */
+** Buffer sent - check for TX buffer errors.
+** Called with lp->hw_lock held
+*/
 static int ewrk3_tx(struct net_device *dev)
 {
 	struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
@@ -1631,6 +1633,7 @@
 	u_long iobase = dev->base_addr;
 	int i, j, status = 0;
 	u_char csr;
+	unsigned long flags;
 	union ewrk3_addr {
 		u_char addr[HASH_TABLE_LEN * ETH_ALEN];
 		u_short val[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
@@ -1745,19 +1748,26 @@
 		}

 		break;
-	case EWRK3_GET_STATS:	/* Get the driver statistics */
-		cli();
-		ioc->len = sizeof(lp->pktStats);
-		if (copy_to_user(ioc->data, &lp->pktStats, ioc->len))
-			status = -EFAULT;
-		sti();
+	case EWRK3_GET_STATS: { /* Get the driver statistics */
+		typeof(lp->pktStats) *tmp_stats =
+        		kmalloc(sizeof(lp->pktStats), GFP_KERNEL);
+		if (!tmp_stats) return -ENOMEM;
+
+		spin_lock_irqsave(&lp->hw_lock, flags);
+		memcpy(tmp_stats, &lp->pktStats, sizeof(lp->pktStats));
+		spin_unlock_irqrestore(&lp->hw_lock, flags);

+		ioc->len = sizeof(lp->pktStats);
+		if (copy_to_user(ioc->data, tmp_stats, sizeof(lp->pktStats)))
+    			status = -EFAULT;
+		kfree(tmp_stats);
 		break;
+	}
 	case EWRK3_CLR_STATS:	/* Zero out the driver statistics */
 		if (capable(CAP_NET_ADMIN)) {
-			cli();
+			spin_lock_irqsave(&lp->hw_lock, flags);
 			memset(&lp->pktStats, 0, sizeof(lp->pktStats));
-			sti();
+			spin_unlock_irqrestore(&lp->hw_lock,flags);
 		} else {
 			status = -EPERM;
 		}

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

end of thread, other threads:[~2002-10-03  9:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-03  0:59 [PATCH] cli()/sti() fix for drivers/net/ewrk3.c Denis Vlasenko
2002-10-02 20:45 ` Francois Romieu
2002-10-03 13:08   ` Denis Vlasenko
2002-10-03 14:14     ` Denis Vlasenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®