From: David Laight <David.Laight@ACULAB.COM>
To: 'Martin Kaiser' <martin@kaiser.cx>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Larry Finger <Larry.Finger@lwfinger.net>,
Phillip Potter <phil@philpotter.co.uk>,
Michael Straube <straube.linux@gmail.com>,
"linux-staging@lists.linux.dev" <linux-staging@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] staging: r8188eu: remove local BIT macro
Date: Sat, 19 Mar 2022 22:35:58 +0000 [thread overview]
Message-ID: <ac3343ea279b4d048d77b3cf2724bcbe@AcuMS.aculab.com> (raw)
In-Reply-To: <20220319180342.3143734-1-martin@kaiser.cx>
From: Martin Kaiser <martin@kaiser.cx>
> Sent: 19 March 2022 18:04
>
> The r8188eu driver defines a local BIT(x) macro. Remove this local macro
> and use the one from include/linux/bits.h.
>
> The global BIT macro returns an unsigned long value, the removed local
> BIT macro used a signed int.
>
> DYNAMIC_BB_DYNAMIC_TXPWR is defined as BIT(2), ~DYNAMIC_BB_DYNAMIC_TXPWR
> is passed to Switch_DM_Func as a u32 parameter. We need a cast in this
> case as ~DYNAMIC_BB_DYNAMIC_TXPWR is a 64-bit value on x86_64 systems.
Hmmm....
Why not fix the called function so that the caller doesn't
need to do the invert.
...
> b/drivers/staging/r8188eu/core/rtw_wlan_util.c
> index 665b077190bc..f32401deae9a 100644
> --- a/drivers/staging/r8188eu/core/rtw_wlan_util.c
> +++ b/drivers/staging/r8188eu/core/rtw_wlan_util.c
> @@ -1276,13 +1276,13 @@ void update_IOT_info(struct adapter *padapter)
> pmlmeinfo->turboMode_cts2self = 0;
> pmlmeinfo->turboMode_rtsen = 1;
> /* disable high power */
> - Switch_DM_Func(padapter, (~DYNAMIC_BB_DYNAMIC_TXPWR), false);
> + Switch_DM_Func(padapter, (u32)(~DYNAMIC_BB_DYNAMIC_TXPWR), false);
The function is defined as a real function:
Even though all the callers either pass 'true' or 'false' for enable.
void Switch_DM_Func(struct adapter *padapter, u32 mode, u8 enable)
{
if (enable)
SetHwReg8188EU(padapter, HW_VAR_DM_FUNC_SET, (u8 *)(&mode));
else
SetHwReg8188EU(padapter, HW_VAR_DM_FUNC_CLR, (u8 *)(&mode));
}
That (u8 *)&mode cast is at best dubious.
Searching for the callers also gives:
Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, false)
Should that have an invert?
Or is the other call wrong?
They don't both look right.
Or is DYNAMIC_FUNC_DISABLE just zero?
SetHwReg8188EU() is basically a big switch statement on the
'probably mostly constant' second argument.
The two relevant switch cases are:
case HW_VAR_DM_FUNC_SET:
if (*((u32 *)val) == DYNAMIC_ALL_FUNC_ENABLE) {
podmpriv->SupportAbility = pdmpriv->InitODMFlag;
} else {
podmpriv->SupportAbility |= *((u32 *)val);
}
break;
case HW_VAR_DM_FUNC_CLR:
podmpriv->SupportAbility &= *((u32 *)val);
break;
So the ~ should probably be moved to the final statement.
OTOH this code is a big pile of poo.
Abstraction functions gone mad.
If you have a function that does two different things based on
a parameter that is always a constant you really should have
two different functions.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2022-03-19 22:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-19 18:03 [PATCH] staging: r8188eu: remove local BIT macro Martin Kaiser
2022-03-19 22:35 ` David Laight [this message]
2022-03-21 9:06 ` Dan Carpenter
2022-03-21 9:14 ` David Laight
2022-03-21 9:34 ` Martin Kaiser
2022-03-21 8:15 ` Dan Carpenter
2022-03-21 9:04 ` David Laight
2022-03-21 9:07 ` Dan Carpenter
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=ac3343ea279b4d048d77b3cf2724bcbe@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=Larry.Finger@lwfinger.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=martin@kaiser.cx \
--cc=phil@philpotter.co.uk \
--cc=straube.linux@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