All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: rtl8723bs: core: simplify the if condition
@ 2021-10-09  6:00 Saurav Girepunje
  2021-10-09 16:51 ` Hans de Goede
  2021-10-11 12:09 ` Dan Carpenter
  0 siblings, 2 replies; 4+ messages in thread
From: Saurav Girepunje @ 2021-10-09  6:00 UTC (permalink / raw)
  To: gregkh, fabioaiuto83, ross.schm.dev, deborahbrouwer3563,
	hdegoede, marcocesati, saurav.girepunje, phil, linux-staging,
	linux-kernel
  Cc: saurav.girepunje

if psta is NULL, function is returning with fail. On next if condition
again checking if psta is not a NULL. Remove multiple if condition check.

Function is already using goto exit statement to exit.Replace multiple
return with goto exit statement.

Signed-off-by: Saurav Girepunje <saurav.girepunje@gmail.com>
---
 drivers/staging/rtl8723bs/core/rtw_xmit.c | 61 ++++++++++-------------
 1 file changed, 26 insertions(+), 35 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_xmit.c b/drivers/staging/rtl8723bs/core/rtw_xmit.c
index 34505b35a7f3..4e4a1bed882b 100644
--- a/drivers/staging/rtl8723bs/core/rtw_xmit.c
+++ b/drivers/staging/rtl8723bs/core/rtw_xmit.c
@@ -932,49 +932,40 @@ s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr
 		/* TODO: fill HT Control Field */

 		/* Update Seq Num will be handled by f/w */
-		{
-			struct sta_info *psta;
-
-			psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
-			if (pattrib->psta != psta)
-				return _FAIL;
-
-			if (!psta)
-				return _FAIL;
+		struct sta_info *psta;

-			if (!(psta->state & _FW_LINKED))
-				return _FAIL;
+		psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
+		if (!psta || pattrib->psta != psta || !(psta->state & _FW_LINKED))
+			res = _FAIL;
+			goto exit;

-			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];
+		psta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
+		psta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
+		pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority];

-				SetSeqNum(hdr, pattrib->seqnum);
+		SetSeqNum(hdr, pattrib->seqnum);

-				/* check if enable ampdu */
-				if (pattrib->ht_en && psta->htpriv.ampdu_enable)
-					if (psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority))
-						pattrib->ampdu_en = true;
+		/* check if enable ampdu */
+		if (pattrib->ht_en && psta->htpriv.ampdu_enable)
+			if (psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority))
+				pattrib->ampdu_en = true;

-				/* re-check if enable ampdu by BA_starting_seqctrl */
-				if (pattrib->ampdu_en == true) {
-					u16 tx_seq;
+		/* re-check if enable ampdu by BA_starting_seqctrl */
+		if (pattrib->ampdu_en == true) {
+			u16 tx_seq;

-					tx_seq = psta->BA_starting_seqctrl[pattrib->priority & 0x0f];
+			tx_seq = psta->BA_starting_seqctrl[pattrib->priority & 0x0f];

-					/* check BA_starting_seqctrl */
-					if (SN_LESS(pattrib->seqnum, tx_seq)) {
-						pattrib->ampdu_en = false;/* AGG BK */
-					} else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
-						psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
+			/* check BA_starting_seqctrl */
+			if (SN_LESS(pattrib->seqnum, tx_seq)) {
+				pattrib->ampdu_en = false;/* AGG BK */
+			} else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
+				psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;

-						pattrib->ampdu_en = true;/* AGG EN */
-					} else {
-						psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
-						pattrib->ampdu_en = true;/* AGG EN */
-					}
-				}
+				pattrib->ampdu_en = true;/* AGG EN */
+			} else {
+				psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
+				pattrib->ampdu_en = true;/* AGG EN */
 			}
 		}
 	}
--
2.32.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] staging: rtl8723bs: core: simplify the if condition
  2021-10-09  6:00 [PATCH] staging: rtl8723bs: core: simplify the if condition Saurav Girepunje
@ 2021-10-09 16:51 ` Hans de Goede
  2021-10-09 18:14   ` Saurav Girepunje
  2021-10-11 12:09 ` Dan Carpenter
  1 sibling, 1 reply; 4+ messages in thread
From: Hans de Goede @ 2021-10-09 16:51 UTC (permalink / raw)
  To: Saurav Girepunje, gregkh, fabioaiuto83, ross.schm.dev,
	deborahbrouwer3563, marcocesati, phil, linux-staging,
	linux-kernel
  Cc: saurav.girepunje

Hi,

On 10/9/21 8:00 AM, Saurav Girepunje wrote:
> if psta is NULL, function is returning with fail. On next if condition
> again checking if psta is not a NULL. Remove multiple if condition check.
> 
> Function is already using goto exit statement to exit.Replace multiple
> return with goto exit statement.
> 
> Signed-off-by: Saurav Girepunje <saurav.girepunje@gmail.com>
> ---
>  drivers/staging/rtl8723bs/core/rtw_xmit.c | 61 ++++++++++-------------
>  1 file changed, 26 insertions(+), 35 deletions(-)
> 
> diff --git a/drivers/staging/rtl8723bs/core/rtw_xmit.c b/drivers/staging/rtl8723bs/core/rtw_xmit.c
> index 34505b35a7f3..4e4a1bed882b 100644
> --- a/drivers/staging/rtl8723bs/core/rtw_xmit.c
> +++ b/drivers/staging/rtl8723bs/core/rtw_xmit.c
> @@ -932,49 +932,40 @@ s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr
>  		/* TODO: fill HT Control Field */
> 
>  		/* Update Seq Num will be handled by f/w */
> -		{
> -			struct sta_info *psta;
> -
> -			psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
> -			if (pattrib->psta != psta)
> -				return _FAIL;
> -
> -			if (!psta)
> -				return _FAIL;
> +		struct sta_info *psta;

You are now declaring a variable after some statements, this will
cause a compiler warning in some cases. Please move this variable
declaration up, grouping it together with the other variable
declarations.

> 
> -			if (!(psta->state & _FW_LINKED))
> -				return _FAIL;
> +		psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
> +		if (!psta || pattrib->psta != psta || !(psta->state & _FW_LINKED))
> +			res = _FAIL;
> +			goto exit;

You are both removing an identation level here because you are removing
the compound statement which contained the psta declaration as well
as refactoring the code.

Please split this into 2 separate commits, 1 where you only drop the
extra indentation level (and move the psta declaration up).

And then a separate commit which just the actual code changes.

Your current patch is very hard to review because you are doing
2 things at once.

Also it looks like this patch depends on your previous patch:
"[PATCH] staging: rtl8723bs: core: remove empty else section"

When patches depend on each other please send them together
as a single patch series. E.g. for version 2 (v2) of a 3 patch
series consisting of the last 3 commits in your local tree use
(so the next version of these patches) use:

git format-patch -v2 --cover-letter HEAD~3
$editor v2-0000-cover-letter.patch 
 <describe series contents + what was changed in the cover-letter>
git send-email v2-00*.patch

Regards,

Hans


> 
> -			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];
> +		psta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
> +		psta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
> +		pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority];
> 
> -				SetSeqNum(hdr, pattrib->seqnum);
> +		SetSeqNum(hdr, pattrib->seqnum);
> 
> -				/* check if enable ampdu */
> -				if (pattrib->ht_en && psta->htpriv.ampdu_enable)
> -					if (psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority))
> -						pattrib->ampdu_en = true;
> +		/* check if enable ampdu */
> +		if (pattrib->ht_en && psta->htpriv.ampdu_enable)
> +			if (psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority))
> +				pattrib->ampdu_en = true;
> 
> -				/* re-check if enable ampdu by BA_starting_seqctrl */
> -				if (pattrib->ampdu_en == true) {
> -					u16 tx_seq;
> +		/* re-check if enable ampdu by BA_starting_seqctrl */
> +		if (pattrib->ampdu_en == true) {
> +			u16 tx_seq;
> 
> -					tx_seq = psta->BA_starting_seqctrl[pattrib->priority & 0x0f];
> +			tx_seq = psta->BA_starting_seqctrl[pattrib->priority & 0x0f];
> 
> -					/* check BA_starting_seqctrl */
> -					if (SN_LESS(pattrib->seqnum, tx_seq)) {
> -						pattrib->ampdu_en = false;/* AGG BK */
> -					} else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
> -						psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
> +			/* check BA_starting_seqctrl */
> +			if (SN_LESS(pattrib->seqnum, tx_seq)) {
> +				pattrib->ampdu_en = false;/* AGG BK */
> +			} else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
> +				psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
> 
> -						pattrib->ampdu_en = true;/* AGG EN */
> -					} else {
> -						psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
> -						pattrib->ampdu_en = true;/* AGG EN */
> -					}
> -				}
> +				pattrib->ampdu_en = true;/* AGG EN */
> +			} else {
> +				psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
> +				pattrib->ampdu_en = true;/* AGG EN */
>  			}
>  		}
>  	}
> --
> 2.32.0
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] staging: rtl8723bs: core: simplify the if condition
  2021-10-09 16:51 ` Hans de Goede
@ 2021-10-09 18:14   ` Saurav Girepunje
  0 siblings, 0 replies; 4+ messages in thread
From: Saurav Girepunje @ 2021-10-09 18:14 UTC (permalink / raw)
  To: Hans de Goede, gregkh, fabioaiuto83, ross.schm.dev,
	deborahbrouwer3563, marcocesati, phil, linux-staging,
	linux-kernel
  Cc: saurav.girepunje



On 09/10/21 10:21 pm, Hans de Goede wrote:
> Hi,
> 
> On 10/9/21 8:00 AM, Saurav Girepunje wrote:
>> if psta is NULL, function is returning with fail. On next if condition
>> again checking if psta is not a NULL. Remove multiple if condition check.
>>
>> Function is already using goto exit statement to exit.Replace multiple
>> return with goto exit statement.
>>
>> Signed-off-by: Saurav Girepunje <saurav.girepunje@gmail.com>
>> ---
>>   drivers/staging/rtl8723bs/core/rtw_xmit.c | 61 ++++++++++-------------
>>   1 file changed, 26 insertions(+), 35 deletions(-)
>>
>> diff --git a/drivers/staging/rtl8723bs/core/rtw_xmit.c b/drivers/staging/rtl8723bs/core/rtw_xmit.c
>> index 34505b35a7f3..4e4a1bed882b 100644
>> --- a/drivers/staging/rtl8723bs/core/rtw_xmit.c
>> +++ b/drivers/staging/rtl8723bs/core/rtw_xmit.c
>> @@ -932,49 +932,40 @@ s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr
>>   		/* TODO: fill HT Control Field */
>>
>>   		/* Update Seq Num will be handled by f/w */
>> -		{
>> -			struct sta_info *psta;
>> -
>> -			psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
>> -			if (pattrib->psta != psta)
>> -				return _FAIL;
>> -
>> -			if (!psta)
>> -				return _FAIL;
>> +		struct sta_info *psta;
> 
> You are now declaring a variable after some statements, this will
> cause a compiler warning in some cases. Please move this variable
> declaration up, grouping it together with the other variable
> declarations.
> 
Yes, I will move variable declaration to up.
>>
>> -			if (!(psta->state & _FW_LINKED))
>> -				return _FAIL;
>> +		psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
>> +		if (!psta || pattrib->psta != psta || !(psta->state & _FW_LINKED))
>> +			res = _FAIL;
>> +			goto exit;
> 
> You are both removing an identation level here because you are removing
> the compound statement which contained the psta declaration as well
> as refactoring the code.
> 
> Please split this into 2 separate commits, 1 where you only drop the
> extra indentation level (and move the psta declaration up).
> 
> And then a separate commit which just the actual code changes.
> 
> Your current patch is very hard to review because you are doing
> 2 things at once.
> 
> Also it looks like this patch depends on your previous patch:
> "[PATCH] staging: rtl8723bs: core: remove empty else section"
> 
> When patches depend on each other please send them together
> as a single patch series. E.g. for version 2 (v2) of a 3 patch
> series consisting of the last 3 commits in your local tree use
> (so the next version of these patches) use:
> 
> git format-patch -v2 --cover-letter HEAD~3
> $editor v2-0000-cover-letter.patch
>   <describe series contents + what was changed in the cover-letter>
> git send-email v2-00*.patch
> 
> Regards,
> 
> Hans
>
Sure, I will split this patch and resend all of them as a single patch 
series including my previous patch.

> 
>>
>> -			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];
>> +		psta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
>> +		psta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
>> +		pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority];
>>
>> -				SetSeqNum(hdr, pattrib->seqnum);
>> +		SetSeqNum(hdr, pattrib->seqnum);
>>
>> -				/* check if enable ampdu */
>> -				if (pattrib->ht_en && psta->htpriv.ampdu_enable)
>> -					if (psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority))
>> -						pattrib->ampdu_en = true;
>> +		/* check if enable ampdu */
>> +		if (pattrib->ht_en && psta->htpriv.ampdu_enable)
>> +			if (psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority))
>> +				pattrib->ampdu_en = true;
>>
>> -				/* re-check if enable ampdu by BA_starting_seqctrl */
>> -				if (pattrib->ampdu_en == true) {
>> -					u16 tx_seq;
>> +		/* re-check if enable ampdu by BA_starting_seqctrl */
>> +		if (pattrib->ampdu_en == true) {
>> +			u16 tx_seq;
>>
>> -					tx_seq = psta->BA_starting_seqctrl[pattrib->priority & 0x0f];
>> +			tx_seq = psta->BA_starting_seqctrl[pattrib->priority & 0x0f];
>>
>> -					/* check BA_starting_seqctrl */
>> -					if (SN_LESS(pattrib->seqnum, tx_seq)) {
>> -						pattrib->ampdu_en = false;/* AGG BK */
>> -					} else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
>> -						psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
>> +			/* check BA_starting_seqctrl */
>> +			if (SN_LESS(pattrib->seqnum, tx_seq)) {
>> +				pattrib->ampdu_en = false;/* AGG BK */
>> +			} else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
>> +				psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
>>
>> -						pattrib->ampdu_en = true;/* AGG EN */
>> -					} else {
>> -						psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
>> -						pattrib->ampdu_en = true;/* AGG EN */
>> -					}
>> -				}
>> +				pattrib->ampdu_en = true;/* AGG EN */
>> +			} else {
>> +				psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
>> +				pattrib->ampdu_en = true;/* AGG EN */
>>   			}
>>   		}
>>   	}
>> --
>> 2.32.0
>>
> 

Thanks Hans for review.

Regards,
Saurav

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] staging: rtl8723bs: core: simplify the if condition
  2021-10-09  6:00 [PATCH] staging: rtl8723bs: core: simplify the if condition Saurav Girepunje
  2021-10-09 16:51 ` Hans de Goede
@ 2021-10-11 12:09 ` Dan Carpenter
  1 sibling, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-10-11 12:09 UTC (permalink / raw)
  To: Saurav Girepunje
  Cc: gregkh, fabioaiuto83, ross.schm.dev, deborahbrouwer3563,
	hdegoede, marcocesati, phil, linux-staging, linux-kernel,
	saurav.girepunje

You didn't compile test the patch.

On Sat, Oct 09, 2021 at 11:30:53AM +0530, Saurav Girepunje wrote:
> if psta is NULL, function is returning with fail. On next if condition
> again checking if psta is not a NULL. Remove multiple if condition check.
> 

I don't think this is an accurate description of what the patch does.

> Function is already using goto exit statement to exit.Replace multiple
> return with goto exit statement.

No.  Do nothing labels only hurt readability and introduce "forgot to
set the error code bugs."

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-11 12:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-09  6:00 [PATCH] staging: rtl8723bs: core: simplify the if condition Saurav Girepunje
2021-10-09 16:51 ` Hans de Goede
2021-10-09 18:14   ` Saurav Girepunje
2021-10-11 12:09 ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.