Skip to contentSkip to conversation

Staging: i4l: No assignment in if statements

PATCH In review Mihaela Muraru 2 participants 2 messages Oct 15, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Staging: i4l: No assignment in if statements

Move the assignment before the statement 'if'.
Found with Coccinelle:
@r1@
identifier ptr;
expression fn;
statement S;
constant c;
@@

+ptr=fn;
if (
- (ptr=fn)
+ ptr

	< c) S

---
Changes in v2:
- rewrite the semantic patch;

---
 drivers/staging/i4l/pcbit/callbacks.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/staging/i4l/pcbit/callbacks.c +18 -10
index efb6d6a..6d8d02d 100644
@@ -56,8 +56,8 @@ void cb_out_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	 *     - kfree   when msg has been sent
 	 */
 
-	if ((len = capi_conn_req(cbdata->data.setup.CalledPN, &skb,
-				 chan->proto)) < 0)
+	len = capi_conn_req(cbdata->data.setup.CalledPN, &skb, chan->proto);
+	if (len < 0)
 	{
 		printk("capi_conn_req failed\n");
 		return;
@@ -89,7 +89,8 @@ void cb_out_2(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	int len;
 	ushort refnum;
 
-	if ((len = capi_conn_active_resp(chan, &skb)) < 0)
+	len = capi_conn_active_resp(chan, &skb);
+	if (len < 0)
 	{
 		printk("capi_conn_active_req failed\n");
 		return;
@@ -110,7 +111,8 @@ void cb_out_2(struct pcbit_dev *dev, struct pcbit_chan *chan,
 
 	/* Select protocol  */
 
-	if ((len = capi_select_proto_req(chan, &skb, 1 /*outgoing*/)) < 0) {
+	len = capi_select_proto_req(chan, &skb, 1);
+	if (len /*outgoing*/< 0) {
 		printk("capi_select_proto_req failed\n");
 		return;
 	}
@@ -170,7 +172,8 @@ void cb_in_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	dev->dev_if->statcallb(&ictl);
 
 
-	if ((len = capi_conn_resp(chan, &skb)) < 0) {
+	len = capi_conn_resp(chan, &skb);
+	if (len < 0) {
 		printk(KERN_DEBUG "capi_conn_resp failed\n");
 		return;
 	}
@@ -194,7 +197,8 @@ void cb_in_2(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	struct sk_buff *skb;
 	int len;
 
-	if ((len = capi_conn_active_req(chan, &skb)) < 0) {
+	len = capi_conn_active_req(chan, &skb);
+	if (len < 0) {
 		printk(KERN_DEBUG "capi_conn_active_req failed\n");
 		return;
 	}
@@ -220,7 +224,8 @@ void cb_in_3(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	struct sk_buff *skb;
 	int len;
 
-	if ((len = capi_select_proto_req(chan, &skb, 0 /*incoming*/)) < 0)
+	len = capi_select_proto_req(chan, &skb, 0);
+	if (len /*incoming*/< 0)
 	{
 		printk("capi_select_proto_req failed\n");
 		return;
@@ -247,7 +252,8 @@ void cb_disc_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	ushort refnum;
 	isdn_ctrl ictl;
 
-	if ((len = capi_disc_resp(chan, &skb)) < 0) {
+	len = capi_disc_resp(chan, &skb);
+	if (len < 0) {
 		printk("capi_disc_resp failed\n");
 		return;
 	}
@@ -275,7 +281,8 @@ void cb_disc_2(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	int len;
 	ushort refnum;
 
-	if ((len = capi_disc_req(chan->callref, &skb, CAUSE_NORMAL)) < 0)
+	len = capi_disc_req(chan->callref, &skb, CAUSE_NORMAL);
+	if (len < 0)
 	{
 		printk("capi_disc_req failed\n");
 		return;
@@ -318,7 +325,8 @@ void cb_selp_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	int len;
 	ushort refnum;
 
-	if ((len = capi_activate_transp_req(chan, &skb)) < 0)
+	len = capi_activate_transp_req(chan, &skb);
+	if (len < 0)
 	{
 		printk("capi_conn_activate_transp_req failed\n");
 		return;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 28 lines · Mihaela Muraru

Move the assignment before the statement 'if'.
Found with Coccinelle:
@r1@
identifier ptr;
expression fn;
statement S;
constant c;
@@

(quoted diff) +2 -1
+ptr=fn;
 if (
-	(ptr=fn)
+	ptr
	< c) S

---
Changes in v2:
- rewrite the semantic patch;

---
 drivers/staging/i4l/pcbit/callbacks.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/staging/i4l/pcbit/callbacks.c +0 -0
index efb6d6a..6d8d02d 100644

drivers/staging/i4l/pcbit/callbacks.c void cb_out_1(struct pcbit_dev *dev, struct pcbit_chan *chan, · line 61

Quoted 8 lines
drivers/staging/i4l/pcbit/callbacks.c +2 -2
@@ -56,8 +56,8 @@ void cb_out_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	 *     - kfree   when msg has been sent
 	 */
 
-	if ((len = capi_conn_req(cbdata->data.setup.CalledPN, &skb,
-				 chan->proto)) < 0)
+	len = capi_conn_req(cbdata->data.setup.CalledPN, &skb, chan->proto);
+	if (len < 0)
 	{

Perhaps you could push this { up to the previous line at the same time.

Quoted 13 lines
drivers/staging/i4l/pcbit/callbacks.c +2 -1
 		printk("capi_conn_req failed\n");
 		return;
@@ -89,7 +89,8 @@ void cb_out_2(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	int len;
 	ushort refnum;
 
-	if ((len = capi_conn_active_resp(chan, &skb)) < 0)
+	len = capi_conn_active_resp(chan, &skb);
+	if (len < 0)
 	{
 		printk("capi_conn_active_req failed\n");
 		return;

drivers/staging/i4l/pcbit/callbacks.c void cb_out_2(struct pcbit_dev *dev, struct pcbit_chan *chan, · line 115

Quoted 6 lines
drivers/staging/i4l/pcbit/callbacks.c +2 -1
@@ -110,7 +111,8 @@ void cb_out_2(struct pcbit_dev *dev, struct pcbit_chan *chan,
 
 	/* Select protocol  */
 
-	if ((len = capi_select_proto_req(chan, &skb, 1 /*outgoing*/)) < 0) {
+	len = capi_select_proto_req(chan, &skb, 1);
+	if (len /*outgoing*/< 0) {

The outgoing comment really seems to be attached to the argument 1 in the function call.

Quoted 24 lines
drivers/staging/i4l/pcbit/callbacks.c +4 -2
 		printk("capi_select_proto_req failed\n");
 		return;
 	}
@@ -170,7 +172,8 @@ void cb_in_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	dev->dev_if->statcallb(&ictl);
 
 
-	if ((len = capi_conn_resp(chan, &skb)) < 0) {
+	len = capi_conn_resp(chan, &skb);
+	if (len < 0) {
 		printk(KERN_DEBUG "capi_conn_resp failed\n");
 		return;
 	}
@@ -194,7 +197,8 @@ void cb_in_2(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	struct sk_buff *skb;
 	int len;
 
-	if ((len = capi_conn_active_req(chan, &skb)) < 0) {
+	len = capi_conn_active_req(chan, &skb);
+	if (len < 0) {
 		printk(KERN_DEBUG "capi_conn_active_req failed\n");
 		return;
 	}

drivers/staging/i4l/pcbit/callbacks.c void cb_in_3(struct pcbit_dev *dev, struct pcbit_chan *chan, · line 228

Quoted 6 lines
drivers/staging/i4l/pcbit/callbacks.c +2 -1
@@ -220,7 +224,8 @@ void cb_in_3(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	struct sk_buff *skb;
 	int len;
 
-	if ((len = capi_select_proto_req(chan, &skb, 0 /*incoming*/)) < 0)
+	len = capi_select_proto_req(chan, &skb, 0);
+	if (len /*incoming*/< 0)

Likewise here the incoming seems to be attached to the 0 argument.

It's a separate issue, but it really looks like this argument should be a boolean, or an enum that would eliminate the need for the comment.

julia

Quoted 43 lines
drivers/staging/i4l/pcbit/callbacks.c +6 -4
 	{
 		printk("capi_select_proto_req failed\n");
 		return;
@@ -247,7 +252,8 @@ void cb_disc_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	ushort refnum;
 	isdn_ctrl ictl;
 
-	if ((len = capi_disc_resp(chan, &skb)) < 0) {
+	len = capi_disc_resp(chan, &skb);
+	if (len < 0) {
 		printk("capi_disc_resp failed\n");
 		return;
 	}
@@ -275,7 +281,8 @@ void cb_disc_2(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	int len;
 	ushort refnum;
 
-	if ((len = capi_disc_req(chan->callref, &skb, CAUSE_NORMAL)) < 0)
+	len = capi_disc_req(chan->callref, &skb, CAUSE_NORMAL);
+	if (len < 0)
 	{
 		printk("capi_disc_req failed\n");
 		return;
@@ -318,7 +325,8 @@ void cb_selp_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
 	int len;
 	ushort refnum;
 
-	if ((len = capi_activate_transp_req(chan, &skb)) < 0)
+	len = capi_activate_transp_req(chan, &skb);
+	if (len < 0)
 	{
 		printk("capi_conn_activate_transp_req failed\n");
 		return;
--

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/20161015132041.GA20307%40domino-MS-16Y1.
For more options, visit https://groups.google.com/d/optout.