Skip to contentSkip to conversation

gigaset: turn nonsense checks into WARN_ON

PATCH In review Alan Cox 2 participants 2 messages Dec 9, 2015 – Dec 12, 2015

lore
Share & tools
lore

Alan Cox

author
#0 lore raw

PATCH 1/1 gigaset: turn nonsense checks into WARN_ON

These checks do nothing useful to protect the code from races. On the other hand if the old code has been masking a real bug we would like to know about it.

The check for tiocmset is kept because it is valid for a tty driver to have a NULL tiocmset method. That in itself is probably a mistake given modern coding practices - but needs fixing in the tty layer.

---
 drivers/isdn/gigaset/ser-gigaset.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/isdn/gigaset/ser-gigaset.c +5 -5
index d8771b5..8e21f6af 100644
@@ -67,8 +67,7 @@ static int write_modem(struct cardstate *cs)
 	struct sk_buff *skb = bcs->tx_skb;
 	int sent = -EOPNOTSUPP;
 
-	if (!tty || !tty->ops || !skb)
-		return -EINVAL;
+	WARN_ON(!tty || !tty->ops || !skb);
 
 	if (!skb->len) {
 		dev_kfree_skb_any(skb);
@@ -109,8 +108,7 @@ static int send_cb(struct cardstate *cs)
 	unsigned long flags;
 	int sent = 0;
 
-	if (!tty || !tty->ops)
-		return -EFAULT;
+	WARN_ON(!tty || !tty->ops);
 
 	cb = cs->cmdbuf;
 	if (!cb)
@@ -432,7 +430,9 @@ static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
 	struct tty_struct *tty = cs->hw.ser->tty;
 	unsigned int set, clear;
 
-	if (!tty || !tty->ops || !tty->ops->tiocmset)
+	WARN_ON(!tty || !tty->ops);
+	/* tiocmset is an optional tty driver method */
+	if (!tty->ops->tiocmset)
 		return -EINVAL;
 	set = new_state & ~old_state;
 	clear = old_state & ~new_state;
Acked-by on v1 1/1
#1 lore raw

Am 09.12.2015 um 21:33 schrieb Alan Cox:

Quoted 9 lines

These checks do nothing useful to protect the code from races. On the other hand if the old code has been masking a real bug we would like to know about it.

The check for tiocmset is kept because it is valid for a tty driver to have a NULL tiocmset method. That in itself is probably a mistake given modern coding practices - but needs fixing in the tty layer.

(Overlooking the nettling subject line.)

Quoted 40 lines
---
 drivers/isdn/gigaset/ser-gigaset.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/isdn/gigaset/ser-gigaset.c +5 -5
index d8771b5..8e21f6af 100644
@@ -67,8 +67,7 @@ static int write_modem(struct cardstate *cs)
 	struct sk_buff *skb = bcs->tx_skb;
 	int sent = -EOPNOTSUPP;
 
-	if (!tty || !tty->ops || !skb)
-		return -EINVAL;
+	WARN_ON(!tty || !tty->ops || !skb);
 
 	if (!skb->len) {
 		dev_kfree_skb_any(skb);
@@ -109,8 +108,7 @@ static int send_cb(struct cardstate *cs)
 	unsigned long flags;
 	int sent = 0;
 
-	if (!tty || !tty->ops)
-		return -EFAULT;
+	WARN_ON(!tty || !tty->ops);
 
 	cb = cs->cmdbuf;
 	if (!cb)
@@ -432,7 +430,9 @@ static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
 	struct tty_struct *tty = cs->hw.ser->tty;
 	unsigned int set, clear;
 
-	if (!tty || !tty->ops || !tty->ops->tiocmset)
+	WARN_ON(!tty || !tty->ops);
+	/* tiocmset is an optional tty driver method */
+	if (!tty->ops->tiocmset)
 		return -EINVAL;
 	set = new_state & ~old_state;
 	clear = old_state & ~new_state;
Signature · 3 lines
Tilman Schmidt                              E-Mail: [email protected]
Bonn, Germany
Nous, on a des fleurs et des bougies pour nous protéger.