Skip to content

Commit 4944be2

Browse files
akihikodakikuba-moo
authored andcommitted
virtio_net: Allocate rss_hdr with devres
virtnet_probe() lacks the code to free rss_hdr in its error path. Allocate rss_hdr with devres so that it will be automatically freed. Fixes: 86a48a0 ("virtio_net: Support dynamic rss indirection table size") Signed-off-by: Akihiko Odaki <[email protected]> Acked-by: Jason Wang <[email protected]> Reviewed-by: Xuan Zhuo <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Tested-by: Lei Yang <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent ed3100e commit 4944be2

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

drivers/net/virtio_net.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3642,7 +3642,7 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
36423642
if (vi->has_rss && !netif_is_rxfh_configured(dev)) {
36433643
old_rss_hdr = vi->rss_hdr;
36443644
old_rss_trailer = vi->rss_trailer;
3645-
vi->rss_hdr = kzalloc(virtnet_rss_hdr_size(vi), GFP_KERNEL);
3645+
vi->rss_hdr = devm_kzalloc(&dev->dev, virtnet_rss_hdr_size(vi), GFP_KERNEL);
36463646
if (!vi->rss_hdr) {
36473647
vi->rss_hdr = old_rss_hdr;
36483648
return -ENOMEM;
@@ -3653,15 +3653,15 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
36533653

36543654
if (!virtnet_commit_rss_command(vi)) {
36553655
/* restore ctrl_rss if commit_rss_command failed */
3656-
kfree(vi->rss_hdr);
3656+
devm_kfree(&dev->dev, vi->rss_hdr);
36573657
vi->rss_hdr = old_rss_hdr;
36583658
vi->rss_trailer = old_rss_trailer;
36593659

36603660
dev_warn(&dev->dev, "Fail to set num of queue pairs to %d, because committing RSS failed\n",
36613661
queue_pairs);
36623662
return -EINVAL;
36633663
}
3664-
kfree(old_rss_hdr);
3664+
devm_kfree(&dev->dev, old_rss_hdr);
36653665
goto succ;
36663666
}
36673667

@@ -6768,7 +6768,7 @@ static int virtnet_probe(struct virtio_device *vdev)
67686768
virtio_cread16(vdev, offsetof(struct virtio_net_config,
67696769
rss_max_indirection_table_length));
67706770
}
6771-
vi->rss_hdr = kzalloc(virtnet_rss_hdr_size(vi), GFP_KERNEL);
6771+
vi->rss_hdr = devm_kzalloc(&vdev->dev, virtnet_rss_hdr_size(vi), GFP_KERNEL);
67726772
if (!vi->rss_hdr) {
67736773
err = -ENOMEM;
67746774
goto free;
@@ -7051,8 +7051,6 @@ static void virtnet_remove(struct virtio_device *vdev)
70517051

70527052
remove_vq_common(vi);
70537053

7054-
kfree(vi->rss_hdr);
7055-
70567054
free_netdev(vi->dev);
70577055
}
70587056

0 commit comments

Comments
 (0)