iio: Use macro magic to avoid manual assign of driver_module
Starting point in boiler plate reduction similar to that done for many similar cases elsewhere in the kernel. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
a575de2da5
commit
63b19547cc
@ -1660,14 +1660,11 @@ static int iio_check_unique_scan_index(struct iio_dev *indio_dev)
|
|||||||
|
|
||||||
static const struct iio_buffer_setup_ops noop_ring_setup_ops;
|
static const struct iio_buffer_setup_ops noop_ring_setup_ops;
|
||||||
|
|
||||||
/**
|
int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
|
||||||
* iio_device_register() - register a device with the IIO subsystem
|
|
||||||
* @indio_dev: Device structure filled by the device driver
|
|
||||||
**/
|
|
||||||
int iio_device_register(struct iio_dev *indio_dev)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
indio_dev->driver_module = this_mod;
|
||||||
/* If the calling driver did not initialize of_node, do it here */
|
/* If the calling driver did not initialize of_node, do it here */
|
||||||
if (!indio_dev->dev.of_node && indio_dev->dev.parent)
|
if (!indio_dev->dev.of_node && indio_dev->dev.parent)
|
||||||
indio_dev->dev.of_node = indio_dev->dev.parent->of_node;
|
indio_dev->dev.of_node = indio_dev->dev.parent->of_node;
|
||||||
@ -1713,7 +1710,8 @@ int iio_device_register(struct iio_dev *indio_dev)
|
|||||||
indio_dev->setup_ops = &noop_ring_setup_ops;
|
indio_dev->setup_ops = &noop_ring_setup_ops;
|
||||||
|
|
||||||
cdev_init(&indio_dev->chrdev, &iio_buffer_fileops);
|
cdev_init(&indio_dev->chrdev, &iio_buffer_fileops);
|
||||||
indio_dev->chrdev.owner = indio_dev->info->driver_module;
|
|
||||||
|
indio_dev->chrdev.owner = this_mod;
|
||||||
|
|
||||||
ret = cdev_device_add(&indio_dev->chrdev, &indio_dev->dev);
|
ret = cdev_device_add(&indio_dev->chrdev, &indio_dev->dev);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -1731,7 +1729,7 @@ error_unreg_debugfs:
|
|||||||
iio_device_unregister_debugfs(indio_dev);
|
iio_device_unregister_debugfs(indio_dev);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(iio_device_register);
|
EXPORT_SYMBOL(__iio_device_register);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* iio_device_unregister() - unregister a device from the IIO subsystem
|
* iio_device_unregister() - unregister a device from the IIO subsystem
|
||||||
@ -1763,23 +1761,8 @@ static void devm_iio_device_unreg(struct device *dev, void *res)
|
|||||||
iio_device_unregister(*(struct iio_dev **)res);
|
iio_device_unregister(*(struct iio_dev **)res);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev,
|
||||||
* devm_iio_device_register - Resource-managed iio_device_register()
|
struct module *this_mod)
|
||||||
* @dev: Device to allocate iio_dev for
|
|
||||||
* @indio_dev: Device structure filled by the device driver
|
|
||||||
*
|
|
||||||
* Managed iio_device_register. The IIO device registered with this
|
|
||||||
* function is automatically unregistered on driver detach. This function
|
|
||||||
* calls iio_device_register() internally. Refer to that function for more
|
|
||||||
* information.
|
|
||||||
*
|
|
||||||
* If an iio_dev registered with this function needs to be unregistered
|
|
||||||
* separately, devm_iio_device_unregister() must be used.
|
|
||||||
*
|
|
||||||
* RETURNS:
|
|
||||||
* 0 on success, negative error number on failure.
|
|
||||||
*/
|
|
||||||
int devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev)
|
|
||||||
{
|
{
|
||||||
struct iio_dev **ptr;
|
struct iio_dev **ptr;
|
||||||
int ret;
|
int ret;
|
||||||
@ -1789,7 +1772,7 @@ int devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
*ptr = indio_dev;
|
*ptr = indio_dev;
|
||||||
ret = iio_device_register(indio_dev);
|
ret = __iio_device_register(indio_dev, this_mod);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
devres_add(dev, ptr);
|
devres_add(dev, ptr);
|
||||||
else
|
else
|
||||||
@ -1797,7 +1780,7 @@ int devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(devm_iio_device_register);
|
EXPORT_SYMBOL_GPL(__devm_iio_device_register);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* devm_iio_device_unregister - Resource-managed iio_device_unregister()
|
* devm_iio_device_unregister - Resource-managed iio_device_unregister()
|
||||||
|
@ -250,7 +250,7 @@ static int iio_trigger_attach_poll_func(struct iio_trigger *trig,
|
|||||||
= bitmap_empty(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER);
|
= bitmap_empty(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER);
|
||||||
|
|
||||||
/* Prevent the module from being removed whilst attached to a trigger */
|
/* Prevent the module from being removed whilst attached to a trigger */
|
||||||
__module_get(pf->indio_dev->info->driver_module);
|
__module_get(pf->indio_dev->driver_module);
|
||||||
|
|
||||||
/* Get irq number */
|
/* Get irq number */
|
||||||
pf->irq = iio_trigger_get_irq(trig);
|
pf->irq = iio_trigger_get_irq(trig);
|
||||||
@ -286,7 +286,7 @@ out_free_irq:
|
|||||||
out_put_irq:
|
out_put_irq:
|
||||||
iio_trigger_put_irq(trig, pf->irq);
|
iio_trigger_put_irq(trig, pf->irq);
|
||||||
out_put_module:
|
out_put_module:
|
||||||
module_put(pf->indio_dev->info->driver_module);
|
module_put(pf->indio_dev->driver_module);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,7 +307,7 @@ static int iio_trigger_detach_poll_func(struct iio_trigger *trig,
|
|||||||
trig->attached_own_device = false;
|
trig->attached_own_device = false;
|
||||||
iio_trigger_put_irq(trig, pf->irq);
|
iio_trigger_put_irq(trig, pf->irq);
|
||||||
free_irq(pf->irq, pf);
|
free_irq(pf->irq, pf);
|
||||||
module_put(pf->indio_dev->info->driver_module);
|
module_put(pf->indio_dev->driver_module);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -518,6 +518,7 @@ struct iio_buffer_setup_ops {
|
|||||||
/**
|
/**
|
||||||
* struct iio_dev - industrial I/O device
|
* struct iio_dev - industrial I/O device
|
||||||
* @id: [INTERN] used to identify device internally
|
* @id: [INTERN] used to identify device internally
|
||||||
|
* @driver_module: [INTERN] used to make it harder to undercut users
|
||||||
* @modes: [DRIVER] operating modes supported by device
|
* @modes: [DRIVER] operating modes supported by device
|
||||||
* @currentmode: [DRIVER] current operating mode
|
* @currentmode: [DRIVER] current operating mode
|
||||||
* @dev: [DRIVER] device structure, should be assigned a parent
|
* @dev: [DRIVER] device structure, should be assigned a parent
|
||||||
@ -558,6 +559,7 @@ struct iio_buffer_setup_ops {
|
|||||||
*/
|
*/
|
||||||
struct iio_dev {
|
struct iio_dev {
|
||||||
int id;
|
int id;
|
||||||
|
struct module *driver_module;
|
||||||
|
|
||||||
int modes;
|
int modes;
|
||||||
int currentmode;
|
int currentmode;
|
||||||
@ -604,9 +606,34 @@ struct iio_dev {
|
|||||||
|
|
||||||
const struct iio_chan_spec
|
const struct iio_chan_spec
|
||||||
*iio_find_channel_from_si(struct iio_dev *indio_dev, int si);
|
*iio_find_channel_from_si(struct iio_dev *indio_dev, int si);
|
||||||
int iio_device_register(struct iio_dev *indio_dev);
|
/**
|
||||||
|
* iio_device_register() - register a device with the IIO subsystem
|
||||||
|
* @indio_dev: Device structure filled by the device driver
|
||||||
|
**/
|
||||||
|
#define iio_device_register(iio_dev) \
|
||||||
|
__iio_device_register((iio_dev), THIS_MODULE)
|
||||||
|
int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod);
|
||||||
void iio_device_unregister(struct iio_dev *indio_dev);
|
void iio_device_unregister(struct iio_dev *indio_dev);
|
||||||
int devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev);
|
/**
|
||||||
|
* devm_iio_device_register - Resource-managed iio_device_register()
|
||||||
|
* @dev: Device to allocate iio_dev for
|
||||||
|
* @indio_dev: Device structure filled by the device driver
|
||||||
|
*
|
||||||
|
* Managed iio_device_register. The IIO device registered with this
|
||||||
|
* function is automatically unregistered on driver detach. This function
|
||||||
|
* calls iio_device_register() internally. Refer to that function for more
|
||||||
|
* information.
|
||||||
|
*
|
||||||
|
* If an iio_dev registered with this function needs to be unregistered
|
||||||
|
* separately, devm_iio_device_unregister() must be used.
|
||||||
|
*
|
||||||
|
* RETURNS:
|
||||||
|
* 0 on success, negative error number on failure.
|
||||||
|
*/
|
||||||
|
#define devm_iio_device_register(dev, indio_dev) \
|
||||||
|
__devm_iio_device_register((dev), (indio_dev), THIS_MODULE);
|
||||||
|
int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev,
|
||||||
|
struct module *this_mod);
|
||||||
void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev);
|
void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev);
|
||||||
int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
|
int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
|
||||||
int iio_device_claim_direct_mode(struct iio_dev *indio_dev);
|
int iio_device_claim_direct_mode(struct iio_dev *indio_dev);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user