Skip to content

Commit 99e1241

Browse files
Yang YingliangDominik Brodowski
authored andcommitted
pcmcia: ds: fix possible name leak in error path in pcmcia_device_add()
Afer commit 1fa5ae8 ("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: 1fa5ae8 ("driver core: get rid of struct device's bus_id string array") Signed-off-by: Yang Yingliang <[email protected]> [[email protected]: simplification, commit message modified] Signed-off-by: Dominik Brodowski <[email protected]>
1 parent 402ab97 commit 99e1241

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

drivers/pcmcia/ds.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,6 @@ static struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s,
513513
/* by default don't allow DMA */
514514
p_dev->dma_mask = 0;
515515
p_dev->dev.dma_mask = &p_dev->dma_mask;
516-
dev_set_name(&p_dev->dev, "%d.%d", p_dev->socket->sock, p_dev->device_no);
517-
if (!dev_name(&p_dev->dev))
518-
goto err_free;
519516
p_dev->devname = kasprintf(GFP_KERNEL, "pcmcia%s", dev_name(&p_dev->dev));
520517
if (!p_dev->devname)
521518
goto err_free;
@@ -573,6 +570,7 @@ static struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s,
573570

574571
pcmcia_device_query(p_dev);
575572

573+
dev_set_name(&p_dev->dev, "%d.%d", p_dev->socket->sock, p_dev->device_no);
576574
if (device_register(&p_dev->dev)) {
577575
mutex_lock(&s->ops_mutex);
578576
list_del(&p_dev->socket_device_list);

0 commit comments

Comments
 (0)