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

Andy Shevchenko
2025-04-03T13:39:39Z

On Thu, Apr 03, 2025 at 02:26:43PM +0100, Abraham Samuel Adekunle wrote:
> 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

Missing period.

...

> + 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);
> +
> + /* 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;
> +
> + 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;

While at it, make this more readable:

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;

Ditto.

Also consider to use module operator as it shows the exact amount of the
records we support in the circular buffer.

psta->BA_starting_seqctrl[pattrib->priority & 0x0f] =
(pattrib->seqnum + 1) % 4096;

Since it's power-of-two denominator, it will be optimised by the compiler to
the same code as it's now.

> + pattrib->ampdu_en = true;/* AGG EN */
> }

--
With Best Regards,
Andy Shevchenko