Skip to contentSkip to conversation

tty: Flags should be accessed via the foo_bit interfaces

PATCH In review Alan Cox 4 participants 4 messages Dec 4, 2008 – Dec 5, 2008

Subsystems (3)
lore
Share & tools
lore

Alan Cox

author
#0 lore raw

PATCH 1/1 tty: Flags should be accessed via the foo_bit interfaces

From: Alan Cox <[email protected]>

We have various drivers that poke around directly and we need to clean this up before it causes problems. Fix up the networking ones - (Dave can you send this via the net tree as that seems simplest)

---

 drivers/net/irda/irtty-sir.c |    7 +++----
 drivers/net/slip.c           |   11 +++++------
 drivers/net/wan/x25_asy.c    |    8 ++++----
 drivers/net/wireless/strip.c |    8 +++-----
 4 files changed, 15 insertions(+), 19 deletions(-)
drivers/net/irda/irtty-sir.c +3 -4
index 6bcee01..d53aa95 100644
@@ -191,7 +191,7 @@ static int irtty_do_write(struct sir_dev *dev, const unsigned char *ptr, size_t
 	tty = priv->tty;
 	if (!tty->ops->write)
 		return 0;
-	tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
+	set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
 	writelen = tty_write_room(tty);
 	if (writelen > len)
 		writelen = len;
@@ -263,8 +263,7 @@ static void irtty_write_wakeup(struct tty_struct *tty)
 	IRDA_ASSERT(priv != NULL, return;);
 	IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return;);
 
-	tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
-
+	clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
 	if (priv->dev)
 		sirdev_write_complete(priv->dev);
 }
@@ -522,7 +521,7 @@ static void irtty_close(struct tty_struct *tty)
 
 	/* Stop tty */
 	irtty_stop_receiver(tty, TRUE);
-	tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
+	clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
 	if (tty->ops->stop)
 		tty->ops->stop(tty);
 
drivers/net/slip.c +5 -6
index 1d58991..951c7df 100644
@@ -402,7 +402,7 @@ static void sl_encaps(struct slip *sl, unsigned char *icp, int len)
 	 * if we did not request it before write operation.
 	 *       14 Oct 1994  Dmitry Gorodchanin.
 	 */
-	sl->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
+	set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
 	actual = sl->tty->ops->write(sl->tty, sl->xbuff, count);
 #ifdef SL_CHECK_TRANSMIT
 	sl->dev->trans_start = jiffies;
@@ -432,7 +432,7 @@ static void slip_write_wakeup(struct tty_struct *tty)
 		/* Now serial buffer is almost free & we can start
 		 * transmission of another packet */
 		sl->tx_packets++;
-		tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
+		clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
 		sl_unlock(sl);
 		return;
 	}
@@ -465,7 +465,7 @@ static void sl_tx_timeout(struct net_device *dev)
 			(tty_chars_in_buffer(sl->tty) || sl->xleft) ?
 				"bad line quality" : "driver error");
 		sl->xleft = 0;
-		sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
+		clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
 		sl_unlock(sl);
 #endif
 	}
@@ -515,10 +515,9 @@ sl_close(struct net_device *dev)
 	struct slip *sl = netdev_priv(dev);
 
 	spin_lock_bh(&sl->lock);
-	if (sl->tty) {
+	if (sl->tty)
+		clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
 		/* TTY discipline is running. */
-		sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
-	}
 	netif_stop_queue(dev);
 	sl->rcount   = 0;
 	sl->xleft    = 0;
drivers/net/wan/x25_asy.c +4 -4
index 2a6c7a6..ed0b196 100644
@@ -243,7 +243,7 @@ static void x25_asy_encaps(struct x25_asy *sl, unsigned char *icp, int len)
 	 * if we did not request it before write operation.
 	 *       14 Oct 1994  Dmitry Gorodchanin.
 	 */
-	sl->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
+	set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
 	actual = sl->tty->ops->write(sl->tty, sl->xbuff, count);
 	sl->xleft = count - actual;
 	sl->xhead = sl->xbuff + actual;
@@ -268,7 +268,7 @@ static void x25_asy_write_wakeup(struct tty_struct *tty)
 		/* Now serial buffer is almost free & we can start
 		 * transmission of another packet */
 		sl->stats.tx_packets++;
-		tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
+		clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
 		x25_asy_unlock(sl);
 		return;
 	}
@@ -291,7 +291,7 @@ static void x25_asy_timeout(struct net_device *dev)
 		       (tty_chars_in_buffer(sl->tty) || sl->xleft) ?
 		       "bad line quality" : "driver error");
 		sl->xleft = 0;
-		sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
+		clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
 		x25_asy_unlock(sl);
 	}
 	spin_unlock(&sl->lock);
@@ -504,7 +504,7 @@ static int x25_asy_close(struct net_device *dev)
 
 	spin_lock(&sl->lock);
 	if (sl->tty)
-		sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
+		clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
 
 	netif_stop_queue(dev);
 	sl->rcount = 0;
drivers/net/wireless/strip.c +3 -5
index 417e9e6..fdba397 100644
@@ -1252,7 +1252,7 @@ static void strip_write_some_more(struct tty_struct *tty)
 #endif
 	} else {		/* Else start transmission of another packet */
 
-		tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
+		clear_bit(TTY_DO_WRITE_WAKEUP, &strip_info->tty->flags);
 		strip_unlock(strip_info);
 	}
 }
@@ -1455,8 +1455,7 @@ static void strip_send(struct strip *strip_info, struct sk_buff *skb)
 	 */
 	strip_info->tx_head = strip_info->tx_buff;
 	strip_info->tx_left = ptr - strip_info->tx_buff;
-	strip_info->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
-
+	set_bit(TTY_DO_WRITE_WAKEUP, &strip_info->tty->flags);
 	/*
 	 * 4. Debugging check to make sure we're not overflowing the buffer.
 	 */
@@ -2455,8 +2454,7 @@ static int strip_close_low(struct net_device *dev)
 
 	if (strip_info->tty == NULL)
 		return -EBUSY;
-	strip_info->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
-
+	clear_bit(TTY_DO_WRITE_WAKEUP, &strip_info->tty->flags);
 	netif_stop_queue(dev);
 
 	/*
#1 lore raw
Quoted 40 lines · Alan Cox

From: Alan Cox <[email protected]>

We have various drivers that poke around directly and we need to clean this up before it causes problems. Fix up the networking ones - (Dave can you send this via the net tree as that seems simplest)

drivers/net/slip.c +3 -3
index 1d58991..951c7df 100644
@@ -402,7 +402,7 @@ static void sl_encaps(struct slip *sl, unsigned char *icp, int len)
        * if we did not request it before write operation.
        *       14 Oct 1994  Dmitry Gorodchanin.
        */
-       sl->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
+       set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
       actual = sl->tty->ops->write(sl->tty, sl->xbuff, count);
 #ifdef SL_CHECK_TRANSMIT
       sl->dev->trans_start = jiffies;
@@ -432,7 +432,7 @@ static void slip_write_wakeup(struct tty_struct *tty)
               /* Now serial buffer is almost free & we can start
                * transmission of another packet */
               sl->tx_packets++;
-               tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
+               clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
               sl_unlock(sl);
               return;
       }
@@ -465,7 +465,7 @@ static void sl_tx_timeout(struct net_device *dev)
                       (tty_chars_in_buffer(sl->tty) || sl->xleft) ?
                               "bad line quality" : "driver error");
               sl->xleft = 0;
-               sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
+               clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
               sl_unlock(sl);
 #endif
       }

drivers/net/slip.c sl_close(struct net_device *dev) · line 521

Quoted 9 lines
drivers/net/slip.c +2 -3
@@ -515,10 +515,9 @@ sl_close(struct net_device *dev)
       struct slip *sl = netdev_priv(dev);
 
       spin_lock_bh(&sl->lock);
-       if (sl->tty) {
+       if (sl->tty)
+               clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
               /* TTY discipline is running. */
-               sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
-       }

The indentation of the comment looks like it might be wrong here.

Quoted 3 lines
drivers/net/slip.c +0 -0
       netif_stop_queue(dev);
       sl->rcount   = 0;
       sl->xleft    = 0;
maintainer
#2 lore raw

From: "Will Newton" <[email protected]>
Date: Thu, 4 Dec 2008 15:50:29 +0000

Quoted 13 lines · Alan Cox

drivers/net/slip.c sl_close(struct net_device *dev) · line 521

Quoted 10 lines
drivers/net/slip.c +2 -3
@@ -515,10 +515,9 @@ sl_close(struct net_device *dev)
       struct slip *sl = netdev_priv(dev);
 
       spin_lock_bh(&sl->lock);
-       if (sl->tty) {
+       if (sl->tty)
+               clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
               /* TTY discipline is running. */
-               sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
-       }

The indentation of the comment looks like it might be wrong here.

Indeed. In fact it's now transposed with the operation it describes, and thus the braces should probably be preserved here as well.

Alan could you please fix this up?

Thanks!

#3 lore raw
In reply to Alan Cox

drivers/net/slip.c static void slip_write_wakeup(struct tty_struct *tty) · line 435

Quoted 8 lines · On Thu, 04 Dec 2008 15:41:19 +0000 Alan Cox <[email protected]> wrote:
drivers/net/slip.c +1 -1
@@ -432,7 +432,7 @@ static void slip_write_wakeup(struct tty_struct *tty)
 		/* Now serial buffer is almost free & we can start
 		 * transmission of another packet */
 		sl->tx_packets++;
-		tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
+		clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);

that's different.