* [PATCH] ice: switch: Simplify memory allocation
@ 2022-09-04 14:18 Christophe JAILLET
2022-09-06 10:45 ` [Intel-wired-lan] " Michal Swiatkowski
0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2022-09-04 14:18 UTC (permalink / raw)
To: Jesse Brandeburg, Tony Nguyen, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: linux-kernel, kernel-janitors, Christophe JAILLET,
intel-wired-lan, netdev
'rbuf' is locale to the ice_get_initial_sw_cfg() function.
There is no point in using devm_kzalloc()/devm_kfree().
use kzalloc()/kfree() instead.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
As a side effect, it also require less memory. devm_kzalloc() has a small
memory overhead, and requesting ICE_SW_CFG_MAX_BUF_LEN (i.e. 2048) bytes,
4096 are really allocated.
---
drivers/net/ethernet/intel/ice/ice_switch.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c
index 697feb89188c..eb6e19deb70d 100644
--- a/drivers/net/ethernet/intel/ice/ice_switch.c
+++ b/drivers/net/ethernet/intel/ice/ice_switch.c
@@ -2274,9 +2274,7 @@ int ice_get_initial_sw_cfg(struct ice_hw *hw)
int status;
u16 i;
- rbuf = devm_kzalloc(ice_hw_to_dev(hw), ICE_SW_CFG_MAX_BUF_LEN,
- GFP_KERNEL);
-
+ rbuf = kzalloc(ICE_SW_CFG_MAX_BUF_LEN, GFP_KERNEL);
if (!rbuf)
return -ENOMEM;
@@ -2324,7 +2322,7 @@ int ice_get_initial_sw_cfg(struct ice_hw *hw)
}
} while (req_desc && !status);
- devm_kfree(ice_hw_to_dev(hw), rbuf);
+ kfree(rbuf);
return status;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Intel-wired-lan] [PATCH] ice: switch: Simplify memory allocation
2022-09-04 14:18 [PATCH] ice: switch: Simplify memory allocation Christophe JAILLET
@ 2022-09-06 10:45 ` Michal Swiatkowski
0 siblings, 0 replies; 2+ messages in thread
From: Michal Swiatkowski @ 2022-09-06 10:45 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Jesse Brandeburg, Tony Nguyen, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, intel-wired-lan, kernel-janitors,
linux-kernel, netdev
On Sun, Sep 04, 2022 at 04:18:02PM +0200, Christophe JAILLET wrote:
> 'rbuf' is locale to the ice_get_initial_sw_cfg() function.
> There is no point in using devm_kzalloc()/devm_kfree().
>
> use kzalloc()/kfree() instead.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> As a side effect, it also require less memory. devm_kzalloc() has a small
> memory overhead, and requesting ICE_SW_CFG_MAX_BUF_LEN (i.e. 2048) bytes,
> 4096 are really allocated.
> ---
> drivers/net/ethernet/intel/ice/ice_switch.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c
> index 697feb89188c..eb6e19deb70d 100644
> --- a/drivers/net/ethernet/intel/ice/ice_switch.c
> +++ b/drivers/net/ethernet/intel/ice/ice_switch.c
> @@ -2274,9 +2274,7 @@ int ice_get_initial_sw_cfg(struct ice_hw *hw)
> int status;
> u16 i;
>
> - rbuf = devm_kzalloc(ice_hw_to_dev(hw), ICE_SW_CFG_MAX_BUF_LEN,
> - GFP_KERNEL);
> -
> + rbuf = kzalloc(ICE_SW_CFG_MAX_BUF_LEN, GFP_KERNEL);
> if (!rbuf)
> return -ENOMEM;
>
> @@ -2324,7 +2322,7 @@ int ice_get_initial_sw_cfg(struct ice_hw *hw)
> }
> } while (req_desc && !status);
>
> - devm_kfree(ice_hw_to_dev(hw), rbuf);
> + kfree(rbuf);
> return status;
> }
>
> --
> 2.34.1
>
Thanks for catching that
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
> _______________________________________________
> Intel-wired-lan mailing list
> Intel-wired-lan@osuosl.org
> https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-06 10:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-04 14:18 [PATCH] ice: switch: Simplify memory allocation Christophe JAILLET
2022-09-06 10:45 ` [Intel-wired-lan] " Michal Swiatkowski
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).