Skip to contentSkip to conversation

Staging: irda: Don't use assignment inside if statement

PATCH In review Srishti Sharma 2 participants 5 messages Sep 15, 2017

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

PATCH v2 1/1 Staging: irda: Don't use assignment inside if statement

Write assignment statement outside the if statement. Done using the following semantic patch by coccinelle.

@@
identifier E;
expression F;
statement S;
@@

-if((E = F))
+E = F;
+if(E)
S

---
Changes in v2:
-Semicolon was missing in one of the statements of the
semantic patch

 drivers/staging/irda/drivers/irda-usb.c | 4 ++--
 drivers/staging/irda/drivers/mcs7780.c  | 9 ++++++---
 drivers/staging/irda/net/irqueue.c      | 3 ++-
 3 files changed, 10 insertions(+), 6 deletions(-)
drivers/staging/irda/drivers/irda-usb.c +2 -2
index 723e49b..82bfc05 100644
@@ -334,9 +334,9 @@ static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self)
 	urb->transfer_flags = 0;
 
 	/* Irq disabled -> GFP_ATOMIC */
-	if ((ret = usb_submit_urb(urb, GFP_ATOMIC))) {
+	ret = usb_submit_urb(urb, GFP_ATOMIC);
+	if (ret)
 		net_warn_ratelimited("%s(), failed Speed URB\n", __func__);
-	}
 }
 
 /*------------------------------------------------------------------*/
drivers/staging/irda/drivers/mcs7780.c +6 -3
index c3f0b25..2b674d5 100644
@@ -605,19 +605,22 @@ static int mcs_speed_change(struct mcs_cb *mcs)
 	if (mcs->new_speed <= 115200) {
 		rval &= ~MCS_FIR;
 
-		if ((rst = (mcs->speed > 115200)))
+		rst = (mcs->speed > 115200);
+		if (rst)
 			mcs_set_reg(mcs, MCS_MINRXPW_REG, 0);
 
 	} else if (mcs->new_speed <= 1152000) {
 		rval &= ~MCS_FIR;
 
-		if ((rst = !(mcs->speed == 576000 || mcs->speed == 1152000)))
+		rst = !(mcs->speed == 576000 || mcs->speed == 1152000);
+		if (rst)
 			mcs_set_reg(mcs, MCS_MINRXPW_REG, 5);
 
 	} else {
 		rval |= MCS_FIR;
 
-		if ((rst = (mcs->speed != 4000000)))
+		rst = (mcs->speed != 4000000);
+		if (rst)
 			mcs_set_reg(mcs, MCS_MINRXPW_REG, 5);
 
 	}
drivers/staging/irda/net/irqueue.c +2 -1
index 160dc89..5aab072 100644
@@ -217,7 +217,8 @@ static __u32 hash( const char* name)
 
 	while(*name) {
 		h = (h<<4) + *name++;
-		if ((g = (h & 0xf0000000)))
+		g = (h & 0xf0000000);
+		if (g)
 			h ^=g>>24;
 		h &=~g;
 	}
Signature · 1 line
2.7.4
Acked-by on v2 1/1
#1 lore raw
Quoted 14 lines · Srishti Sharma

Write assignment statement outside the if statement. Done using the following semantic patch by coccinelle.

@@
identifier E;
expression F;
statement S;
@@

(quoted diff) +2 -1
-if((E = F))
+E = F;
+if(E)
  S
Quoted 1 line
Quoted 80 lines

---
Changes in v2:
-Semicolon was missing in one of the statements of the
semantic patch

 drivers/staging/irda/drivers/irda-usb.c | 4 ++--
 drivers/staging/irda/drivers/mcs7780.c  | 9 ++++++---
 drivers/staging/irda/net/irqueue.c      | 3 ++-
 3 files changed, 10 insertions(+), 6 deletions(-)
drivers/staging/irda/drivers/irda-usb.c +2 -2
index 723e49b..82bfc05 100644
@@ -334,9 +334,9 @@ static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self)
 	urb->transfer_flags = 0;
 
 	/* Irq disabled -> GFP_ATOMIC */
-	if ((ret = usb_submit_urb(urb, GFP_ATOMIC))) {
+	ret = usb_submit_urb(urb, GFP_ATOMIC);
+	if (ret)
 		net_warn_ratelimited("%s(), failed Speed URB\n", __func__);
-	}
 }
 
 /*------------------------------------------------------------------*/
drivers/staging/irda/drivers/mcs7780.c +6 -3
index c3f0b25..2b674d5 100644
@@ -605,19 +605,22 @@ static int mcs_speed_change(struct mcs_cb *mcs)
 	if (mcs->new_speed <= 115200) {
 		rval &= ~MCS_FIR;
 
-		if ((rst = (mcs->speed > 115200)))
+		rst = (mcs->speed > 115200);
+		if (rst)
 			mcs_set_reg(mcs, MCS_MINRXPW_REG, 0);
 
 	} else if (mcs->new_speed <= 1152000) {
 		rval &= ~MCS_FIR;
 
-		if ((rst = !(mcs->speed == 576000 || mcs->speed == 1152000)))
+		rst = !(mcs->speed == 576000 || mcs->speed == 1152000);
+		if (rst)
 			mcs_set_reg(mcs, MCS_MINRXPW_REG, 5);
 
 	} else {
 		rval |= MCS_FIR;
 
-		if ((rst = (mcs->speed != 4000000)))
+		rst = (mcs->speed != 4000000);
+		if (rst)
 			mcs_set_reg(mcs, MCS_MINRXPW_REG, 5);
 
 	}
drivers/staging/irda/net/irqueue.c +2 -2
index 160dc89..5aab072 100644
@@ -217,7 +217,8 @@ static __u32 hash( const char* name)
 
 	while(*name) {
 		h = (h<<4) + *name++;
-		if ((g = (h & 0xf0000000)))
+		g = (h & 0xf0000000);
+		if (g)
 			h ^=g>>24;
 		h &=~g;
 	}
--

2.7.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1505504680-22167-1-git-send-email-srishtishar%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#2 lore raw
Quoted 13 lines · Julia Lawall
Quoted 9 lines · Srishti Sharma

Write assignment statement outside the if statement. Done using the following semantic patch by coccinelle.

@@
identifier E;
expression F;
statement S;
@@

Quoted 8 lines
Quoted 6 lines
(quoted diff) +2 -1
-if((E = F))
+E = F;
+if(E)
  S

Have sent a patchset for this instead .

Regards,
Srishti

Quoted 81 lines
Quoted 81 lines

---
Changes in v2:
-Semicolon was missing in one of the statements of the
semantic patch

 drivers/staging/irda/drivers/irda-usb.c | 4 ++--
 drivers/staging/irda/drivers/mcs7780.c  | 9 ++++++---
 drivers/staging/irda/net/irqueue.c      | 3 ++-
 3 files changed, 10 insertions(+), 6 deletions(-)
drivers/staging/irda/drivers/irda-usb.c +2 -2
index 723e49b..82bfc05 100644
@@ -334,9 +334,9 @@ static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self)
      urb->transfer_flags = 0;
 
      /* Irq disabled -> GFP_ATOMIC */
-     if ((ret = usb_submit_urb(urb, GFP_ATOMIC))) {
+     ret = usb_submit_urb(urb, GFP_ATOMIC);
+     if (ret)
              net_warn_ratelimited("%s(), failed Speed URB\n", __func__);
-     }
 }
 
 /*------------------------------------------------------------------*/
drivers/staging/irda/drivers/mcs7780.c +6 -3
index c3f0b25..2b674d5 100644
@@ -605,19 +605,22 @@ static int mcs_speed_change(struct mcs_cb *mcs)
      if (mcs->new_speed <= 115200) {
              rval &= ~MCS_FIR;
 
-             if ((rst = (mcs->speed > 115200)))
+             rst = (mcs->speed > 115200);
+             if (rst)
                      mcs_set_reg(mcs, MCS_MINRXPW_REG, 0);
 
      } else if (mcs->new_speed <= 1152000) {
              rval &= ~MCS_FIR;
 
-             if ((rst = !(mcs->speed == 576000 || mcs->speed == 1152000)))
+             rst = !(mcs->speed == 576000 || mcs->speed == 1152000);
+             if (rst)
                      mcs_set_reg(mcs, MCS_MINRXPW_REG, 5);
 
      } else {
              rval |= MCS_FIR;
 
-             if ((rst = (mcs->speed != 4000000)))
+             rst = (mcs->speed != 4000000);
+             if (rst)
                      mcs_set_reg(mcs, MCS_MINRXPW_REG, 5);
 
      }
drivers/staging/irda/net/irqueue.c +2 -2
index 160dc89..5aab072 100644
@@ -217,7 +217,8 @@ static __u32 hash( const char* name)
 
      while(*name) {
              h = (h<<4) + *name++;
-             if ((g = (h & 0xf0000000)))
+             g = (h & 0xf0000000);
+             if (g)
                      h ^=g>>24;
              h &=~g;
      }
--

2.7.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1505504680-22167-1-git-send-email-srishtishar%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#3 lore raw
Quoted 19 lines · Srishti Sharma
Quoted 18 lines · Julia Lawall
Quoted 14 lines · Srishti Sharma

Write assignment statement outside the if statement. Done using the following semantic patch by coccinelle.

@@
identifier E;
expression F;
statement S;
@@

(quoted diff) +2 -1
-if((E = F))
+E = F;
+if(E)
  S
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Have sent a patchset for this instead .

Thanks. Actually, you should have copied the ack.

julia

Quoted 92 lines

Regards,
Srishti

Quoted 74 lines
Quoted 74 lines

---
Changes in v2:
-Semicolon was missing in one of the statements of the
semantic patch

 drivers/staging/irda/drivers/irda-usb.c | 4 ++--
 drivers/staging/irda/drivers/mcs7780.c  | 9 ++++++---
 drivers/staging/irda/net/irqueue.c      | 3 ++-
 3 files changed, 10 insertions(+), 6 deletions(-)
drivers/staging/irda/drivers/irda-usb.c +2 -2
index 723e49b..82bfc05 100644
@@ -334,9 +334,9 @@ static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self)
      urb->transfer_flags = 0;
 
      /* Irq disabled -> GFP_ATOMIC */
-     if ((ret = usb_submit_urb(urb, GFP_ATOMIC))) {
+     ret = usb_submit_urb(urb, GFP_ATOMIC);
+     if (ret)
              net_warn_ratelimited("%s(), failed Speed URB\n", __func__);
-     }
 }
 
 /*------------------------------------------------------------------*/
drivers/staging/irda/drivers/mcs7780.c +6 -3
index c3f0b25..2b674d5 100644
@@ -605,19 +605,22 @@ static int mcs_speed_change(struct mcs_cb *mcs)
      if (mcs->new_speed <= 115200) {
              rval &= ~MCS_FIR;
 
-             if ((rst = (mcs->speed > 115200)))
+             rst = (mcs->speed > 115200);
+             if (rst)
                      mcs_set_reg(mcs, MCS_MINRXPW_REG, 0);
 
      } else if (mcs->new_speed <= 1152000) {
              rval &= ~MCS_FIR;
 
-             if ((rst = !(mcs->speed == 576000 || mcs->speed == 1152000)))
+             rst = !(mcs->speed == 576000 || mcs->speed == 1152000);
+             if (rst)
                      mcs_set_reg(mcs, MCS_MINRXPW_REG, 5);
 
      } else {
              rval |= MCS_FIR;
 
-             if ((rst = (mcs->speed != 4000000)))
+             rst = (mcs->speed != 4000000);
+             if (rst)
                      mcs_set_reg(mcs, MCS_MINRXPW_REG, 5);
 
      }
drivers/staging/irda/net/irqueue.c +2 -2
index 160dc89..5aab072 100644
@@ -217,7 +217,8 @@ static __u32 hash( const char* name)
 
      while(*name) {
              h = (h<<4) + *name++;
-             if ((g = (h & 0xf0000000)))
+             g = (h & 0xf0000000);
+             if (g)
                      h ^=g>>24;
              h &=~g;
      }
--

2.7.4

Quoted 7 lines
Quoted 7 lines

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1505504680-22167-1-git-send-email-srishtishar%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CAB3L5oxr5K5aMo06ROCVV9ejY6a_g1%2BuUkjU%3DZ5bKTJtzUs7sA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

#4 lore raw
Quoted 23 lines · Julia Lawall
Quoted 19 lines · Srishti Sharma
Quoted 18 lines · Julia Lawall
Quoted 14 lines · Srishti Sharma

Write assignment statement outside the if statement. Done using the following semantic patch by coccinelle.

@@
identifier E;
expression F;
statement S;
@@

(quoted diff) +2 -1
-if((E = F))
+E = F;
+if(E)
  S
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Have sent a patchset for this instead .

Thanks. Actually, you should have copied the ack.

Oh.. Sorry didn't realise I could do that :)

Regards,
Srishti

Quoted 95 lines

julia

Quoted 92 lines

Regards,
Srishti

Quoted 74 lines
Quoted 74 lines

---
Changes in v2:
-Semicolon was missing in one of the statements of the
semantic patch

 drivers/staging/irda/drivers/irda-usb.c | 4 ++--
 drivers/staging/irda/drivers/mcs7780.c  | 9 ++++++---
 drivers/staging/irda/net/irqueue.c      | 3 ++-
 3 files changed, 10 insertions(+), 6 deletions(-)
drivers/staging/irda/drivers/irda-usb.c +2 -2
index 723e49b..82bfc05 100644
@@ -334,9 +334,9 @@ static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self)
      urb->transfer_flags = 0;
 
      /* Irq disabled -> GFP_ATOMIC */
-     if ((ret = usb_submit_urb(urb, GFP_ATOMIC))) {
+     ret = usb_submit_urb(urb, GFP_ATOMIC);
+     if (ret)
              net_warn_ratelimited("%s(), failed Speed URB\n", __func__);
-     }
 }
 
 /*------------------------------------------------------------------*/
drivers/staging/irda/drivers/mcs7780.c +6 -3
index c3f0b25..2b674d5 100644
@@ -605,19 +605,22 @@ static int mcs_speed_change(struct mcs_cb *mcs)
      if (mcs->new_speed <= 115200) {
              rval &= ~MCS_FIR;
 
-             if ((rst = (mcs->speed > 115200)))
+             rst = (mcs->speed > 115200);
+             if (rst)
                      mcs_set_reg(mcs, MCS_MINRXPW_REG, 0);
 
      } else if (mcs->new_speed <= 1152000) {
              rval &= ~MCS_FIR;
 
-             if ((rst = !(mcs->speed == 576000 || mcs->speed == 1152000)))
+             rst = !(mcs->speed == 576000 || mcs->speed == 1152000);
+             if (rst)
                      mcs_set_reg(mcs, MCS_MINRXPW_REG, 5);
 
      } else {
              rval |= MCS_FIR;
 
-             if ((rst = (mcs->speed != 4000000)))
+             rst = (mcs->speed != 4000000);
+             if (rst)
                      mcs_set_reg(mcs, MCS_MINRXPW_REG, 5);
 
      }
drivers/staging/irda/net/irqueue.c +2 -2
index 160dc89..5aab072 100644
@@ -217,7 +217,8 @@ static __u32 hash( const char* name)
 
      while(*name) {
              h = (h<<4) + *name++;
-             if ((g = (h & 0xf0000000)))
+             g = (h & 0xf0000000);
+             if (g)
                      h ^=g>>24;
              h &=~g;
      }
--

2.7.4

Quoted 7 lines
Quoted 7 lines

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1505504680-22167-1-git-send-email-srishtishar%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CAB3L5oxr5K5aMo06ROCVV9ejY6a_g1%2BuUkjU%3DZ5bKTJtzUs7sA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.