Skip to content

Commit

Permalink
virtio_net: Allocate rss_hdr with devres
Browse files Browse the repository at this point in the history
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 <akihiko.odaki@daynix.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Lei Yang <leiyang@redhat.com>
Link: https://patch.msgid.link/20250321-virtio-v2-4-33afb8f4640b@daynix.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Akihiko Odaki authored and Jakub Kicinski committed Mar 25, 2025
1 parent ed3100e commit 4944be2
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -3642,7 +3642,7 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
if (vi->has_rss && !netif_is_rxfh_configured(dev)) {
old_rss_hdr = vi->rss_hdr;
old_rss_trailer = vi->rss_trailer;
vi->rss_hdr = kzalloc(virtnet_rss_hdr_size(vi), GFP_KERNEL);
vi->rss_hdr = devm_kzalloc(&dev->dev, virtnet_rss_hdr_size(vi), GFP_KERNEL);
if (!vi->rss_hdr) {
vi->rss_hdr = old_rss_hdr;
return -ENOMEM;
Expand All @@ -3653,15 +3653,15 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)

if (!virtnet_commit_rss_command(vi)) {
/* restore ctrl_rss if commit_rss_command failed */
kfree(vi->rss_hdr);
devm_kfree(&dev->dev, vi->rss_hdr);
vi->rss_hdr = old_rss_hdr;
vi->rss_trailer = old_rss_trailer;

dev_warn(&dev->dev, "Fail to set num of queue pairs to %d, because committing RSS failed\n",
queue_pairs);
return -EINVAL;
}
kfree(old_rss_hdr);
devm_kfree(&dev->dev, old_rss_hdr);
goto succ;
}

Expand Down Expand Up @@ -6768,7 +6768,7 @@ static int virtnet_probe(struct virtio_device *vdev)
virtio_cread16(vdev, offsetof(struct virtio_net_config,
rss_max_indirection_table_length));
}
vi->rss_hdr = kzalloc(virtnet_rss_hdr_size(vi), GFP_KERNEL);
vi->rss_hdr = devm_kzalloc(&vdev->dev, virtnet_rss_hdr_size(vi), GFP_KERNEL);
if (!vi->rss_hdr) {
err = -ENOMEM;
goto free;
Expand Down Expand Up @@ -7051,8 +7051,6 @@ static void virtnet_remove(struct virtio_device *vdev)

remove_vq_common(vi);

kfree(vi->rss_hdr);

free_netdev(vi->dev);
}

Expand Down

0 comments on commit 4944be2

Please sign in to comment.