From: Dan Carpenter <dan.carpenter@oracle.com>
To: Rebecca Mckeever <remckee0@gmail.com>
Cc: outreachy@lists.linux.dev,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] staging: rtl8192u: use min_t/max_t macros instead of if else
Date: Thu, 7 Apr 2022 10:49:45 +0300 [thread overview]
Message-ID: <20220407074945.GJ3293@kadam> (raw)
In-Reply-To: <9855c33d65558f7d2e66805009444288b99f9248.1649288226.git.remckee0@gmail.com>
On Wed, Apr 06, 2022 at 07:09:44PM -0500, Rebecca Mckeever wrote:
> Replace if else statement with min_t or max_t macros to increase
> readability and conform to Linux kernel coding style. The _t versions
> of the macros must be used to avoid applying typeof to the bit fields
> pPeerHTCap->MaxRxAMPDUFactor, and pPeerHTCap->MPDUDensity.
> Found with minmax coccinelle script.
>
> Signed-off-by: Rebecca Mckeever <remckee0@gmail.com>
> ---
> drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c | 13 +++++--------
> 1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
> index dba3f2db9f48..8f2cd669c5d4 100644
> --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
> +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
> @@ -940,10 +940,8 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
> else
> pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_64K;
> } else {
> - if (pPeerHTCap->MaxRxAMPDUFactor < HT_AGG_SIZE_32K)
> - pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor;
> - else
> - pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_32K;
> + pHTInfo->CurrentAMPDUFactor = min_t(u8, pPeerHTCap->MaxRxAMPDUFactor,
> + HT_AGG_SIZE_32K);
The u8 cast doesn't cause a problem, but it makes me nervous so I have
to look up the types involved.
pPeerHTCap->MaxRxAMPDUFactor is 2 bits of a u8.
HT_AGG_SIZE_32K is an enum, which in real life terms of the compilers we
use is going to be a uint.
With min_t() you want to do the casts to a large enough unsigned type
so that it doesn't truncate. And so u8 works. But it would be less
scary if you cast it to a u32 or uint because a read will assume that
probably pPeerHTCap->MaxRxAMPDUFactor is a u32 and HT_AGG_SIZE_32K is an
int. These are false assumptions, but probably that's what most people
will assume.
The reader in this case will feel safe and not worry about truncation so
they won't have to look up the types.
regards,
dan carpenter
prev parent reply other threads:[~2022-04-07 7:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-07 0:09 [PATCH 0/2] staging: rtl8192u: use min/max macros Rebecca Mckeever
2022-04-07 0:09 ` [PATCH 1/2] staging: rtl8192u: use max macro instead of ternary operator Rebecca Mckeever
2022-04-07 7:28 ` Dan Carpenter
2022-04-07 0:09 ` [PATCH 2/2] staging: rtl8192u: use min_t/max_t macros instead of if else Rebecca Mckeever
2022-04-07 7:49 ` Dan Carpenter [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220407074945.GJ3293@kadam \
--to=dan.carpenter@oracle.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=outreachy@lists.linux.dev \
--cc=remckee0@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox