lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160726193359-mutt-send-email-mst@kernel.org>
Date:	Tue, 26 Jul 2016 19:34:51 +0300
From:	"Michael S. Tsirkin" <mst@...hat.com>
To:	Stephen Hemminger <stephen@...workplumber.org>
Cc:	netdev@...r.kernel.org
Subject: Re: [PATCH net-next 3/3] virtio: use kcalloc and kmalloc_array

On Tue, Jul 26, 2016 at 09:20:11AM -0700, Stephen Hemminger wrote:
> Preferred style is to use kcalloc and kmalloc_array.
> 
> Signed-off-by: Stephen Hemminger <stephen@...workplumber.org>
> 
> --- a/drivers/net/virtio_net.c	2016-07-26 09:13:19.805400983 -0700
> +++ b/drivers/net/virtio_net.c	2016-07-26 09:13:19.801400965 -0700
> @@ -1551,13 +1551,13 @@ static int virtnet_find_vqs(struct virtn
>  		    virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ);
>  
>  	/* Allocate space for find_vqs parameters */
> -	vqs = kzalloc(total_vqs * sizeof(*vqs), GFP_KERNEL);
> +	vqs = kzalloc(total_vqs, sizeof(*vqs), GFP_KERNEL);

Does this  build? kzalloc seems to take only two arguments ... what
am I missing?


>  	if (!vqs)
>  		goto err_vq;
> -	callbacks = kmalloc(total_vqs * sizeof(*callbacks), GFP_KERNEL);
> +	callbacks = kmalloc_array(total_vqs, sizeof(*callbacks), GFP_KERNEL);
>  	if (!callbacks)
>  		goto err_callback;
> -	names = kmalloc(total_vqs * sizeof(*names), GFP_KERNEL);
> +	names = kmalloc_array(total_vqs, sizeof(*names), GFP_KERNEL);
>  	if (!names)
>  		goto err_names;
>  
> @@ -1613,10 +1613,10 @@ static int virtnet_alloc_queues(struct v
>  {
>  	int i;
>  
> -	vi->sq = kzalloc(sizeof(*vi->sq) * vi->max_queue_pairs, GFP_KERNEL);
> +	vi->sq = kcalloc(vi->max_queue_pairs, sizeof(*vi->sq), GFP_KERNEL);
>  	if (!vi->sq)
>  		goto err_sq;
> -	vi->rq = kzalloc(sizeof(*vi->rq) * vi->max_queue_pairs, GFP_KERNEL);
> +	vi->rq = kcalloc(vi->max_queue_pairs, sizeof(*vi->rq), GFP_KERNEL);
>  	if (!vi->rq)
>  		goto err_rq;
>  

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ