liquidio: Remove unneeded cast from memory allocation
Subsystems (3)
PATCH 1/1 liquidio: Remove unneeded cast from memory allocation
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.
--- drivers/net/ethernet/cavium/liquidio/octeon_device.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/cavium/liquidio/octeon_device.c +1 -2
@@ -1152,8 +1152,7 @@ octeon_register_dispatch_fn(struct octeon_device *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 =vmalloc (sizeof (struct octeon_dispatch ));if (!dispatch) {dev_err (&oct->pci_dev->dev,"No memory to add dispatch function\n" );
Signature · 1 line
2.17.1
Quoted 6 lines · Wang Hai
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 (structocteon_dispatch*) is useless.
[]
drivers/net/ethernet/cavium/liquidio/octeon_device.c
Quoted 1 line
drivers/net/ethernet/cavium/liquidio/octeon_device.c +0
-0
[]
drivers/net/ethernet/cavium/liquidio/octeon_device.c octeon_register_dispatch_fn(struct octeon_device *oct, · line 1155
Quoted 7 lines
drivers/net/ethernet/cavium/liquidio/octeon_device.c +1
-2@@ -1152,8 +1152,7 @@ octeon_register_dispatch_fn(struct octeon_device *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 =vmalloc (sizeof (struct octeon_dispatch ));
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 abovedrivers/net/ethernet/cavium/liquidio/octeon_device.h- * function along with the received packetdrivers/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-}
drivers/net/ethernet/cavium/liquidio/octeon_device.c octeon_register_dispatch_fn(struct octeon_device *oct, · line 1158
Quoted 3 lines
drivers/net/ethernet/cavium/liquidio/octeon_device.c +0
-0if (!dispatch) {dev_err (&oct->pci_dev->dev,"No memory to add dispatch function\n" );
And this dev_err is unnecessary.
Quoted 20 lines · Joe Perches
Quoted 6 lines · Wang Hai
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 (structocteon_dispatch*) is useless.[]
drivers/net/ethernet/cavium/liquidio/octeon_device.c
Quoted 1 line
drivers/net/ethernet/cavium/liquidio/octeon_device.c +0
-0[]
drivers/net/ethernet/cavium/liquidio/octeon_device.c octeon_register_dispatch_fn(struct octeon_device *oct, · line 1155
Quoted 7 lines
drivers/net/ethernet/cavium/liquidio/octeon_device.c +1
-2@@ -1152,8 +1152,7 @@ octeon_register_dispatch_fn(struct octeon_device *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 =vmalloc (sizeof (struct octeon_dispatch ));More the question is why this is vmalloc at all
as the structure size is very small.
Quoted 3 lines
Likely this should just be kmalloc.
Thanks for your advice. It is indeed best to use kmalloc here.
Quoted 6 lines
drivers/net/ethernet/cavium/liquidio/octeon_device.c octeon_register_dispatch_fn(struct octeon_device *oct, · line 1158
Quoted 3 lines
drivers/net/ethernet/cavium/liquidio/octeon_device.c +0
-0if (!dispatch) {dev_err (&oct->pci_dev->dev,"No memory to add dispatch function\n" );And this
dev_erris unnecessary.
I don't understand why dev_err is not needed here. We can easily know that an error has occurred here through dev_err
Quoted 2 lines
.
Quoted 25 lines · wanghai (M)
Quoted 20 lines · Joe Perches
Quoted 6 lines · Wang Hai
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 (structocteon_dispatch*) is useless.[]
drivers/net/ethernet/cavium/liquidio/octeon_device.c
Quoted 1 line
drivers/net/ethernet/cavium/liquidio/octeon_device.c +0
-0[]
drivers/net/ethernet/cavium/liquidio/octeon_device.c octeon_register_dispatch_fn(struct octeon_device *oct, · line 1155
Quoted 7 lines
drivers/net/ethernet/cavium/liquidio/octeon_device.c +1
-2@@ -1152,8 +1152,7 @@ octeon_register_dispatch_fn(struct octeon_device *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 =vmalloc (sizeof (struct octeon_dispatch ));More the question is why this is vmalloc at all
as the structure size is very small.Quoted 3 lines
Likely this should just be kmalloc.
Thanks for your advice. It is indeed best to use kmalloc here.
Quoted 8 lines
Quoted 6 lines
drivers/net/ethernet/cavium/liquidio/octeon_device.c octeon_register_dispatch_fn(struct octeon_device *oct, · line 1158
Quoted 3 lines
drivers/net/ethernet/cavium/liquidio/octeon_device.c +0
-0if (!dispatch) {dev_err (&oct->pci_dev->dev,"No memory to add dispatch function\n" );And this
dev_erris unnecessary.I don't understand why
dev_erris not needed here. We can easily know that an error has occurred here throughdev_err
Memory allocation failures without __GFP_NOWARN. already do a dump_stack to show the location of the code that could not successfully allocate memory.
Quoted 29 lines · Joe Perches
Quoted 28 lines · wanghai (M)
Quoted 20 lines · Joe Perches
Quoted 6 lines · Wang Hai
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 (structocteon_dispatch*) is useless.[]
drivers/net/ethernet/cavium/liquidio/octeon_device.c
Quoted 1 line
drivers/net/ethernet/cavium/liquidio/octeon_device.c +0
-0[]
drivers/net/ethernet/cavium/liquidio/octeon_device.c octeon_register_dispatch_fn(struct octeon_device *oct, · line 1155
Quoted 7 lines
drivers/net/ethernet/cavium/liquidio/octeon_device.c +1
-2@@ -1152,8 +1152,7 @@ octeon_register_dispatch_fn(struct octeon_device *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 =vmalloc (sizeof (struct octeon_dispatch ));More the question is why this is vmalloc at all
as the structure size is very small.Quoted 3 lines
Likely this should just be kmalloc.
Thanks for your advice. It is indeed best to use kmalloc here.
Quoted 3 lines
Quoted 3 lines
drivers/net/ethernet/cavium/liquidio/octeon_device.c +0
-0if (!dispatch) {dev_err (&oct->pci_dev->dev,"No memory to add dispatch function\n" );
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines
And this
dev_erris unnecessary.I don't understand why
dev_erris not needed here. We can easily know that an error has occurred here throughdev_errMemory allocation failures without
__GFP_NOWARN. already do adump_stackto show the location of the code that could not successfully allocate memory.
Thanks for your explanation. I got it.
Can it be modified like this?
drivers/net/ethernet/cavium/liquidio/octeon_device.c +0 -0
@@ -1152,11 +1152,8 @@ octeon_register_dispatch_fn(struct octeon_device *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;
Quoted 2 lines
.
Quoted 3 lines · wanghai (M)
Thanks for your explanation. I got it.
Can it be modified like this?
[]
Quoted 14 lines
+++
b/drivers/net/ethernet/cavium/liquidio/octeon_device.c(quoted diff) +1
-4@@ -1152,11 +1152,8 @@ octeon_register_dispatch_fn(struct octeon_device *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;
Quoted 2 lines
}
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(-)
drivers/net/ethernet/cavium/liquidio/octeon_device.c +4 -7
@@ -1056,7 +1056,7 @@ void octeon_delete_dispatch_list(struct octeon_device *oct)list_for_each_safe (temp, tmp2, &freelist) {list_del (temp); -vfree (temp); +kfree (temp); } }
@@ -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 = (struct octeon_dispatch *) -vmalloc (sizeof (struct octeon_dispatch )); -if (!dispatch) { -dev_err (&oct->pci_dev->dev, -"No memory to add dispatch function\n" ); + dispatch =kmalloc (sizeof (struct octeon_dispatch ),GFP_KERNEL ); +if (!dispatch)return 1 ; - } + dispatch->opcode = combined_opcode; dispatch->dispatch_fn = fn; dispatch->arg = fn_arg;
Quoted 61 lines · Joe Perches
Quoted 3 lines · wanghai (M)
Thanks for your explanation. I got it.
Can it be modified like this?
[]
Quoted 14 lines
+++
b/drivers/net/ethernet/cavium/liquidio/octeon_device.cdrivers/net/ethernet/cavium/liquidio/octeon_device.c +1
-4@@ -1152,11 +1152,8 @@ octeon_register_dispatch_fn(struct octeon_device *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 ;Quoted 2 lines
} 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(-)drivers/net/ethernet/cavium/liquidio/octeon_device.c +4
-7@@ -1056,7 +1056,7 @@ void octeon_delete_dispatch_list(struct octeon_device *oct)list_for_each_safe (temp, tmp2, &freelist) {list_del (temp); -vfree (temp); +kfree (temp); } }@@ -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 = (struct octeon_dispatch *) -vmalloc (sizeof (struct octeon_dispatch )); -if (!dispatch) { -dev_err (&oct->pci_dev->dev, -"No memory to add dispatch function\n" ); + dispatch =kmalloc (sizeof (struct octeon_dispatch ),GFP_KERNEL ); +if (!dispatch)return 1 ; - } + dispatch->opcode = combined_opcode; dispatch->dispatch_fn = fn; dispatch->arg = fn_arg;
Quoted 1 line
.
Thanks for your suggestion. I just sent another patch for this.
"[PATCH net-next] liquidio: Replace vmalloc with kmalloc in octeon_register_dispatch_fn()"