diff mbox series

[net-next,v2,3/4] net: octeontx2: Use napi_alloc_frag_align() to avoid the memory waste

Message ID 20210131074426.44154-4-haokexin@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: Avoid the memory waste in some Ethernet drivers | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Kevin Hao Jan. 31, 2021, 7:44 a.m. UTC
The napi_alloc_frag_align() will guarantee that a correctly align
buffer address is returned. So use this function to simplify the buffer
alloc and avoid the unnecessary memory waste.

Signed-off-by: Kevin Hao <haokexin@gmail.com>
---
v2: No change.

 drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

sundeep subbaraya Feb. 1, 2021, 12:41 p.m. UTC | #1
Tested-by: Subbaraya Sundeep <sbhatta@marvell.com>

Thanks,
Sundeep

On Sun, Jan 31, 2021 at 1:49 PM Kevin Hao <haokexin@gmail.com> wrote:
>
> The napi_alloc_frag_align() will guarantee that a correctly align
> buffer address is returned. So use this function to simplify the buffer
> alloc and avoid the unnecessary memory waste.
>
> Signed-off-by: Kevin Hao <haokexin@gmail.com>
> ---
> v2: No change.
>
>  drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> index 5ddedc3b754d..cbd68fa9f1d6 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> @@ -488,11 +488,10 @@ dma_addr_t __otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool)
>         dma_addr_t iova;
>         u8 *buf;
>
> -       buf = napi_alloc_frag(pool->rbsize + OTX2_ALIGN);
> +       buf = napi_alloc_frag_align(pool->rbsize, OTX2_ALIGN);
>         if (unlikely(!buf))
>                 return -ENOMEM;
>
> -       buf = PTR_ALIGN(buf, OTX2_ALIGN);
>         iova = dma_map_single_attrs(pfvf->dev, buf, pool->rbsize,
>                                     DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
>         if (unlikely(dma_mapping_error(pfvf->dev, iova))) {
> --
> 2.29.2
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
index 5ddedc3b754d..cbd68fa9f1d6 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
@@ -488,11 +488,10 @@  dma_addr_t __otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool)
 	dma_addr_t iova;
 	u8 *buf;
 
-	buf = napi_alloc_frag(pool->rbsize + OTX2_ALIGN);
+	buf = napi_alloc_frag_align(pool->rbsize, OTX2_ALIGN);
 	if (unlikely(!buf))
 		return -ENOMEM;
 
-	buf = PTR_ALIGN(buf, OTX2_ALIGN);
 	iova = dma_map_single_attrs(pfvf->dev, buf, pool->rbsize,
 				    DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
 	if (unlikely(dma_mapping_error(pfvf->dev, iova))) {