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>
Subject: [PATCH net-next 4/4] virtio_net: Allocate rss_hdr with devres
Date: Tue, 18 Mar 2025 18:56:54 +0900 [thread overview]
Message-ID: <20250318-virtio-v1-4-344caf336ddd@daynix.com> (raw)
In-Reply-To: <20250318-virtio-v1-0-344caf336ddd@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>
---
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 4153a0a5f278..6cbeba65a4a4 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 = kmalloc(virtnet_rss_hdr_size(vi), GFP_KERNEL);
+ vi->rss_hdr = devm_kmalloc(&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 = kmalloc(virtnet_rss_hdr_size(vi), GFP_KERNEL);
+ vi->rss_hdr = devm_kmalloc(&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-18 9:57 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-18 9:56 [PATCH net-next 0/4] virtio_net: Fixes and improvements Akihiko Odaki
2025-03-18 9:56 ` [PATCH net-next 1/4] virtio_net: Split struct virtio_net_rss_config Akihiko Odaki
2025-03-19 1:42 ` Jason Wang
2025-03-18 9:56 ` [PATCH net-next 2/4] virtio_net: Fix endian with virtio_net_ctrl_rss Akihiko Odaki
2025-03-19 1:43 ` Jason Wang
2025-03-18 9:56 ` [PATCH net-next 3/4] virtio_net: Use new RSS config structs Akihiko Odaki
2025-03-19 1:22 ` Xuan Zhuo
2025-03-19 4:46 ` Akihiko Odaki
2025-03-19 1:43 ` Jason Wang
2025-03-19 4:48 ` Akihiko Odaki
2025-03-20 1:50 ` Jason Wang
2025-03-20 5:36 ` Akihiko Odaki
2025-03-21 0:35 ` Jason Wang
2025-03-21 6:34 ` Akihiko Odaki
2025-03-24 4:05 ` Jason Wang
2025-03-18 9:56 ` Akihiko Odaki [this message]
2025-03-19 1:43 ` [PATCH net-next 4/4] virtio_net: Allocate rss_hdr with devres Jason Wang
2025-03-19 8:17 ` [PATCH net-next 0/4] virtio_net: Fixes and improvements Lei Yang
2025-03-19 9:07 ` Michael S. Tsirkin
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=20250318-virtio-v1-4-344caf336ddd@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=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
all inboxes | Powered by JetHome®