* [PATCH 0/5] net: use vmalloc_array() to simplify code
@ 2025-08-12 13:32 Qianfeng Rong
2025-08-12 13:32 ` [PATCH 4/5] wifi: ath5k: " Qianfeng Rong
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Qianfeng Rong @ 2025-08-12 13:32 UTC (permalink / raw)
To: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Jiri Slaby, Nick Kossifidis, Luis Chamberlain, Brian Norris,
Francesco Dolcini, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
Qianfeng Rong, Johannes Berg, Sascha Hauer, Kalle Valo,
Aditya Kumar Singh, Roopni Devanathan, Dan Carpenter,
moderated list:INTEL ETHERNET DRIVERS,
open list:NETWORKING DRIVERS, open list,
open list:NETRONOME ETHERNET DRIVERS,
open list:ATHEROS ATH5K WIRELESS DRIVER,
open list:XDP (eXpress Data Path):Keyword:(?:b|_)xdp(?:b|_)
Remove array_size() calls and replace vmalloc() with vmalloc_array() to
simplify the code and maintain consistency with existing kmalloc_array()
usage.
Compile-tested only.
Qianfeng Rong (5):
ethtool: use vmalloc_array() to simplify code
nfp: flower: use vmalloc_array() to simplify code
ppp: use vmalloc_array() to simplify
wifi: ath5k: use vmalloc_array() to simplify code
wifi: mwifiex: use vmalloc_array() to simplify code
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 2 +-
drivers/net/ethernet/intel/igb/igb_ethtool.c | 8 ++++----
drivers/net/ethernet/intel/igc/igc_ethtool.c | 8 ++++----
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 2 +-
drivers/net/ethernet/intel/ixgbevf/ethtool.c | 6 +++---
drivers/net/ethernet/netronome/nfp/flower/metadata.c | 4 ++--
drivers/net/ppp/bsd_comp.c | 4 ++--
drivers/net/wireless/ath/ath5k/debug.c | 2 +-
drivers/net/wireless/marvell/mwifiex/cfg80211.c | 4 ++--
9 files changed, 20 insertions(+), 20 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 4/5] wifi: ath5k: use vmalloc_array() to simplify code
2025-08-12 13:32 [PATCH 0/5] net: use vmalloc_array() to simplify code Qianfeng Rong
@ 2025-08-12 13:32 ` Qianfeng Rong
2025-08-12 13:32 ` [PATCH 5/5] wifi: mwifiex: " Qianfeng Rong
2025-08-12 20:48 ` [PATCH 0/5] net: " Jakub Kicinski
2 siblings, 0 replies; 13+ messages in thread
From: Qianfeng Rong @ 2025-08-12 13:32 UTC (permalink / raw)
To: Jiri Slaby, Nick Kossifidis, Luis Chamberlain,
open list:ATHEROS ATH5K WIRELESS DRIVER, open list
Cc: Qianfeng Rong
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/ath/ath5k/debug.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
index ec130510aeb2..91736f335210 100644
--- a/drivers/net/wireless/ath/ath5k/debug.c
+++ b/drivers/net/wireless/ath/ath5k/debug.c
@@ -912,7 +912,7 @@ static int open_file_eeprom(struct inode *inode, struct file *file)
/* Create buffer and read in eeprom */
- buf = vmalloc(array_size(eesize, 2));
+ buf = vmalloc_array(2, eesize);
if (!buf) {
ret = -ENOMEM;
goto err;
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 5/5] wifi: mwifiex: use vmalloc_array() to simplify code
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 ` Qianfeng Rong
2025-08-12 13:48 ` Dan Carpenter
2025-08-12 20:48 ` [PATCH 0/5] net: " Jakub Kicinski
2 siblings, 1 reply; 13+ messages in thread
From: Qianfeng Rong @ 2025-08-12 13:32 UTC (permalink / raw)
To: Brian Norris, Francesco Dolcini, Johannes Berg, Sascha Hauer,
Kalle Valo, Qianfeng Rong, Aditya Kumar Singh, Dan Carpenter,
Rameshkumar Sundaram, Roopni Devanathan,
open list:MARVELL MWIFIEX WIRELESS DRIVER, open list
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));
if (!adapter->chan_stats)
return -ENOMEM;
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 5/5] wifi: mwifiex: use vmalloc_array() to simplify code
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-13 18:35 ` Jeff Johnson
0 siblings, 2 replies; 13+ messages in thread
From: Dan Carpenter @ 2025-08-12 13:48 UTC (permalink / raw)
To: Qianfeng Rong
Cc: Brian Norris, Francesco Dolcini, Johannes Berg, Sascha Hauer,
Kalle Valo, Aditya Kumar Singh, Rameshkumar Sundaram,
Roopni Devanathan, open list:MARVELL MWIFIEX WIRELESS DRIVER,
open list
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().
regards,
dan carpenter
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 5/5] wifi: mwifiex: use vmalloc_array() to simplify code
2025-08-12 13:48 ` Dan Carpenter
@ 2025-08-12 14:13 ` Qianfeng Rong
2025-08-12 14:31 ` Dan Carpenter
2025-08-13 18:35 ` Jeff Johnson
1 sibling, 1 reply; 13+ messages in thread
From: Qianfeng Rong @ 2025-08-12 14:13 UTC (permalink / raw)
To: Dan Carpenter
Cc: Brian Norris, Francesco Dolcini, Johannes Berg, Sascha Hauer,
Kalle Valo, Aditya Kumar Singh, Rameshkumar Sundaram,
Roopni Devanathan, open list:MARVELL MWIFIEX WIRELESS DRIVER,
open list
在 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. 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.
Best regards,
Qianfeng
>
> regards,
> dan carpenter
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 5/5] wifi: mwifiex: use vmalloc_array() to simplify code
2025-08-12 14:13 ` Qianfeng Rong
@ 2025-08-12 14:31 ` Dan Carpenter
2025-08-13 6:52 ` Qianfeng Rong
0 siblings, 1 reply; 13+ messages in thread
From: Dan Carpenter @ 2025-08-12 14:31 UTC (permalink / raw)
To: Qianfeng Rong
Cc: Brian Norris, Francesco Dolcini, Johannes Berg, Sascha Hauer,
Kalle Valo, Aditya Kumar Singh, Rameshkumar Sundaram,
Roopni Devanathan, open list:MARVELL MWIFIEX WIRELESS DRIVER,
open list
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
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/5] net: use vmalloc_array() to simplify code
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 20:48 ` Jakub Kicinski
2025-08-13 1:53 ` Qianfeng Rong
2025-08-13 6:49 ` Qianfeng Rong
2 siblings, 2 replies; 13+ messages in thread
From: Jakub Kicinski @ 2025-08-12 20:48 UTC (permalink / raw)
To: Qianfeng Rong
Cc: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Jiri Slaby,
Nick Kossifidis, Luis Chamberlain, Brian Norris,
Francesco Dolcini, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
Johannes Berg, Sascha Hauer, Kalle Valo, Aditya Kumar Singh,
Roopni Devanathan, Dan Carpenter,
moderated list:INTEL ETHERNET DRIVERS,
open list:NETWORKING DRIVERS, open list,
open list:NETRONOME ETHERNET DRIVERS,
open list:ATHEROS ATH5K WIRELESS DRIVER,
open list:XDP (eXpress Data Path):Keyword:(?:b|_)xdp(?:b|_)
On Tue, 12 Aug 2025 21:32:13 +0800 Qianfeng Rong wrote:
> Remove array_size() calls and replace vmalloc() with vmalloc_array() to
> simplify the code and maintain consistency with existing kmalloc_array()
> usage.
You need to submit the first 3 as a separate series.
They get applied to a different tree than wireless patches.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/5] net: use vmalloc_array() to simplify code
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
1 sibling, 0 replies; 13+ messages in thread
From: Qianfeng Rong @ 2025-08-13 1:53 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Jiri Slaby,
Nick Kossifidis, Luis Chamberlain, Brian Norris,
Francesco Dolcini, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
Johannes Berg, Sascha Hauer, Kalle Valo, Aditya Kumar Singh,
Roopni Devanathan, Dan Carpenter,
moderated list:INTEL ETHERNET DRIVERS,
open list:NETWORKING DRIVERS, open list,
open list:NETRONOME ETHERNET DRIVERS,
open list:ATHEROS ATH5K WIRELESS DRIVER,
open list:XDP (eXpress Data Path):Keyword:(?:b|_)xdp(?:b|_)
在 2025/8/13 4:48, Jakub Kicinski 写道:
> On Tue, 12 Aug 2025 21:32:13 +0800 Qianfeng Rong wrote:
>> Remove array_size() calls and replace vmalloc() with vmalloc_array() to
>> simplify the code and maintain consistency with existing kmalloc_array()
>> usage.
> You need to submit the first 3 as a separate series.
> They get applied to a different tree than wireless patches.
Ok, Will do in the next version.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/5] net: use vmalloc_array() to simplify code
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
1 sibling, 0 replies; 13+ messages in thread
From: Qianfeng Rong @ 2025-08-13 6:49 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Jiri Slaby,
Nick Kossifidis, Luis Chamberlain, Brian Norris,
Francesco Dolcini, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
Johannes Berg, Sascha Hauer, Kalle Valo, Aditya Kumar Singh,
Roopni Devanathan, Dan Carpenter,
moderated list:INTEL ETHERNET DRIVERS,
open list:NETWORKING DRIVERS, open list,
open list:NETRONOME ETHERNET DRIVERS,
open list:ATHEROS ATH5K WIRELESS DRIVER,
open list:XDP (eXpress Data Path):Keyword:(?:b|_)xdp(?:b|_)
在 2025/8/13 4:48, Jakub Kicinski 写道:
> On Tue, 12 Aug 2025 21:32:13 +0800 Qianfeng Rong wrote:
>> Remove array_size() calls and replace vmalloc() with vmalloc_array() to
>> simplify the code and maintain consistency with existing kmalloc_array()
>> usage.
> You need to submit the first 3 as a separate series.
> They get applied to a different tree than wireless patches.
Ok,Will do in the next version.
Best regards,
Qianfeng
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 5/5] wifi: mwifiex: use vmalloc_array() to simplify code
2025-08-12 14:31 ` Dan Carpenter
@ 2025-08-13 6:52 ` Qianfeng Rong
2025-08-13 9:25 ` Dan Carpenter
0 siblings, 1 reply; 13+ messages in thread
From: Qianfeng Rong @ 2025-08-13 6:52 UTC (permalink / raw)
To: Dan Carpenter
Cc: Brian Norris, Francesco Dolcini, Johannes Berg, Sascha Hauer,
Kalle Valo, Aditya Kumar Singh, Rameshkumar Sundaram,
Roopni Devanathan, open list:MARVELL MWIFIEX WIRELESS DRIVER,
open list
在 2025/8/12 22:31, Dan Carpenter 写道:
> 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. ;)
Yes, I did find it. ;)
>> 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()
Allocations under 8 pages should use kmalloc() for efficiency. For
allocations exceeding 8 pages, kvmalloc() or vmalloc() is preferable
(of course, non-contiguous physical memory can be used) since
kernel memory management defines PAGE_ALLOC_COSTLY_ORDER = 3
(indicating 8 pages), beyond which contiguous physical memory
allocation becomes unreliable and costly.
>
> 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().
I agree with you, I will try to do this in the next version.
>
> regards,
> dan carpenter
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 5/5] wifi: mwifiex: use vmalloc_array() to simplify code
2025-08-13 6:52 ` Qianfeng Rong
@ 2025-08-13 9:25 ` Dan Carpenter
0 siblings, 0 replies; 13+ messages in thread
From: Dan Carpenter @ 2025-08-13 9:25 UTC (permalink / raw)
To: Qianfeng Rong
Cc: Brian Norris, Francesco Dolcini, Johannes Berg, Sascha Hauer,
Kalle Valo, Aditya Kumar Singh, Rameshkumar Sundaram,
Roopni Devanathan, open list:MARVELL MWIFIEX WIRELESS DRIVER,
open list
On Wed, Aug 13, 2025 at 02:52:51PM +0800, Qianfeng Rong wrote:
> >
> > I really think we should zero this memory, so lets allocate it
> > with kcalloc().
> I agree with you, I will try to do this in the next version.
Thanks. When you resend it make sure to add a Fixes tag and CC stable.
Forgetting to zero the memory is a sort of security issue.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 5/5] wifi: mwifiex: use vmalloc_array() to simplify code
2025-08-12 13:48 ` Dan Carpenter
2025-08-12 14:13 ` Qianfeng Rong
@ 2025-08-13 18:35 ` Jeff Johnson
2025-08-14 6:24 ` Dan Carpenter
1 sibling, 1 reply; 13+ messages in thread
From: Jeff Johnson @ 2025-08-13 18:35 UTC (permalink / raw)
To: Dan Carpenter, Qianfeng Rong
Cc: Brian Norris, Francesco Dolcini, Johannes Berg, Sascha Hauer,
Kalle Valo, Aditya Kumar Singh, Rameshkumar Sundaram,
Roopni Devanathan, open list:MARVELL MWIFIEX WIRELESS DRIVER,
open list
On 8/12/2025 6:48 AM, Dan Carpenter wrote:
> 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().
Should transition from v*() to k*() be separate from transition from *malloc()
to *malloc_array()?
/jeff
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 5/5] wifi: mwifiex: use vmalloc_array() to simplify code
2025-08-13 18:35 ` Jeff Johnson
@ 2025-08-14 6:24 ` Dan Carpenter
0 siblings, 0 replies; 13+ messages in thread
From: Dan Carpenter @ 2025-08-14 6:24 UTC (permalink / raw)
To: Jeff Johnson
Cc: Qianfeng Rong, Brian Norris, Francesco Dolcini, Johannes Berg,
Sascha Hauer, Kalle Valo, Aditya Kumar Singh,
Rameshkumar Sundaram, Roopni Devanathan,
open list:MARVELL MWIFIEX WIRELESS DRIVER, open list
On Wed, Aug 13, 2025 at 11:35:45AM -0700, Jeff Johnson wrote:
> On 8/12/2025 6:48 AM, Dan Carpenter wrote:
> > 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().
>
> Should transition from v*() to k*() be separate from transition from *malloc()
> to *malloc_array()?
It doesn't make sense to split this up. The right thing is kcalloc().
regards,
dan carpenter
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2025-08-14 6:24 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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).