From: Akihiko Odaki <akihiko.odaki@daynix.com>
To: "Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Andrew Melnychenko" <andrew@daynix.com>,
"Joe Damato" <jdamato@fastly.com>,
"Philo Lu" <lulie@linux.alibaba.com>
Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, devel@daynix.com,
Akihiko Odaki <akihiko.odaki@daynix.com>,
Lei Yang <leiyang@redhat.com>
Subject: [PATCH net-next v2 4/4] virtio_net: Allocate rss_hdr with devres
Date: Fri, 21 Mar 2025 15:48:35 +0900 [thread overview]
Message-ID: <20250321-virtio-v2-4-33afb8f4640b@daynix.com> (raw)
In-Reply-To: <20250321-virtio-v2-0-33afb8f4640b@daynix.com>
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: 86a48a00efdf ("virtio_net: Support dynamic rss indirection table size")
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Tested-by: Lei Yang <leiyang@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
---
drivers/net/virtio_net.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 570f77534dfb..6efec9c50b25 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -3580,7 +3580,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;
@@ -3591,7 +3591,7 @@ 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;
@@ -3599,7 +3599,7 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
queue_pairs);
return -EINVAL;
}
- kfree(old_rss_hdr);
+ devm_kfree(&dev->dev, old_rss_hdr);
goto succ;
}
@@ -6702,7 +6702,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;
@@ -6985,8 +6985,6 @@ static void virtnet_remove(struct virtio_device *vdev)
remove_vq_common(vi);
- kfree(vi->rss_hdr);
-
free_netdev(vi->dev);
}
--
2.48.1
next prev parent reply other threads:[~2025-03-21 6:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-21 6:48 [PATCH net-next v2 0/4] virtio_net: Fixes and improvements Akihiko Odaki
2025-03-21 6:48 ` [PATCH net-next v2 1/4] virtio_net: Split struct virtio_net_rss_config Akihiko Odaki
2025-03-21 6:48 ` [PATCH net-next v2 2/4] virtio_net: Fix endian with virtio_net_ctrl_rss Akihiko Odaki
2025-03-21 6:48 ` [PATCH net-next v2 3/4] virtio_net: Use new RSS config structs Akihiko Odaki
2025-03-24 4:01 ` Jason Wang
2025-03-21 6:48 ` Akihiko Odaki [this message]
2025-03-21 7:17 ` [PATCH net-next v2 0/4] virtio_net: Fixes and improvements Xuan Zhuo
2025-03-21 18:26 ` Michael S. Tsirkin
2025-03-24 14:38 ` Lei Yang
2025-03-25 16:40 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250321-virtio-v2-4-33afb8f4640b@daynix.com \
--to=akihiko.odaki@daynix.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@daynix.com \
--cc=davem@davemloft.net \
--cc=devel@daynix.com \
--cc=edumazet@google.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=jdamato@fastly.com \
--cc=kuba@kernel.org \
--cc=leiyang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lulie@linux.alibaba.com \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox