]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
virtio: Avoid repeating a long expression
authorSimon Glass <sjg@chromium.org>
Tue, 17 Jan 2023 17:47:48 +0000 (10:47 -0700)
committerTom Rini <trini@konsulko.com>
Mon, 23 Jan 2023 23:11:40 +0000 (18:11 -0500)
Use a local variable to hold this name, to reduce the amount of code that
needs to be read.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/virtio/virtio-uclass.c

index da4f2f26a632e51bbd19eb071fdcc45f13f94ca7..6d9b029390e06eb4ef14ff4bfefb98b0c5b58e4c 100644 (file)
@@ -214,6 +214,7 @@ static int virtio_uclass_post_probe(struct udevice *udev)
        struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(udev);
        char dev_name[30], *str;
        struct udevice *vdev;
+       const char *name;
        int ret;
 
        if (uc_priv->device >= VIRTIO_ID_MAX_NUM) {
@@ -222,20 +223,19 @@ static int virtio_uclass_post_probe(struct udevice *udev)
                return 0;
        }
 
-       if (!virtio_drv_name[uc_priv->device]) {
+       name = virtio_drv_name[uc_priv->device];
+       if (!name) {
                debug("(%s): underlying virtio device driver unavailable\n",
                      udev->name);
                return 0;
        }
 
-       snprintf(dev_name, sizeof(dev_name), "%s#%d",
-                virtio_drv_name[uc_priv->device], dev_seq(udev));
+       snprintf(dev_name, sizeof(dev_name), "%s#%d", name, dev_seq(udev));
        str = strdup(dev_name);
        if (!str)
                return -ENOMEM;
 
-       ret = device_bind_driver(udev, virtio_drv_name[uc_priv->device],
-                                str, &vdev);
+       ret = device_bind_driver(udev, name, str, &vdev);
        if (ret == -ENOENT) {
                debug("(%s): no driver configured\n", udev->name);
                return 0;