From: Ping-Ke Shih <pkshih@realtek.com>
To: Kalle Valo <kvalo@kernel.org>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>
Subject: RE: [PATCH] wifi: rtw89: use FIELD_PREP to fill MAC quota value
Date: Tue, 8 Nov 2022 00:41:05 +0000 [thread overview]
Message-ID: <b2df88bd03aa49adb734ea9440e414a8@realtek.com> (raw)
In-Reply-To: <87zgd3t0cg.fsf@kernel.org>
> -----Original Message-----
> From: Kalle Valo <kvalo@kernel.org>
> Sent: Monday, November 7, 2022 8:29 PM
> To: Ping-Ke Shih <pkshih@realtek.com>
> Cc: linux-wireless@vger.kernel.org
> Subject: Re: [PATCH] wifi: rtw89: use FIELD_PREP to fill MAC quota value
>
> Ping-Ke Shih <pkshih@realtek.com> writes:
>
> > Coverity reported shift 16 bits could cause sign extension and might get
> > an unexpected value. Since the input values are predefined and no this
> > kind of case, original code is safe so far. But, still changing them to
> > use FIELD_PREP() will be more clear and prevent mistakes in the future.
> >
> > The original message of Coverity is:
> > Suspicious implicit sign extension: "max_cfg->cma0_dma" with type "u16"
> > (16 bits, unsigned) is promoted in "max_cfg->cma0_dma << 16" to type
> > "int" (32 bits, signed), then sign-extended to type "unsigned long"
> > (64 bits, unsigned). If "max_cfg->cma0_dma << 16" is greater than
> > 0x7FFFFFFF, the upper bits of the result will all be 1."
> >
> > Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> > Addresses-Coverity-ID: 1527095 ("Integer handling issues")
> > Fixes: e3ec7017f6a2 ("rtw89: add Realtek 802.11ax driver")
> > Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
> > ---
> > drivers/net/wireless/realtek/rtw89/mac.c | 6 ++----
> > 1 file changed, 2 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/net/wireless/realtek/rtw89/mac.c b/drivers/net/wireless/realtek/rtw89/mac.c
> > index bb49033b587d2..11081dfdfb172 100644
> > --- a/drivers/net/wireless/realtek/rtw89/mac.c
> > +++ b/drivers/net/wireless/realtek/rtw89/mac.c
> > @@ -1487,10 +1487,8 @@ static int dle_mix_cfg(struct rtw89_dev *rtwdev, const struct rtw89_dle_mem *cfg
> > #define INVALID_QT_WCPU U16_MAX
> > #define SET_QUOTA_VAL(_min_x, _max_x, _module, _idx) \
> > do { \
> > - val = ((_min_x) & \
> > - B_AX_ ## _module ## _MIN_SIZE_MASK) | \
> > - (((_max_x) << 16) & \
> > - B_AX_ ## _module ## _MAX_SIZE_MASK); \
> > + val = FIELD_PREP(B_AX_ ## _module ## _MIN_SIZE_MASK, _min_x) | \
> > + FIELD_PREP(B_AX_ ## _module ## _MAX_SIZE_MASK, _max_x); \
>
> BTW in wireless nowadays the preference is to use u32_encode_bits() & co
> instead of FIELD_PREP(). Not an issue for this patch, just wanted to
> mention anyway.
>
I can practice to use u32_encode_bits() from this patch. Will send v2.
Ping-Ke
prev parent reply other threads:[~2022-11-08 0:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-03 7:24 [PATCH] wifi: rtw89: use FIELD_PREP to fill MAC quota value Ping-Ke Shih
2022-11-07 12:28 ` Kalle Valo
2022-11-08 0:41 ` Ping-Ke Shih [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=b2df88bd03aa49adb734ea9440e414a8@realtek.com \
--to=pkshih@realtek.com \
--cc=kvalo@kernel.org \
--cc=linux-wireless@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).