Skip to content

Commit

Permalink
drivers: dio: fix possible memory leak in dio_init()
Browse files Browse the repository at this point in the history
[ Upstream commit e63e99397b2613d50a5f4f02ed07307e67a190f1 ]

If device_register() returns error, the 'dev' and name needs be
freed. Add a release function, and then call put_device() in the
error path, so the name is freed in kobject_cleanup() and to the
'dev' is freed in release function.

Fixes: 2e4c77b ("m68k: dio - Kill warn_unused_result warnings")
Fixes: 1fa5ae8 ("driver core: get rid of struct device's bus_id string array")
Signed-off-by: Yang Yingliang <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Yang Yingliang authored and gregkh committed Jan 7, 2023
1 parent 2aecfec commit affe3ce
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/dio/dio.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ static char dio_no_name[] = { 0 };

#endif /* CONFIG_DIO_CONSTANTS */

static void dio_dev_release(struct device *dev)
{
struct dio_dev *ddev = container_of(dev, typeof(struct dio_dev), dev);
kfree(ddev);
}

int __init dio_find(int deviceid)
{
/* Called to find a DIO device before the full bus scan has run.
Expand Down Expand Up @@ -234,6 +240,7 @@ static int __init dio_init(void)
dev->bus = &dio_bus;
dev->dev.parent = &dio_bus.dev;
dev->dev.bus = &dio_bus_type;
dev->dev.release = dio_dev_release;
dev->scode = scode;
dev->resource.start = pa;
dev->resource.end = pa + DIO_SIZE(scode, va);
Expand Down Expand Up @@ -261,6 +268,7 @@ static int __init dio_init(void)
if (error) {
pr_err("DIO: Error registering device %s\n",
dev->name);
put_device(&dev->dev);
continue;
}
error = dio_create_sysfs_dev_files(dev);
Expand Down

0 comments on commit affe3ce

Please sign in to comment.