Subject: Re: [PATCH net-next v8 1/8] net: ethtool: pass a pointer to parameters to get/set_rxfh ethtool ops

From: Jakub Kicinski <[email-masked]>
Date: Fri, 8 Dec 2023 17:57:03 -0800

On Wed,  6 Dec 2023 16:36:35 -0700 Ahmed Zaki wrote:
> -	rxfh.indir_size = dev_indir_size;
> -	rxfh.key_size = dev_key_size;
> +	rxfh.indir_size = rxfh_dev.indir_size;
> +	rxfh.key_size = rxfh_dev.key_size;
>  	if (copy_to_user(useraddr, &rxfh, sizeof(rxfh)))
>  		return -EFAULT;
>  
> -	if ((user_indir_size && (user_indir_size != dev_indir_size)) ||
> -	    (user_key_size && (user_key_size != dev_key_size)))
> +	if ((user_indir_size && user_indir_size != rxfh_dev.indir_size) ||
> +	    (user_key_size && user_key_size != rxfh_dev.key_size))
>  		return -EINVAL;
>  
> -	indir_bytes = user_indir_size * sizeof(indir[0]);
> -	total_size = indir_bytes + user_key_size;
> -	rss_config = kzalloc(total_size, GFP_USER);
> -	if (!rss_config)
> -		return -ENOMEM;
> -
> -	if (user_indir_size)
> -		indir = (u32 *)rss_config;
> +	indir_bytes = user_indir_size * sizeof(*rxfh_dev.indir);
> +	if (indir_bytes) {
> +		rxfh_dev.indir = kzalloc(indir_bytes, GFP_KERNEL);
> +		if (!rxfh_dev.indir)
> +			return -ENOMEM;
> +	}
>  
> -	if (user_key_size)
> -		hkey = rss_config + indir_bytes;
> +	if (user_key_size) {
> +		rxfh_dev.key = kzalloc(user_key_size, GFP_KERNEL);
> +		if (!rxfh_dev.key) {
> +			kfree(rxfh_dev.indir);
> +			return -ENOMEM;
> +		}
> +	}

Splitting the allocation into two separate kzalloc()s should be 
a separate change.

> +struct ethtool_rxfh_param {
> +	__u8	hfunc;
> +	__u32   indir_size;
> +	__u32	*indir;
> +	__u32   key_size;
> +	__u8	*key;
> +};

no underscores needed on types, this is a kernel struct