Skip to contentSkip to conversation

staging: rtl8712: Make return of 0 explicit

PATCH Superseded Bhaktipriya Shridhar 2 participants 3 messages Feb 24, 2016 Staging

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8712: Make return of 0 explicit

Delete unnecessary local variable whose value is always 0 and that hides the fact that the result is always 0.

The following Coccinelle script was used:

@@
identifier ret; expression e;
type T;
@@
(
- T ret;
|
- T ret = 0;
)
...
-ret = 0;
... when != ret = e
return
- ret
+ 0
;

---
 drivers/staging/rtl8712/xmit_linux.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/staging/rtl8712/xmit_linux.c +1 -5
index adb51f0..9d6fa6b 100644
@@ -163,19 +163,15 @@ int r8712_xmit_entry(_pkt *pkt, struct  net_device *pnetdev)
 	struct xmit_frame *pxmitframe = NULL;
 	struct _adapter *padapter = netdev_priv(pnetdev);
 	struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
-	int ret = 0;
 
 	if (!r8712_if_up(padapter)) {
-		ret = 0;
 		goto _xmit_entry_drop;
 	}
 	pxmitframe = r8712_alloc_xmitframe(pxmitpriv);
 	if (!pxmitframe) {
-		ret = 0;
 		goto _xmit_entry_drop;
 	}
 	if ((!r8712_update_attrib(padapter, pkt, &pxmitframe->attrib))) {
-		ret = 0;
 		goto _xmit_entry_drop;
 	}
 	padapter->ledpriv.LedControlHandler(padapter, LED_CTL_TX);
@@ -193,5 +189,5 @@ _xmit_entry_drop:
 		r8712_free_xmitframe(pxmitpriv, pxmitframe);
 	pxmitpriv->tx_drop++;
 	dev_kfree_skb_any(pkt);
-	return ret;
+	return 0;
 }

--
2.1.4

#1 lore raw
Quoted 41 lines · Bhaktipriya Shridhar

Delete unnecessary local variable whose value is always 0 and that hides the fact that the result is always 0.

The following Coccinelle script was used:

@@
identifier ret; expression e;
type T;
@@
(
- T ret;
|
- T ret = 0;
)
...
-ret = 0;
... when != ret = e
return
- ret
+ 0
;

---
 drivers/staging/rtl8712/xmit_linux.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/staging/rtl8712/xmit_linux.c +0 -2
index adb51f0..9d6fa6b 100644
@@ -163,19 +163,15 @@ int r8712_xmit_entry(_pkt *pkt, struct  net_device *pnetdev)
 	struct xmit_frame *pxmitframe = NULL;
 	struct _adapter *padapter = netdev_priv(pnetdev);
 	struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
-	int ret = 0;
 
 	if (!r8712_if_up(padapter)) {
-		ret = 0;
 		goto _xmit_entry_drop;
 	}

drivers/staging/rtl8712/xmit_linux.c int r8712_xmit_entry(_pkt *pkt, struct net_device *pnetdev) · line 177

Quoted 10 lines
drivers/staging/rtl8712/xmit_linux.c +0 -2
 	pxmitframe = r8712_alloc_xmitframe(pxmitpriv);
 	if (!pxmitframe) {
-		ret = 0;
 		goto _xmit_entry_drop;
 	}
 	if ((!r8712_update_attrib(padapter, pkt, &pxmitframe->attrib))) {
-		ret = 0;
 		goto _xmit_entry_drop;
 	}
 	padapter->ledpriv.LedControlHandler(padapter, LED_CTL_TX);

There is still a return ret here, so this code should not have compiled.

I'm not sure why the semantic patch didn't do the right thing.

julia

Quoted 17 lines
drivers/staging/rtl8712/xmit_linux.c +1 -2
@@ -193,5 +189,5 @@ _xmit_entry_drop:
 		r8712_free_xmitframe(pxmitpriv, pxmitframe);
 	pxmitpriv->tx_drop++;
 	dev_kfree_skb_any(pkt);
-	return ret;
+	return 0;
 }
--

2.1.4

Signature · 5 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/20160224205043.GA23454%40Karyakshetra.
For more options, visit https://groups.google.com/d/optout.
#2 lore raw

Hello Julia,

Thank you for the prompt reply. I have been trying hard to get this semantic patch to work. I'm unable to understand why it's replacing only the final occurrence of "return ret" to "return 0". Can you please guide me.

Thanks,
Bhaktipriya

Quoted 77 lines · Julia Lawall
Quoted 41 lines · Bhaktipriya Shridhar

Delete unnecessary local variable whose value is always 0 and that hides the fact that the result is always 0.

The following Coccinelle script was used:

@@
identifier ret; expression e;
type T;
@@
(
- T ret;
|
- T ret = 0;
)
...
-ret = 0;
... when != ret = e
return
- ret
+ 0
;

---
 drivers/staging/rtl8712/xmit_linux.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/staging/rtl8712/xmit_linux.c +0 -2
index adb51f0..9d6fa6b 100644
@@ -163,19 +163,15 @@ int r8712_xmit_entry(_pkt *pkt, struct  net_device *pnetdev)
      struct xmit_frame *pxmitframe = NULL;
      struct _adapter *padapter = netdev_priv(pnetdev);
      struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
-     int ret = 0;
 
      if (!r8712_if_up(padapter)) {
-             ret = 0;
              goto _xmit_entry_drop;
      }

drivers/staging/rtl8712/xmit_linux.c int r8712_xmit_entry(_pkt *pkt, struct net_device *pnetdev) · line 177

Quoted 10 lines
drivers/staging/rtl8712/xmit_linux.c +0 -2
      pxmitframe = r8712_alloc_xmitframe(pxmitpriv);
      if (!pxmitframe) {
-             ret = 0;
              goto _xmit_entry_drop;
      }
      if ((!r8712_update_attrib(padapter, pkt, &pxmitframe->attrib))) {
-             ret = 0;
              goto _xmit_entry_drop;
      }
      padapter->ledpriv.LedControlHandler(padapter, LED_CTL_TX);

There is still a return ret here, so this code should not have compiled.

I'm not sure why the semantic patch didn't do the right thing.

julia

Quoted 17 lines
drivers/staging/rtl8712/xmit_linux.c +1 -2
@@ -193,5 +189,5 @@ _xmit_entry_drop:
              r8712_free_xmitframe(pxmitpriv, pxmitframe);
      pxmitpriv->tx_drop++;
      dev_kfree_skb_any(pkt);
-     return ret;
+     return 0;
 }
--

2.1.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/20160224205043.GA23454%40Karyakshetra.
For more options, visit https://groups.google.com/d/optout.