From: Dan Carpenter <dan.carpenter@linaro.org>
To: Qianfeng Rong <rongqianfeng@vivo.com>
Cc: Brian Norris <briannorris@chromium.org>,
Francesco Dolcini <francesco@dolcini.it>,
Johannes Berg <johannes.berg@intel.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Kalle Valo <kvalo@kernel.org>,
Aditya Kumar Singh <quic_adisi@quicinc.com>,
Rameshkumar Sundaram <quic_ramess@quicinc.com>,
Roopni Devanathan <quic_rdevanat@quicinc.com>,
"open list:MARVELL MWIFIEX WIRELESS DRIVER"
<linux-wireless@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 5/5] wifi: mwifiex: use vmalloc_array() to simplify code
Date: Tue, 12 Aug 2025 17:31:39 +0300 [thread overview]
Message-ID: <aJtQS-Tpzw90Hqtl@stanley.mountain> (raw)
In-Reply-To: <e66eb22f-5565-4f33-b523-f93dc81a1210@vivo.com>
On Tue, Aug 12, 2025 at 10:13:43PM +0800, Qianfeng Rong wrote:
>
> 在 2025/8/12 21:48, Dan Carpenter 写道:
> > On Tue, Aug 12, 2025 at 09:32:18PM +0800, Qianfeng Rong wrote:
> > > Remove array_size() calls and replace vmalloc() with vmalloc_array() to
> > > simplify the code.
> > >
> > > Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> > > ---
> > > drivers/net/wireless/marvell/mwifiex/cfg80211.c | 4 ++--
> > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
> > > index 3498743d5ec0..fb4183ff02a9 100644
> > > --- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c
> > > +++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
> > > @@ -4673,8 +4673,8 @@ int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
> > > * additional active scan request for hidden SSIDs on passive channels.
> > > */
> > > adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a);
> > > - adapter->chan_stats = vmalloc(array_size(sizeof(*adapter->chan_stats),
> > > - adapter->num_in_chan_stats));
> > > + adapter->chan_stats = vmalloc_array(adapter->num_in_chan_stats,
> > > + sizeof(*adapter->chan_stats));
> > n_channels_bg is 14
> > n_channels_a is either 0 or 31 depending on if we're using BAND_A.
> > sizeof(*adapter->chan_stats) is 10.
> >
> > So we're either allocating 280 or 900 bytes, which is quite small. We
> > should just use kmalloc_array() instead of vmalloc_array().
> Switching to kmalloc_array() requires changing vfree() to kfree(),
> but I couldn't locate the memory release code.
It's not hard to locate with a bit of looking. ;)
> This modification
> likely requires deep familiarity with the codebase. Also, for
> variable-sized allocations, kvmalloc_array() is preferable, but
> requires kvfree() for proper memory release.
Don't use kvmalloc_array(). The rules are:
1) small amounts of memory: kmalloc()
2) possibly large ammounts of memory up to 2GB: kvmalloc()
3) definitely large ammounts of memory or larger than 2GB: vmalloc()
There are also places where the memory needs to be contiguous and for
those situations kvmalloc() and vmalloc() can't be used.
Here we're allocating less than a PAGE so the appropriate thing is
kmalloc_array().
I'm looking at this some more and these statistics are updated in
mwifiex_update_chan_statistics() and not necessarily all of them
are updated. But they're used in mwifiex_cfg80211_dump_survey()
when potentially the memory is still uninitialized.
I really think we should zero this memory, so lets allocate it
with kcalloc().
regards,
dan carpenter
next prev parent reply other threads:[~2025-08-12 14:31 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-12 13:32 [PATCH 0/5] net: use vmalloc_array() to simplify code Qianfeng Rong
2025-08-12 13:32 ` [PATCH 4/5] wifi: ath5k: " Qianfeng Rong
2025-08-12 13:32 ` [PATCH 5/5] wifi: mwifiex: " Qianfeng Rong
2025-08-12 13:48 ` Dan Carpenter
2025-08-12 14:13 ` Qianfeng Rong
2025-08-12 14:31 ` Dan Carpenter [this message]
2025-08-13 6:52 ` Qianfeng Rong
2025-08-13 9:25 ` Dan Carpenter
2025-08-13 18:35 ` Jeff Johnson
2025-08-14 6:24 ` Dan Carpenter
2025-08-12 20:48 ` [PATCH 0/5] net: " Jakub Kicinski
2025-08-13 1:53 ` Qianfeng Rong
2025-08-13 6:49 ` Qianfeng Rong
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=aJtQS-Tpzw90Hqtl@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=briannorris@chromium.org \
--cc=francesco@dolcini.it \
--cc=johannes.berg@intel.com \
--cc=kvalo@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=quic_adisi@quicinc.com \
--cc=quic_ramess@quicinc.com \
--cc=quic_rdevanat@quicinc.com \
--cc=rongqianfeng@vivo.com \
--cc=s.hauer@pengutronix.de \
/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