]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
pcmcia: ds: fix possible name leak in error path in pcmcia_device_add()
authorYang Yingliang <yangyingliang@huawei.com>
Sat, 12 Nov 2022 09:29:24 +0000 (17:29 +0800)
committerDominik Brodowski <linux@dominikbrodowski.net>
Sun, 3 Sep 2023 08:27:19 +0000 (10:27 +0200)
Afer commit 1fa5ae857bb1 ("driver core: get rid of struct device's
bus_id string array"), the name of device is allocated dynamically.
Therefore, it needs to be freed, which is done by the driver core for
us once all references to the device are gone. Therefore, move the
dev_set_name() call immediately before the call device_register(), which
either succeeds (then the freeing will be done upon subsequent remvoal),
or puts the reference in the error call. Also, it is not unusual that the
return value of dev_set_name is not checked.

Fixes: 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
[linux@dominikbrodowski.net: simplification, commit message modified]
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
drivers/pcmcia/ds.c

index c90c68dee1e45c95c1ebdc10b78643b5e74aee80..b4b8363d1de21f3997ee6d7e5a3af65f169a56a5 100644 (file)
@@ -513,9 +513,6 @@ static struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s,
        /* by default don't allow DMA */
        p_dev->dma_mask = 0;
        p_dev->dev.dma_mask = &p_dev->dma_mask;
-       dev_set_name(&p_dev->dev, "%d.%d", p_dev->socket->sock, p_dev->device_no);
-       if (!dev_name(&p_dev->dev))
-               goto err_free;
        p_dev->devname = kasprintf(GFP_KERNEL, "pcmcia%s", dev_name(&p_dev->dev));
        if (!p_dev->devname)
                goto err_free;
@@ -573,6 +570,7 @@ static struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s,
 
        pcmcia_device_query(p_dev);
 
+       dev_set_name(&p_dev->dev, "%d.%d", p_dev->socket->sock, p_dev->device_no);
        if (device_register(&p_dev->dev)) {
                mutex_lock(&s->ops_mutex);
                list_del(&p_dev->socket_device_list);