Re: [PATCH 3/4] sfc/siena: use kmalloc() to allocate logging buffer
From: Edward Cree
Date: Wed Jul 01 2026 - 13:02:55 EST
On 01/07/2026 14:57, Mike Rapoport (Microsoft) wrote:
> efx_siena_mcdi_init() allocates a logging buffer for MCDI firmware
> communication diagnostics.
>
> This buffer can be allocated with kmalloc() as there's nothing special
> about it to go directly to the page allocator.
>
> kmalloc() provides a better API that does not require ugly casts and
> kfree() does not need to know the size of the freed object.
>
> Performance difference between kmalloc() and __get_free_pages() is not
> measurable as both allocators take an object/page from a per-CPU list for
> fast path allocations.
>
> For the slow path the performance is anyway determined by the amount of
> reclaim involved rather than by what allocator is used.
>
> Replace use of __get_free_page() with kmalloc() and free_page() with
> kfree().
>
> Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@xxxxxxxxxx
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
Reviewed-by: Edward Cree <ecree.xilinx@xxxxxxxxx>
(resending since I hit 'reply' instead of 'reply all' the first time)
> ---
> drivers/net/ethernet/sfc/siena/mcdi.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/sfc/siena/mcdi.c b/drivers/net/ethernet/sfc/siena/mcdi.c
> index 4d0d6bd5d3d1..048c1e6017c0 100644
> --- a/drivers/net/ethernet/sfc/siena/mcdi.c
> +++ b/drivers/net/ethernet/sfc/siena/mcdi.c
> @@ -7,6 +7,7 @@
> #include <linux/delay.h>
> #include <linux/moduleparam.h>
> #include <linux/atomic.h>
> +#include <linux/slab.h>
> #include "net_driver.h"
> #include "nic.h"
> #include "io.h"
> @@ -73,7 +74,7 @@ int efx_siena_mcdi_init(struct efx_nic *efx)
> mcdi->efx = efx;
> #ifdef CONFIG_SFC_SIENA_MCDI_LOGGING
> /* consuming code assumes buffer is page-sized */
> - mcdi->logging_buffer = (char *)__get_free_page(GFP_KERNEL);
> + mcdi->logging_buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
> if (!mcdi->logging_buffer)
> goto fail1;
> mcdi->logging_enabled = efx_siena_mcdi_logging_default;
> @@ -116,7 +117,7 @@ int efx_siena_mcdi_init(struct efx_nic *efx)
> return 0;
> fail2:
> #ifdef CONFIG_SFC_SIENA_MCDI_LOGGING
> - free_page((unsigned long)mcdi->logging_buffer);
> + kfree(mcdi->logging_buffer);
> fail1:
> #endif
> kfree(efx->mcdi);
> @@ -142,7 +143,7 @@ void efx_siena_mcdi_fini(struct efx_nic *efx)
> return;
>
> #ifdef CONFIG_SFC_SIENA_MCDI_LOGGING
> - free_page((unsigned long)efx->mcdi->iface.logging_buffer);
> + kfree(efx->mcdi->iface.logging_buffer);
> #endif
>
> kfree(efx->mcdi);
>