Skip to contentSkip to conversation

staging: Remove useless intialisation

PATCH In review Amitoj Kaur Chawla 2 participants 8 messages Oct 14, 2015 – Oct 15, 2015 Staging

lore
Share & tools
lore
#0 lore raw

cover staging: Remove useless intialisation

This patchset removes multiple useless intialisations of variables which are immediately reassigned.

The semantic patch used to find this is:

// <smpl>
@@
type T;
identifier x;
constant C;
expression e;
@@

T x
- = C
;
x = e;
// </smpl>

Amitoj Kaur Chawla (5):
staging: unisys: Remove useless intialisation
staging: speakup: speakup_audptr: Remove useless intialisation
staging: speakup: varhandlers: Remove useless intialisation
staging: rtl8712: rtl8712_recv: Remove useless intialisation
staging: rtl8712: rtl871x_mp: Remove useless initialisation

 drivers/staging/rtl8712/rtl8712_recv.c         | 2 +-
 drivers/staging/rtl8712/rtl871x_mp.c           | 6 +++---
 drivers/staging/speakup/speakup_audptr.c       | 2 +-
 drivers/staging/speakup/varhandlers.c          | 2 +-
 drivers/staging/unisys/visorinput/visorinput.c | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/5 staging: unisys: Remove useless intialisation

Remove intialisation of a variable that is immediately reassigned.

The semantic patch used to find this is:

// <smpl>
@@
type T;
identifier x;
constant C;
expression e;
@@

T x
- = C
;
x = e;
// </smpl>

---
 drivers/staging/unisys/visorinput/visorinput.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/unisys/visorinput/visorinput.c +1 -1
index 3a1b24f..6e42d59 100644
@@ -264,7 +264,7 @@ register_client_keyboard(void *devdata,  /* opaque on purpose */
 
 {
 	int i, error;
-	struct input_dev *visorinput_dev = NULL;
+	struct input_dev *visorinput_dev;
 
 	visorinput_dev = input_allocate_device();
 	if (!visorinput_dev)
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/5 staging: speakup: speakup_audptr: Remove useless intialisation

In reply to Amitoj Kaur Chawla

Remove intialisation of a variable that is immediately reassigned.

The semantic patch used to find this is:

// <smpl>
@@
type T;
identifier x;
constant C;
expression e;
@@

T x
- = C
;
x = e;
// </smpl>

---
 drivers/staging/speakup/speakup_audptr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/speakup/speakup_audptr.c +1 -1
index ea89e36..a9a6872 100644
@@ -162,7 +162,7 @@ static void synth_version(struct spk_synth *synth)
 
 static int synth_probe(struct spk_synth *synth)
 {
-	int failed = 0;
+	int failed;
 
 	failed = spk_serial_synth_probe(synth);
 	if (failed == 0)
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/5 staging: speakup: varhandlers: Remove useless intialisation

In reply to Amitoj Kaur Chawla

Remove intialisation of a variable that is immediately reassigned.

The semantic patch used to find this is:

// <smpl>
@@
type T;
identifier x;
constant C;
expression e;
@@

T x
- = C
;
x = e;
// </smpl>

---
 drivers/staging/speakup/varhandlers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/speakup/varhandlers.c +1 -1
index b2afec6..ab4fe8d 100644
@@ -323,7 +323,7 @@ char *spk_strlwr(char *s)
 
 char *spk_s2uchar(char *start, char *dest)
 {
-	int val = 0;
+	int val;
 
 	val = simple_strtoul(skip_spaces(start), &start, 10);
 	if (*start == ',')
Signature · 1 line
1.9.1
#4 lore raw

PATCH 4/5 staging: rtl8712: rtl8712_recv: Remove useless intialisation

In reply to Amitoj Kaur Chawla

Remove intialisation of a variable that is immediately reassigned.

The semantic patch used to find this is:

// <smpl>
@@
type T;
identifier x;
constant C;
expression e;
@@

T x
- = C
;
x = e;
// </smpl>

---
 drivers/staging/rtl8712/rtl8712_recv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8712/rtl8712_recv.c +1 -1
index fae06d9..fd2b7e8 100644
@@ -158,7 +158,7 @@ int r8712_free_recvframe(union recv_frame *precvframe,
 static void update_recvframe_attrib_from_recvstat(struct rx_pkt_attrib *pattrib,
 					   struct recv_stat *prxstat)
 {
-	u16 drvinfo_sz = 0;
+	u16 drvinfo_sz;
 
 	drvinfo_sz = (le32_to_cpu(prxstat->rxdw0)&0x000f0000)>>16;
 	drvinfo_sz <<= 3;
Signature · 1 line
1.9.1
#5 lore raw

PATCH 5/5 staging: rtl8712: rtl871x_mp: Remove useless initialisation

In reply to Amitoj Kaur Chawla

Remove intialisation of a variable that is immediately reassigned.

The semantic patch used to find this is:

// <smpl>
@@
type T;
identifier x;
constant C;
expression e;
@@

T x
- = C
;
x = e;
// </smpl>

---
 drivers/staging/rtl8712/rtl871x_mp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8712/rtl871x_mp.c +3 -3
index 26201ea..00b80f7 100644
@@ -295,7 +295,7 @@ void r8712_SetChannel(struct _adapter *pAdapter)
 
 static void SetCCKTxPower(struct _adapter *pAdapter, u8 TxPower)
 {
-	u16 TxAGC = 0;
+	u16 TxAGC;
 
 	TxAGC = TxPower;
 	set_bb_reg(pAdapter, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC);
@@ -726,7 +726,7 @@ static u32 GetPhyRxPktCounts(struct _adapter *pAdapter, u32 selbit)
 
 u32 r8712_GetPhyRxPktReceived(struct _adapter *pAdapter)
 {
-	u32 OFDM_cnt = 0, CCK_cnt = 0, HT_cnt = 0;
+	u32 OFDM_cnt, CCK_cnt, HT_cnt;
 
 	OFDM_cnt = GetPhyRxPktCounts(pAdapter, OFDM_MPDU_OK_BIT);
 	CCK_cnt = GetPhyRxPktCounts(pAdapter, CCK_MPDU_OK_BIT);
@@ -736,7 +736,7 @@ u32 r8712_GetPhyRxPktReceived(struct _adapter *pAdapter)
 
 u32 r8712_GetPhyRxPktCRC32Error(struct _adapter *pAdapter)
 {
-	u32 OFDM_cnt = 0, CCK_cnt = 0, HT_cnt = 0;
+	u32 OFDM_cnt, CCK_cnt, HT_cnt;
 
 	OFDM_cnt = GetPhyRxPktCounts(pAdapter, OFDM_MPDU_FAIL_BIT);
 	CCK_cnt = GetPhyRxPktCounts(pAdapter, CCK_MPDU_FAIL_BIT);
Signature · 1 line
1.9.1
#6 lore raw

Re: [Outreachy kernel] [PATCH 5/5] staging: rtl8712: rtl871x_mp: Remove useless initialisation

Quoted 12 lines · Amitoj Kaur Chawla

Remove intialisation of a variable that is immediately reassigned.

The semantic patch used to find this is:

// <smpl>
@@
type T;
identifier x;
constant C;
expression e;
@@

Quoted 4 lines

T x
- = C
;
x = e;

In some cases there are many variables that have been simplified, but this rule doesn't reflect that, because in this rule the assignment has to come immediately after the declaration. You could have made the following rule:

T x
- = C
;
... when != x
x = e;

But that could potentially give cases where the x = e is quite far away, which is probably not exactly what you want either. So you could just say that you identified some further opportunities by hand, and cleaned them up too.

julia

Quoted 49 lines

// </smpl>

---
 drivers/staging/rtl8712/rtl871x_mp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8712/rtl871x_mp.c +3 -3
index 26201ea..00b80f7 100644
@@ -295,7 +295,7 @@ void r8712_SetChannel(struct _adapter *pAdapter)
 
 static void SetCCKTxPower(struct _adapter *pAdapter, u8 TxPower)
 {
-	u16 TxAGC = 0;
+	u16 TxAGC;
 
 	TxAGC = TxPower;
 	set_bb_reg(pAdapter, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC);
@@ -726,7 +726,7 @@ static u32 GetPhyRxPktCounts(struct _adapter *pAdapter, u32 selbit)
 
 u32 r8712_GetPhyRxPktReceived(struct _adapter *pAdapter)
 {
-	u32 OFDM_cnt = 0, CCK_cnt = 0, HT_cnt = 0;
+	u32 OFDM_cnt, CCK_cnt, HT_cnt;
 
 	OFDM_cnt = GetPhyRxPktCounts(pAdapter, OFDM_MPDU_OK_BIT);
 	CCK_cnt = GetPhyRxPktCounts(pAdapter, CCK_MPDU_OK_BIT);
@@ -736,7 +736,7 @@ u32 r8712_GetPhyRxPktReceived(struct _adapter *pAdapter)
 
 u32 r8712_GetPhyRxPktCRC32Error(struct _adapter *pAdapter)
 {
-	u32 OFDM_cnt = 0, CCK_cnt = 0, HT_cnt = 0;
+	u32 OFDM_cnt, CCK_cnt, HT_cnt;
 
 	OFDM_cnt = GetPhyRxPktCounts(pAdapter, OFDM_MPDU_FAIL_BIT);
 	CCK_cnt = GetPhyRxPktCounts(pAdapter, CCK_MPDU_FAIL_BIT);
Signature · 8 lines
1.9.1

-- 
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/654a2272bc6169ee93a7c08a62bc855969d878ba.1444855933.git.amitoj1606%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
#7 lore raw

Re: [Outreachy kernel] [PATCH v2 5/5] staging: rtl8712: rtl871x_mp: Remove useless initialisation

In reply to Amitoj Kaur Chawla
Quoted 3 lines · Amitoj Kaur Chawla

Remove intialisation of a variable that is immediately reassigned. The problem was found using coccinelle semantic patch and further opportunities were identified by hand.

Better, thanks.

julia

Quoted 66 lines

The semantic patch used to find this is:

// <smpl>
@@
type T;
identifier x;
constant C;
expression e;
@@

T x
- = C
;
x = e;
// </smpl>

---
Changes in v2:
-Modify commit message

 drivers/staging/rtl8712/rtl871x_mp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8712/rtl871x_mp.c +3 -3
index 26201ea..00b80f7 100644
@@ -295,7 +295,7 @@ void r8712_SetChannel(struct _adapter *pAdapter)
 
 static void SetCCKTxPower(struct _adapter *pAdapter, u8 TxPower)
 {
-	u16 TxAGC = 0;
+	u16 TxAGC;
 
 	TxAGC = TxPower;
 	set_bb_reg(pAdapter, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC);
@@ -726,7 +726,7 @@ static u32 GetPhyRxPktCounts(struct _adapter *pAdapter, u32 selbit)
 
 u32 r8712_GetPhyRxPktReceived(struct _adapter *pAdapter)
 {
-	u32 OFDM_cnt = 0, CCK_cnt = 0, HT_cnt = 0;
+	u32 OFDM_cnt, CCK_cnt, HT_cnt;
 
 	OFDM_cnt = GetPhyRxPktCounts(pAdapter, OFDM_MPDU_OK_BIT);
 	CCK_cnt = GetPhyRxPktCounts(pAdapter, CCK_MPDU_OK_BIT);
@@ -736,7 +736,7 @@ u32 r8712_GetPhyRxPktReceived(struct _adapter *pAdapter)
 
 u32 r8712_GetPhyRxPktCRC32Error(struct _adapter *pAdapter)
 {
-	u32 OFDM_cnt = 0, CCK_cnt = 0, HT_cnt = 0;
+	u32 OFDM_cnt, CCK_cnt, HT_cnt;
 
 	OFDM_cnt = GetPhyRxPktCounts(pAdapter, OFDM_MPDU_FAIL_BIT);
 	CCK_cnt = GetPhyRxPktCounts(pAdapter, CCK_MPDU_FAIL_BIT);
Signature · 8 lines
1.9.1

-- 
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/654a2272bc6169ee93a7c08a62bc855969d878ba.1444855933.git.amitoj1606%40gmail.com.
For more options, visit https://groups.google.com/d/optout.