[PATCH] virtio: Check dev_set_name() return value

Bo Liu posted 1 patch 3 years, 9 months ago
drivers/virtio/virtio.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] virtio: Check dev_set_name() return value
Posted by Bo Liu 3 years, 9 months ago
It's possible that dev_set_name() returns -ENOMEM, catch and handle this.

Signed-off-by: Bo Liu <liubo03@inspur.com>
---
 drivers/virtio/virtio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 7deeed30d1f3..ddd4466da83b 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -428,7 +428,9 @@ int register_virtio_device(struct virtio_device *dev)
 		goto out;
 
 	dev->index = err;
-	dev_set_name(&dev->dev, "virtio%u", dev->index);
+	err = dev_set_name(&dev->dev, "virtio%u", dev->index);
+	if (err)
+		goto out_ida_remove;
 
 	err = virtio_device_of_init(dev);
 	if (err)
-- 
2.27.0
Re: [PATCH] virtio: Check dev_set_name() return value
Posted by Jason Wang 3 years, 9 months ago
On Thu, Jul 7, 2022 at 11:18 AM Bo Liu <liubo03@inspur.com> wrote:
>
> It's possible that dev_set_name() returns -ENOMEM, catch and handle this.
>
> Signed-off-by: Bo Liu <liubo03@inspur.com>

Acked-by: Jason Wang <jasowang@redhat.com>

> ---
>  drivers/virtio/virtio.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
> index 7deeed30d1f3..ddd4466da83b 100644
> --- a/drivers/virtio/virtio.c
> +++ b/drivers/virtio/virtio.c
> @@ -428,7 +428,9 @@ int register_virtio_device(struct virtio_device *dev)
>                 goto out;
>
>         dev->index = err;
> -       dev_set_name(&dev->dev, "virtio%u", dev->index);
> +       err = dev_set_name(&dev->dev, "virtio%u", dev->index);
> +       if (err)
> +               goto out_ida_remove;
>
>         err = virtio_device_of_init(dev);
>         if (err)
> --
> 2.27.0
>