mirror of
https://github.com/FEX-Emu/linux.git
synced 2024-12-23 09:56:00 +00:00
iio: Refuse to register triggers with duplicate names
The trigger name is documented as unique but drivers are currently allowed to register triggers with duplicate names. This should be considered a bug since it makes the 'current_trigger' interface unusable. Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
deb4d1fdcb
commit
3b8e73ec82
@ -64,6 +64,8 @@ static struct attribute *iio_trig_dev_attrs[] = {
|
|||||||
};
|
};
|
||||||
ATTRIBUTE_GROUPS(iio_trig_dev);
|
ATTRIBUTE_GROUPS(iio_trig_dev);
|
||||||
|
|
||||||
|
static struct iio_trigger *__iio_trigger_find_by_name(const char *name);
|
||||||
|
|
||||||
int iio_trigger_register(struct iio_trigger *trig_info)
|
int iio_trigger_register(struct iio_trigger *trig_info)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@ -86,11 +88,19 @@ int iio_trigger_register(struct iio_trigger *trig_info)
|
|||||||
|
|
||||||
/* Add to list of available triggers held by the IIO core */
|
/* Add to list of available triggers held by the IIO core */
|
||||||
mutex_lock(&iio_trigger_list_lock);
|
mutex_lock(&iio_trigger_list_lock);
|
||||||
|
if (__iio_trigger_find_by_name(trig_info->name)) {
|
||||||
|
pr_err("Duplicate trigger name '%s'\n", trig_info->name);
|
||||||
|
ret = -EEXIST;
|
||||||
|
goto error_device_del;
|
||||||
|
}
|
||||||
list_add_tail(&trig_info->list, &iio_trigger_list);
|
list_add_tail(&trig_info->list, &iio_trigger_list);
|
||||||
mutex_unlock(&iio_trigger_list_lock);
|
mutex_unlock(&iio_trigger_list_lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
error_device_del:
|
||||||
|
mutex_unlock(&iio_trigger_list_lock);
|
||||||
|
device_del(&trig_info->dev);
|
||||||
error_unregister_id:
|
error_unregister_id:
|
||||||
ida_simple_remove(&iio_trigger_ida, trig_info->id);
|
ida_simple_remove(&iio_trigger_ida, trig_info->id);
|
||||||
return ret;
|
return ret;
|
||||||
@ -109,6 +119,18 @@ void iio_trigger_unregister(struct iio_trigger *trig_info)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL(iio_trigger_unregister);
|
EXPORT_SYMBOL(iio_trigger_unregister);
|
||||||
|
|
||||||
|
/* Search for trigger by name, assuming iio_trigger_list_lock held */
|
||||||
|
static struct iio_trigger *__iio_trigger_find_by_name(const char *name)
|
||||||
|
{
|
||||||
|
struct iio_trigger *iter;
|
||||||
|
|
||||||
|
list_for_each_entry(iter, &iio_trigger_list, list)
|
||||||
|
if (!strcmp(iter->name, name))
|
||||||
|
return iter;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static struct iio_trigger *iio_trigger_find_by_name(const char *name,
|
static struct iio_trigger *iio_trigger_find_by_name(const char *name,
|
||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user