Remove casting the values returned by memory allocation function.
Coccinelle emits WARNING:
./drivers/net/ethernet/cavium/liquidio/octeon_device.c:1155:14-36: WARNING:
casting value returned by memory allocation function to (struct octeon_dispatch *) is useless.
Signed-off-by: Wang Hai <redacted>
---
drivers/net/ethernet/cavium/liquidio/octeon_device.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
From: Joe Perches <joe@perches.com> Date: 2020-07-24 21:29:45
On Fri, 2020-07-24 at 21:00 +0800, Wang Hai wrote:
Remove casting the values returned by memory allocation function.
Coccinelle emits WARNING:
./drivers/net/ethernet/cavium/liquidio/octeon_device.c:1155:14-36: WARNING:
casting value returned by memory allocation function to (struct octeon_dispatch *) is useless.
More the question is why this is vmalloc at all
as the structure size is very small.
Likely this should just be kmalloc.
drivers/net/ethernet/cavium/liquidio/octeon_device.h:struct octeon_dispatch {
drivers/net/ethernet/cavium/liquidio/octeon_device.h- /** List head for this entry */
drivers/net/ethernet/cavium/liquidio/octeon_device.h- struct list_head list;
drivers/net/ethernet/cavium/liquidio/octeon_device.h-
drivers/net/ethernet/cavium/liquidio/octeon_device.h- /** The opcode for which the dispatch function & arg should be used */
drivers/net/ethernet/cavium/liquidio/octeon_device.h- u16 opcode;
drivers/net/ethernet/cavium/liquidio/octeon_device.h-
drivers/net/ethernet/cavium/liquidio/octeon_device.h- /** The function to be called for a packet received by the driver */
drivers/net/ethernet/cavium/liquidio/octeon_device.h- octeon_dispatch_fn_t dispatch_fn;
drivers/net/ethernet/cavium/liquidio/octeon_device.h-
drivers/net/ethernet/cavium/liquidio/octeon_device.h- /* The application specified argument to be passed to the above
drivers/net/ethernet/cavium/liquidio/octeon_device.h- * function along with the received packet
drivers/net/ethernet/cavium/liquidio/octeon_device.h- */
drivers/net/ethernet/cavium/liquidio/octeon_device.h- void *arg;
drivers/net/ethernet/cavium/liquidio/octeon_device.h-}
if (!dispatch) {
dev_err(&oct->pci_dev->dev,
"No memory to add dispatch function\n");
On Fri, 2020-07-24 at 21:00 +0800, Wang Hai wrote:
quoted
Remove casting the values returned by memory allocation function.
Coccinelle emits WARNING:
./drivers/net/ethernet/cavium/liquidio/octeon_device.c:1155:14-36: WARNING:
casting value returned by memory allocation function to (struct octeon_dispatch *) is useless.
From: Joe Perches <joe@perches.com> Date: 2020-07-28 09:11:31
On Tue, 2020-07-28 at 16:42 +0800, wanghai (M) wrote:
在 2020/7/25 5:29, Joe Perches 写道:
quoted
On Fri, 2020-07-24 at 21:00 +0800, Wang Hai wrote:
quoted
Remove casting the values returned by memory allocation function.
Coccinelle emits WARNING:
./drivers/net/ethernet/cavium/liquidio/octeon_device.c:1155:14-36: WARNING:
casting value returned by memory allocation function to (struct octeon_dispatch *) is useless.
On Tue, 2020-07-28 at 16:42 +0800, wanghai (M) wrote:
quoted
在 2020/7/25 5:29, Joe Perches 写道:
quoted
On Fri, 2020-07-24 at 21:00 +0800, Wang Hai wrote:
quoted
Remove casting the values returned by memory allocation function.
Coccinelle emits WARNING:
./drivers/net/ethernet/cavium/liquidio/octeon_device.c:1155:14-36: WARNING:
casting value returned by memory allocation function to (struct octeon_dispatch *) is useless.
*oct,
dev_dbg(&oct->pci_dev->dev,
"Adding opcode to dispatch list linked list\n");
- dispatch = (struct octeon_dispatch *)
- vmalloc(sizeof(struct octeon_dispatch));
+ dispatch = kmalloc(sizeof(struct octeon_dispatch),
GFP_KERNEL);
if (!dispatch) {
- dev_err(&oct->pci_dev->dev,
- "No memory to add dispatch function\n");
return 1;
}
dispatch->opcode = combined_opcode;
Yes, but the free also needs to be changed.
I think it's:
---
drivers/net/ethernet/cavium/liquidio/octeon_device.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
*oct,
dev_dbg(&oct->pci_dev->dev,
"Adding opcode to dispatch list linked list\n");
- dispatch = (struct octeon_dispatch *)
- vmalloc(sizeof(struct octeon_dispatch));
+ dispatch = kmalloc(sizeof(struct octeon_dispatch),
GFP_KERNEL);
if (!dispatch) {
- dev_err(&oct->pci_dev->dev,
- "No memory to add dispatch function\n");
return 1;
}
dispatch->opcode = combined_opcode;
Yes, but the free also needs to be changed.
I think it's:
---
drivers/net/ethernet/cavium/liquidio/octeon_device.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
@@ -1152,13 +1152,10 @@ octeon_register_dispatch_fn(struct octeon_device *oct,dev_dbg(&oct->pci_dev->dev,"Adding opcode to dispatch list linked list\n");-dispatch=(structocteon_dispatch*)-vmalloc(sizeof(structocteon_dispatch));-if(!dispatch){-dev_err(&oct->pci_dev->dev,-"No memory to add dispatch function\n");+dispatch=kmalloc(sizeof(structocteon_dispatch),GFP_KERNEL);+if(!dispatch)return1;-}+dispatch->opcode=combined_opcode;dispatch->dispatch_fn=fn;dispatch->arg=fn_arg;
.
Thanks for your suggestion. I just sent another patch for this.
"[PATCH net-next] liquidio: Replace vmalloc with kmalloc in
octeon_register_dispatch_fn()"