* [PATCH] octeon_ep: Remove unnecessary cast @ 2022-04-20 1:47 Haowen Bai 2022-04-20 2:07 ` Joe Perches 0 siblings, 1 reply; 5+ messages in thread From: Haowen Bai @ 2022-04-20 1:47 UTC (permalink / raw) To: Veerasenareddy Burru, Abhijit Ayarekar, David S. Miller, Jakub Kicinski, Paolo Abeni Cc: Haowen Bai, netdev, linux-kernel 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 <baihaowen@meizu.com> --- 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 945947ec7723..96768823cced 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 = 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); -- 2.7.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] octeon_ep: Remove unnecessary cast 2022-04-20 1:47 [PATCH] octeon_ep: Remove unnecessary cast Haowen Bai @ 2022-04-20 2:07 ` Joe Perches 2022-05-24 3:28 ` [PATCH V2] " Haowen Bai 0 siblings, 1 reply; 5+ messages in thread From: Joe Perches @ 2022-04-20 2:07 UTC (permalink / raw) To: Haowen Bai, Veerasenareddy Burru, Abhijit Ayarekar, David S. Miller, Jakub Kicinski, Paolo Abeni Cc: netdev, linux-kernel 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). ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH V2] octeon_ep: Remove unnecessary cast 2022-04-20 2:07 ` Joe Perches @ 2022-05-24 3:28 ` Haowen Bai 2022-05-24 3:48 ` Joe Perches 0 siblings, 1 reply; 5+ messages in thread From: Haowen Bai @ 2022-05-24 3:28 UTC (permalink / raw) To: joe Cc: aayarekar, baihaowen, davem, kuba, linux-kernel, netdev, pabeni, vburru 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 <baihaowen@meizu.com> --- 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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH V2] octeon_ep: Remove unnecessary cast 2022-05-24 3:28 ` [PATCH V2] " Haowen Bai @ 2022-05-24 3:48 ` Joe Perches 2022-05-24 3:51 ` baihaowen 0 siblings, 1 reply; 5+ messages in thread From: Joe Perches @ 2022-05-24 3:48 UTC (permalink / raw) To: Haowen Bai; +Cc: aayarekar, davem, kuba, linux-kernel, netdev, pabeni, vburru On Tue, 2022-05-24 at 11:28 +0800, Haowen Bai wrote: > ./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 = vcalloc(oq->max_count, OCTEP_OQ_RECVBUF_SIZE); trivia: Perhaps better to remove the used once #define OCTEP_OQ_RECVBUF_SIZE and use the more obvious oq->buff_info = vcalloc(oq->max_count, sizeof(struct octep_rx_buffer)); though I believe the vcalloc may be better as kvcalloc as max_count isn't particularly high and struct octep_rx_buffer is small. Maybe: --- drivers/net/ethernet/marvell/octeon_ep/octep_rx.c | 8 ++++---- drivers/net/ethernet/marvell/octeon_ep/octep_rx.h | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c index d9ae0937d17a8..d6a0da61db449 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c @@ -158,8 +158,8 @@ 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 = kvcalloc(oq->max_count, sizeof(struct octep_rx_buffer), + GFP_KERNEL); if (unlikely(!oq->buff_info)) { dev_err(&oct->pdev->dev, "Failed to allocate buffer info for OQ-%d\n", q_no); @@ -176,7 +176,7 @@ static int octep_setup_oq(struct octep_device *oct, int q_no) return 0; oq_fill_buff_err: - vfree(oq->buff_info); + kvfree(oq->buff_info); oq->buff_info = NULL; buf_list_err: dma_free_coherent(oq->dev, desc_ring_size, @@ -230,7 +230,7 @@ static int octep_free_oq(struct octep_oq *oq) octep_oq_free_ring_buffers(oq); - vfree(oq->buff_info); + kvfree(oq->buff_info); if (oq->desc_ring) dma_free_coherent(oq->dev, diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.h b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.h index 782a24f27f3e0..34a32d95cd4b3 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.h +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.h @@ -67,8 +67,6 @@ struct octep_rx_buffer { u64 len; }; -#define OCTEP_OQ_RECVBUF_SIZE (sizeof(struct octep_rx_buffer)) - /* Output Queue statistics. Each output queue has four stats fields. */ struct octep_oq_stats { /* Number of packets received from the Device. */ ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH V2] octeon_ep: Remove unnecessary cast 2022-05-24 3:48 ` Joe Perches @ 2022-05-24 3:51 ` baihaowen 0 siblings, 0 replies; 5+ messages in thread From: baihaowen @ 2022-05-24 3:51 UTC (permalink / raw) To: Joe Perches; +Cc: aayarekar, davem, kuba, linux-kernel, netdev, pabeni, vburru 在 2022/5/24 上午11:48, Joe Perches 写道: > On Tue, 2022-05-24 at 11:28 +0800, Haowen Bai wrote: >> ./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 = vcalloc(oq->max_count, OCTEP_OQ_RECVBUF_SIZE); > trivia: > > Perhaps better to remove the used once #define OCTEP_OQ_RECVBUF_SIZE > and use the more obvious > > oq->buff_info = vcalloc(oq->max_count, sizeof(struct octep_rx_buffer)); > > though I believe the vcalloc may be better as kvcalloc as max_count isn't > particularly high and struct octep_rx_buffer is small. > > Maybe: > --- > drivers/net/ethernet/marvell/octeon_ep/octep_rx.c | 8 ++++---- > drivers/net/ethernet/marvell/octeon_ep/octep_rx.h | 2 -- > 2 files changed, 4 insertions(+), 6 deletions(-) > > diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c > index d9ae0937d17a8..d6a0da61db449 100644 > --- a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c > +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c > @@ -158,8 +158,8 @@ 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 = kvcalloc(oq->max_count, sizeof(struct octep_rx_buffer), > + GFP_KERNEL); > if (unlikely(!oq->buff_info)) { > dev_err(&oct->pdev->dev, > "Failed to allocate buffer info for OQ-%d\n", q_no); > @@ -176,7 +176,7 @@ static int octep_setup_oq(struct octep_device *oct, int q_no) > return 0; > > oq_fill_buff_err: > - vfree(oq->buff_info); > + kvfree(oq->buff_info); > oq->buff_info = NULL; > buf_list_err: > dma_free_coherent(oq->dev, desc_ring_size, > @@ -230,7 +230,7 @@ static int octep_free_oq(struct octep_oq *oq) > > octep_oq_free_ring_buffers(oq); > > - vfree(oq->buff_info); > + kvfree(oq->buff_info); > > if (oq->desc_ring) > dma_free_coherent(oq->dev, > diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.h b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.h > index 782a24f27f3e0..34a32d95cd4b3 100644 > --- a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.h > +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.h > @@ -67,8 +67,6 @@ struct octep_rx_buffer { > u64 len; > }; > > -#define OCTEP_OQ_RECVBUF_SIZE (sizeof(struct octep_rx_buffer)) > - > /* Output Queue statistics. Each output queue has four stats fields. */ > struct octep_oq_stats { > /* Number of packets received from the Device. */ > > Good work, thanks for suggestion. -- Haowen Bai suggestionSynonymsBetasuggestion (noun)idea(generic)thought(generic)suggestion (noun)propositionprofferproposal(generic)suggestion (noun)tracehintsmall indefinite quantity(generic)small indefinite amount(generic)Source: WordNetLanguageToolbasic ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-05-24 3:51 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-04-20 1:47 [PATCH] octeon_ep: Remove unnecessary cast Haowen Bai 2022-04-20 2:07 ` Joe Perches 2022-05-24 3:28 ` [PATCH V2] " Haowen Bai 2022-05-24 3:48 ` Joe Perches 2022-05-24 3:51 ` baihaowen
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.