virtio_ring: reject NULL recycle callback in reset/resize helpers
PATCH 1/1 virtio_ring: reject NULL recycle callback in reset/resize helpers
virtqueue_reset() and virtqueue_resize() rely on the recycle callback to release each detached unused buffer after disable_vq_and_reset().
As a defensive change, reject a NULL recycle callback explicitly to make this requirement clear. Update virtqueue_disable_and_recycle() to warn and return -EINVAL when @recycle is NULL, and update the descriptions for virtqueue_reset() and virtqueue_resize() to document that @recycle must not be %NULL.
--- drivers/virtio/virtio_ring.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/virtio/virtio_ring.c +5 -2
@@ -2698,6 +2698,9 @@ static int virtqueue_disable_and_recycle(struct virtqueue *_vq,void *buf;int err; +if (WARN_ON_ONCE (!recycle)) +return -EINVAL ; +if (!vq->we_own_ring)return -EPERM ;
@@ -3311,7 +3314,7 @@ EXPORT_SYMBOL_GPL(vring_create_virtqueue_map);* virtqueue_resize - resize the vring of vq * @_vq: the struct virtqueue we're talking about. * @num: new ring num -* @recycle: callback to recycle unused buffers +* @recycle: callback to recycle unused buffers, must not be %NULL * @recycle_done: callback to be invoked when recycle for all unused buffers done * * When it is really necessary to create a new vring, it will set the current vq
@@ -3367,7 +3370,7 @@ EXPORT_SYMBOL_GPL(virtqueue_resize);/** * virtqueue_reset - detach and recycle all unused buffers * @_vq: the struct virtqueue we're talking about. -* @recycle: callback to recycle unused buffers +* @recycle: callback to recycle unused buffers, must not be %NULL * @recycle_done: callback to be invoked when recycle for all unused buffers done * * Caller must ensure we don't call this with other virtqueue operations
Signature · 1 line
2.34.1
Michael S. Tsirkin
maintainerQuoted 8 lines · Shengwen Cheng
virtqueue_reset()andvirtqueue_resize()rely on the recycle callback to release each detached unused buffer afterdisable_vq_and_reset().As a defensive change, reject a NULL recycle callback explicitly to make this requirement clear. Update
virtqueue_disable_and_recycle()to warn and return-EINVALwhen @recycle is NULL, and update the descriptions forvirtqueue_reset()andvirtqueue_resize()to document that @recycle must not be %NULL.
I see little point in this change, sorry.
Quoted 38 lines
--- drivers/virtio/virtio_ring.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/virtio/virtio_ring.c +5
-2@@ -2698,6 +2698,9 @@ static int virtqueue_disable_and_recycle(struct virtqueue *_vq,void *buf;int err; +if (WARN_ON_ONCE (!recycle)) +return -EINVAL ; +if (!vq->we_own_ring)return -EPERM ;@@ -3311,7 +3314,7 @@ EXPORT_SYMBOL_GPL(vring_create_virtqueue_map);* virtqueue_resize - resize the vring of vq * @_vq: the struct virtqueue we're talking about. * @num: new ring num -* @recycle: callback to recycle unused buffers +* @recycle: callback to recycle unused buffers, must not be %NULL * @recycle_done: callback to be invoked when recycle for all unused buffers done * * When it is really necessary to create a new vring, it will set the current vq @@ -3367,7 +3370,7 @@ EXPORT_SYMBOL_GPL(virtqueue_resize);/** * virtqueue_reset - detach and recycle all unused buffers * @_vq: the struct virtqueue we're talking about. -* @recycle: callback to recycle unused buffers +* @recycle: callback to recycle unused buffers, must not be %NULL * @recycle_done: callback to be invoked when recycle for all unused buffers done * * Caller must ensure we don't call this with other virtqueue operations Signature · 1 line
2.34.1