2022-04-22 17:10:30

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] octeon_ep: Remove unnecessary cast

On Wed, 2022-04-20 at 09:47 +0800, Haowen Bai wrote:
> Fix the following coccicheck warning:
>
> ./drivers/net/ethernet/marvell/octeon_ep/octep_rx.c:161:18-40: WARNING:
> casting value returned by memory allocation function to (struct
> octep_rx_buffer *) is useless.
[]
> diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c
[]
> @@ -158,8 +158,7 @@ static int octep_setup_oq(struct octep_device *oct, int q_no)
> goto desc_dma_alloc_err;
> }
>
> - oq->buff_info = (struct octep_rx_buffer *)
> - vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE);
> + oq->buff_info = vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE);
> if (unlikely(!oq->buff_info)) {
> dev_err(&oct->pdev->dev,
> "Failed to allocate buffer info for OQ-%d\n", q_no);

probably better to use kvcalloc or maybe vcalloc if oq->max_count is
always expected to be huge.

OCTEP_OQ_RECVBUF_SIZE is pretty small (just a pointer and a u64).



2022-05-24 10:32:15

by baihaowen

[permalink] [raw]
Subject: [PATCH V2] octeon_ep: Remove unnecessary cast

Fix the following coccicheck warning:

./drivers/net/ethernet/marvell/octeon_ep/octep_rx.c:161:18-40: WARNING:
casting value returned by memory allocation function to (struct
octep_rx_buffer *) is useless.

Signed-off-by: Haowen Bai <[email protected]>
---
V1->V2: change vzalloc to vcalloc as suggestion.

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

diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c
index d9ae0937d17a..3c43f8078528 100644
--- a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c
+++ b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c
@@ -158,8 +158,7 @@ static int octep_setup_oq(struct octep_device *oct, int q_no)
goto desc_dma_alloc_err;
}

- oq->buff_info = (struct octep_rx_buffer *)
- vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE);
+ oq->buff_info = vcalloc(oq->max_count, OCTEP_OQ_RECVBUF_SIZE);
if (unlikely(!oq->buff_info)) {
dev_err(&oct->pdev->dev,
"Failed to allocate buffer info for OQ-%d\n", q_no);
--
2.7.4