mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
iio: core: Clean up device correctly on iio_device_alloc() failure
Once we called device_initialize() we have to call put_device() on it. Refactor the code to make it in the right order. Fixes:fe6f45f6ba("iio: core: check return value when calling dev_set_name()") Fixes:847ec80bba("Staging: IIO: core support for device registration and management") Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Nuno Sá <nuno.sa@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
committed by
Jonathan Cameron
parent
f5d203467a
commit
b0e6871415
@@ -1697,11 +1697,6 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
|
||||
ACCESS_PRIVATE(indio_dev, priv) = (char *)iio_dev_opaque +
|
||||
ALIGN(sizeof(*iio_dev_opaque), IIO_DMA_MINALIGN);
|
||||
|
||||
indio_dev->dev.parent = parent;
|
||||
indio_dev->dev.type = &iio_device_type;
|
||||
indio_dev->dev.bus = &iio_bus_type;
|
||||
device_initialize(&indio_dev->dev);
|
||||
|
||||
INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list);
|
||||
|
||||
iio_dev_opaque->id = ida_alloc(&iio_ida, GFP_KERNEL);
|
||||
@@ -1727,6 +1722,11 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
|
||||
mutex_init(&iio_dev_opaque->mlock);
|
||||
mutex_init(&iio_dev_opaque->info_exist_lock);
|
||||
|
||||
indio_dev->dev.parent = parent;
|
||||
indio_dev->dev.type = &iio_device_type;
|
||||
indio_dev->dev.bus = &iio_bus_type;
|
||||
device_initialize(&indio_dev->dev);
|
||||
|
||||
return indio_dev;
|
||||
}
|
||||
EXPORT_SYMBOL(iio_device_alloc);
|
||||
|
||||
Reference in New Issue
Block a user