diff mbox series

[ethtool,v2,02/13] ethtool: fix trivial issue in allocation

Message ID 20221208011122.2343363-3-jesse.brandeburg@intel.com (mailing list archive)
State Changes Requested
Delegated to: Michal Kubecek
Headers show
Series ethtool: clean up and fix | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Jesse Brandeburg Dec. 8, 2022, 1:11 a.m. UTC
Fix the following warning by changing the type being multiplied by to
the type being assigned to.

Description: Result of 'calloc' is converted to a pointer of type
'unsigned long', which is incompatible with sizeof operand type 'long'
File: /home/jbrandeb/git/ethtool/rxclass.c
Line: 527

Fixes: 5a3279e43f2b ("rxclass: Replace global rmgr with automatic variable/parameter")
Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
---
 rxclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Michal Kubecek Dec. 8, 2022, 8:26 a.m. UTC | #1
On Wed, Dec 07, 2022 at 05:11:11PM -0800, Jesse Brandeburg wrote:
> Fix the following warning by changing the type being multiplied by to
> the type being assigned to.
> 
> Description: Result of 'calloc' is converted to a pointer of type
> 'unsigned long', which is incompatible with sizeof operand type 'long'
> File: /home/jbrandeb/git/ethtool/rxclass.c
> Line: 527
> 
> Fixes: 5a3279e43f2b ("rxclass: Replace global rmgr with automatic variable/parameter")
> Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
> ---
>  rxclass.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/rxclass.c b/rxclass.c
> index 6cf81fdafc85..ebdd97960e5b 100644
> --- a/rxclass.c
> +++ b/rxclass.c
> @@ -524,7 +524,7 @@ static int rmgr_init(struct cmd_context *ctx, struct rmgr_ctrl *rmgr)
>  	}
>  
>  	/* initialize bitmap for storage of valid locations */
> -	rmgr->slot = calloc(1, BITS_TO_LONGS(rmgr->size) * sizeof(long));
> +	rmgr->slot = calloc(1, BITS_TO_LONGS(rmgr->size) * sizeof(unsigned long));

While at it, maybe we should take the cleanup one step further and use
sizeof(*rmgr->slot) or sizeof(rmgr->slot[0]) instead. And perhaps it
would also make sense to follow the logic of calloc() arguments and use

	calloc(BITS_TO_LONGS(rmgr->size), sizeof(rmgr->slot[0]))

Michal


>  	if (!rmgr->slot) {
>  		perror("rmgr: Cannot allocate memory for RX class rules");
>  		return -1;
> -- 
> 2.31.1
>
diff mbox series

Patch

diff --git a/rxclass.c b/rxclass.c
index 6cf81fdafc85..ebdd97960e5b 100644
--- a/rxclass.c
+++ b/rxclass.c
@@ -524,7 +524,7 @@  static int rmgr_init(struct cmd_context *ctx, struct rmgr_ctrl *rmgr)
 	}
 
 	/* initialize bitmap for storage of valid locations */
-	rmgr->slot = calloc(1, BITS_TO_LONGS(rmgr->size) * sizeof(long));
+	rmgr->slot = calloc(1, BITS_TO_LONGS(rmgr->size) * sizeof(unsigned long));
 	if (!rmgr->slot) {
 		perror("rmgr: Cannot allocate memory for RX class rules");
 		return -1;