Skip to contentSkip to conversation

Unnecessary code cleanup patches

PATCH Superseded Abraham Samuel Adekunle 2 participants 6 messages Apr 2, 2025 – Apr 3, 2025

Subsystems (4)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover Unnecessary code cleanup patches

The patchset modifies unnecessary duplicate NULL test on a value in an expression, when the value has been NULL tested in a previous expression.

Abraham Samuel Adekunle (2):
staging: media: Remove NULL test on an already tested value
staging: rtl8723bs: Prevent duplicate NULL tests on a value

 drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c | 2 +-
 drivers/staging/media/av7110/sp8870.c                     | 2 +-
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c             | 2 +-
 drivers/staging/rtl8723bs/core/rtw_xmit.c                 | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 staging: media: Remove NULL test on an already tested value

When a value has been tested for NULL in an expression, a second NULL test on the same value in another expression is unnecessary when the value has not been assigned NULL.

Remove unnecessary duplicate NULL tests on the same value that has previously been NULL tested.

Found by Coccinelle

---
 drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c | 2 +-
 drivers/staging/media/av7110/sp8870.c                     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c +1 -1
index e176483df301..0abac820299a 100644
@@ -1292,7 +1292,7 @@ static int gmin_get_config_dsm_var(struct device *dev,
 	 * if it founds something different than string, letting it
 	 * to fall back to the old code.
 	 */
-	if (cur && cur->type != ACPI_TYPE_STRING) {
+	if (cur->type != ACPI_TYPE_STRING) {
 		dev_info(dev, "found non-string _DSM entry for '%s'\n", var);
 		ACPI_FREE(obj);
 		return -EINVAL;
drivers/staging/media/av7110/sp8870.c +1 -1
index 0c813860f5b2..8c5fa5ed5340 100644
@@ -508,7 +508,7 @@ static int sp8870_set_frontend(struct dvb_frontend *fe)
 	}
 
 	if (debug) {
-		if (valid) {
+		{
 			if (trials > 1) {
 				pr_info("%s(): firmware lockup!!!\n", __func__);
 				pr_info("%s(): recovered after %i trial(s))\n",  __func__, trials - 1);
Signature · 1 line
2.34.1
#4 lore raw

PATCH 2/2 staging: rtl8723bs: Prevent duplicate NULL tests on a value

In reply to Abraham Samuel Adekunle

When a value has been tested for NULL in an expression, a second NULL test on the same value in another expression is unnecessary when the value has not been assigned NULL.

Remove unnecessary duplicate NULL tests on the same value that has previously been NULL tested.

Found by Coccinelle

---
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 2 +-
 drivers/staging/rtl8723bs/core/rtw_xmit.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +1 -1
index 90966b7034ab..675226535cd1 100644
@@ -1323,7 +1323,7 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
 	spin_unlock_bh(&pstapriv->asoc_list_lock);
 
 	/*  now the station is qualified to join our BSS... */
-	if (pstat && (pstat->state & WIFI_FW_ASSOC_SUCCESS) && (status == WLAN_STATUS_SUCCESS)) {
+	if ((pstat->state & WIFI_FW_ASSOC_SUCCESS) && (status == WLAN_STATUS_SUCCESS)) {
 		/* 1 bss_cap_update & sta_info_update */
 		bss_cap_update_on_sta_join(padapter, pstat);
 		sta_info_update(padapter, pstat);
drivers/staging/rtl8723bs/core/rtw_xmit.c +1 -1
index 026061b464f7..5d5278eefabe 100644
@@ -941,7 +941,7 @@ s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr
 			if (!(psta->state & _FW_LINKED))
 				return _FAIL;
 
-			if (psta) {
+			{
 				psta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
 				psta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
 				pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority];
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/2] staging: media: Remove NULL test on an already tested value

In reply to Abraham Samuel Adekunle
Quoted 10 lines · Abraham Samuel Adekunle

When a value has been tested for NULL in an expression, a second NULL test on the same value in another expression is unnecessary when the value has not been assigned NULL.

Remove unnecessary duplicate NULL tests on the same value that has previously been NULL tested.

 drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c | 2 +-
 drivers/staging/media/av7110/sp8870.c                     | 2 +-

Please, split this on per driver basis, as they have different maintainers and trees to go through.

...

drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c static int gmin_get_config_dsm_var(struct device *dev, · line 1298

Quoted 11 lines
drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c +1 -1
@@ -1292,7 +1292,7 @@ static int gmin_get_config_dsm_var(struct device *dev,
         * if it founds something different than string, letting it
         * to fall back to the old code.
         */
-       if (cur && cur->type != ACPI_TYPE_STRING) {
+       if (cur->type != ACPI_TYPE_STRING) {
                dev_info(dev, "found non-string _DSM entry for '%s'\n", var);
                ACPI_FREE(obj);
                return -EINVAL;

This change is good.

...

drivers/staging/media/av7110/sp8870.c static int sp8870_set_frontend(struct dvb_frontend *fe) · line 514

Quoted 13 lines
drivers/staging/media/av7110/sp8870.c +1 -1
index 0c813860f5b2..8c5fa5ed5340 100644
@@ -508,7 +508,7 @@ static int sp8870_set_frontend(struct dvb_frontend *fe)
        }
 
        if (debug) {
-               if (valid) {
+               {
                        if (trials > 1) {
                                pr_info("%s(): firmware lockup!!!\n", __func__);
                                pr_info("%s(): recovered after %i trial(s))\n",  __func__, trials - 1);

But this is not fully done. Why do we need to keep {}? Just shift left the code and remove those {} altogether.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Re: [PATCH 2/2] staging: rtl8723bs: Prevent duplicate NULL tests on a value

In reply to Abraham Samuel Adekunle
Quoted 9 lines · Abraham Samuel Adekunle

When a value has been tested for NULL in an expression, a second NULL test on the same value in another expression is unnecessary when the value has not been assigned NULL.

Remove unnecessary duplicate NULL tests on the same value that has previously been NULL tested.

Found by Coccinelle

...

drivers/staging/rtl8723bs/core/rtw_xmit.c s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr · line 947

Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_xmit.c +1 -1
-                       if (psta) {
+                       {
                                psta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
                                psta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
                                pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority];

Same comment, shift left and remove pointless {} altogether.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Re: [PATCH 1/2] staging: media: Remove NULL test on an already tested value

In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Abraham Samuel Adekunle

When a value has been tested for NULL in an expression, a second NULL test on the same value in another expression is unnecessary when the value has not been assigned NULL.

Quoted 8 lines
Quoted 5 lines

Remove unnecessary duplicate NULL tests on the same value that has previously been NULL tested.

 drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c | 2 +-
 drivers/staging/media/av7110/sp8870.c                     | 2 +-

Please, split this on per driver basis, as they have different maintainers and trees to go through.

Thank you for your review.
I will do that.

Quoted 26 lines

...

drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c static int gmin_get_config_dsm_var(struct device *dev, · line 1298

Quoted 11 lines
drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c +1 -1
@@ -1292,7 +1292,7 @@ static int gmin_get_config_dsm_var(struct device *dev,
         * if it founds something different than string, letting it
         * to fall back to the old code.
         */
-       if (cur && cur->type != ACPI_TYPE_STRING) {
+       if (cur->type != ACPI_TYPE_STRING) {
                dev_info(dev, "found non-string _DSM entry for '%s'\n", var);
                ACPI_FREE(obj);
                return -EINVAL;

This change is good.

...

Quoted 7 lines
drivers/staging/media/av7110/sp8870.c +0 -0
index 0c813860f5b2..8c5fa5ed5340 100644
@@ -508,7 +508,7 @@ static int sp8870_set_frontend(struct dvb_frontend *fe)
        }
 
Quoted 9 lines

drivers/staging/media/av7110/sp8870.c static int sp8870_set_frontend(struct dvb_frontend *fe) · line 514

Quoted 6 lines
drivers/staging/media/av7110/sp8870.c +1 -1
        if (debug) {
-               if (valid) {
+               {
                        if (trials > 1) {
                                pr_info("%s(): firmware lockup!!!\n", __func__);
                                pr_info("%s(): recovered after %i trial(s))\n",  __func__, trials - 1);

But this is not fully done. Why do we need to keep {}? Just shift left the code and remove those {} altogether.

Okay I will effect the change.
Thanks

Adekunle