Skip to content

Commit

Permalink
mISDN: fix possible memory leak in mISDN_register_device()
Browse files Browse the repository at this point in the history
[ Upstream commit e7d1d4d ]

Afer commit 1fa5ae8 ("driver core: get rid of struct device's
bus_id string array"), the name of device is allocated dynamically,
add put_device() to give up the reference, so that the name can be
freed in kobject_cleanup() when the refcount is 0.

Set device class before put_device() to avoid null release() function
WARN message in device_release().

Fixes: 1fa5ae8 ("driver core: get rid of struct device's bus_id string array")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Yang Yingliang authored and gregkh committed Nov 10, 2022
1 parent 3e2129c commit 029d5b7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/isdn/mISDN/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,12 @@ mISDN_register_device(struct mISDNdevice *dev,
if (debug & DEBUG_CORE)
printk(KERN_DEBUG "mISDN_register %s %d\n",
dev_name(&dev->dev), dev->id);
dev->dev.class = &mISDN_class;

err = create_stack(dev);
if (err)
goto error1;

dev->dev.class = &mISDN_class;
dev->dev.platform_data = dev;
dev->dev.parent = parent;
dev_set_drvdata(&dev->dev, dev);
Expand All @@ -249,8 +250,8 @@ mISDN_register_device(struct mISDNdevice *dev,

error3:
delete_stack(dev);
return err;
error1:
put_device(&dev->dev);
return err;

}
Expand Down

0 comments on commit 029d5b7

Please sign in to comment.