]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
pcmcia: ds: fix refcount leak in pcmcia_device_add()
authorYang Yingliang <yangyingliang@huawei.com>
Sat, 12 Nov 2022 09:29:23 +0000 (17:29 +0800)
committerDominik Brodowski <linux@dominikbrodowski.net>
Sun, 3 Sep 2023 08:14:48 +0000 (10:14 +0200)
As the comment of device_register() says, it should use put_device()
to give up the reference in the error path. Then, insofar resources
will be freed in pcmcia_release_dev(), the error path is no longer
needed. In particular, this means that the (previously missing) dropping
of the reference to &p_dev->function_config->ref is now handled by
pcmcia_release_dev().

Fixes: 360b65b95bae ("[PATCH] pcmcia: make config_t independent, add reference counting")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
[linux@dominikbrodowski.net: simplification, commit message rewrite]
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
drivers/pcmcia/ds.c

index d500e5dbbc3f5e45b6181efa67b1bd27cb04fa8b..c90c68dee1e45c95c1ebdc10b78643b5e74aee80 100644 (file)
@@ -573,8 +573,14 @@ static struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s,
 
        pcmcia_device_query(p_dev);
 
-       if (device_register(&p_dev->dev))
-               goto err_unreg;
+       if (device_register(&p_dev->dev)) {
+               mutex_lock(&s->ops_mutex);
+               list_del(&p_dev->socket_device_list);
+               s->device_count--;
+               mutex_unlock(&s->ops_mutex);
+               put_device(&p_dev->dev);
+               return NULL;
+       }
 
        return p_dev;