PNP: fix name memory leak in pnp_alloc_dev()
authorYang Yingliang <yangyingliang@huawei.com>
Fri, 11 Nov 2022 01:23:58 +0000 (09:23 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 08:26:10 +0000 (09:26 +0100)
[ Upstream commit 110d7b0325c55ff3620073ba4201845f59e22ebf ]

After commit 1fa5ae857bb1 ("driver core: get rid of struct device's
bus_id string array"), the name of device is allocated dynamically,
move dev_set_name() after pnp_add_id() to avoid memory leak.

Fixes: 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Hanjun Guo <guohanjun@huawei.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/pnp/core.c

index 3bf18d7189750f2970753aded98930b03f068621..131b925b820d22516ca15942a4d528d6db049eb8 100644 (file)
@@ -160,14 +160,14 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id,
        dev->dev.coherent_dma_mask = dev->dma_mask;
        dev->dev.release = &pnp_release_device;
 
-       dev_set_name(&dev->dev, "%02x:%02x", dev->protocol->number, dev->number);
-
        dev_id = pnp_add_id(dev, pnpid);
        if (!dev_id) {
                kfree(dev);
                return NULL;
        }
 
+       dev_set_name(&dev->dev, "%02x:%02x", dev->protocol->number, dev->number);
+
        return dev;
 }