From: Yige Jiang <yigejiang86@gmail.com>
To: "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowangio@gmail.com>
Cc: "Yige Jiang" <yigejiang86@gmail.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
virtualization@lists.linux.dev, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, "Francesco Valla" <francesco@valla.it>,
sashiko-bot <sashiko-bot@kernel.org>
Subject: [PATCH] virtio: Release the OF node when unregistering the device
Date: Thu, 19 Nov 2026 18:06:06 +0800 [thread overview]
Message-ID: <20261119085343.virtio-of-node-a02bd3cf522b@gmail.com> (raw)
virtio_device_of_init() acquires the OF node reference once during device
registration. virtio_dev_remove() currently puts it on each driver unbind,
although rebinding the driver does not acquire a new reference. Repeated
unbinds can therefore consume references not owned by the virtio device.
Conversely, unregistering a device that never bound to a driver leaves
the reference held.
Move the put to unregister_virtio_device() so it is paired with device
registration. Save the node pointer before device_unregister(), which
can free the virtio device, and put it after unregister has completed the
driver removal.
Fixes: 694a1116b405 ("virtio: Bind virtio device to device-tree node")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Link: https://lore.kernel.org/all/sashiko-outbox-203883@kernel.org/
Cc: stable@vger.kernel.org
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
AI assistance was used for analysis and patch preparation.
Based on next-20261104 (8b7179210b22).
The same OF node mismatch was independently noted in the linked review.
Compile-tested on 2026-11-05: arm64, GCC 14.2.0, W=1,
drivers/virtio/virtio.o; baseline and patched objects built without warnings.
The code diff is unchanged from that tested version; this refresh adds
the public report attribution and updates the mail headers.
On 2026-11-19 the patch also applies to the identical virtio.c in mainline
4405c18c95d2. No new build, hardware, boot, or KASAN test was performed.
drivers/virtio/virtio.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index a8588d7ad109f1d65135dc7394b1dd4ae04978f1..c8be1a3f479d6abf1249f5fde66b6c93cb260d0d 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -381,8 +381,6 @@ static void virtio_dev_remove(struct device *_d)
/* Acknowledge the device's existence again. */
virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
-
- of_node_put(dev->dev.of_node);
}
/*
@@ -604,10 +602,12 @@ EXPORT_SYMBOL_GPL(is_virtio_device);
void unregister_virtio_device(struct virtio_device *dev)
{
+ struct device_node *np = dev->dev.of_node;
int index = dev->index; /* save for after device release */
virtio_debug_device_exit(dev);
device_unregister(&dev->dev);
+ of_node_put(np);
ida_free(&virtio_index_ida, index);
}
EXPORT_SYMBOL_GPL(unregister_virtio_device);
base-commit: 8b7179210b22f8e48a82c5ceacb9d56a9c4cfec4
reply other threads:[~2026-11-19 10:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261119085343.virtio-of-node-a02bd3cf522b@gmail.com \
--to=yigejiang86@gmail.com \
--cc=eperezma@redhat.com \
--cc=francesco@valla.it \
--cc=jasowangio@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=stable@vger.kernel.org \
--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