Changes in 4.9.335 wifi: mac80211_hwsim: fix debugfs attribute ps with rc table support audit: fix undefined behavior in bit shift for AUDIT_BIT wifi: mac80211: Fix ack frame idr leak when mesh has no route MIPS: pic32: treat port as signed integer af_key: Fix send_acquire race with pfkey_register bus: sunxi-rsb: Support atomic transfers ARM: dts: at91: sam9g20ek: enable udc vbus gpio pinctrl nfc/nci: fix race with opening and closing net: pch_gbe: fix potential memleak in pch_gbe_tx_queue() 9p/fd: fix issue of list_del corruption in p9_fd_cancel() ARM: mxs: fix memory leak in mxs_machine_init() net/mlx4: Check retval of mlx4_bitmap_init net/qla3xxx: fix potential memleak in ql3xxx_send() xfrm: Fix ignored return value in xfrm6_init() NFC: nci: fix memory leak in nci_rx_data_packet() nfc: st-nci: fix incorrect validating logic in EVT_TRANSACTION nfc: st-nci: fix memory leaks in EVT_TRANSACTION net: thunderx: Fix the ACPI memory leak s390/crashdump: fix TOD programmable field size iio: light: apds9960: fix wrong register for gesture gain iio: core: Fix entry not deleted when iio_register_sw_trigger_type() fails kconfig: display recursive dependency resolution hint just once nios2: add FORCE for vmlinuz.gz nilfs2: fix nilfs_sufile_mark_dirty() not set segment usage as dirty serial: 8250: 8250_omap: Avoid RS485 RTS glitch on ->set_termios() xen/platform-pci: add missing free_irq() in error path platform/x86: asus-wmi: add missing pci_dev_put() in asus_wmi_set_xusb2pr() tcp: configurable source port perturb table size net: usb: qmi_wwan: add Telit 0x103a composition drm/amdgpu: always register an MMU notifier for userptr iio: health: afe4403: Fix oob read in afe4403_read_raw iio: health: afe4404: Fix oob read in afe4404_[read|write]_raw hwmon: (i5500_temp) fix missing pci_disable_device() hwmon: (ibmpex) Fix possible UAF when ibmpex_register_bmc() fails net/mlx5: Fix uninitialized variable bug in outlen_write() can: sja1000_isa: sja1000_isa_probe(): add missing free_sja1000dev() can: cc770: cc770_isa_probe(): add missing free_cc770dev() qlcnic: fix sleep-in-atomic-context bugs caused by msleep net: phy: fix null-ptr-deref while probe() failed net: net_netdev: Fix error handling in ntb_netdev_init_module() net/9p: Fix a potential socket leak in p9_socket_open net: hsr: Fix potential use-after-free packet: do not set TP_STATUS_CSUM_VALID on CHECKSUM_COMPLETE net: ethernet: renesas: ravb: Fix promiscuous mode after system resumed hwmon: (coretemp) Check for null before removing sysfs attrs hwmon: (coretemp) fix pci device refcount leak in nv1a_ram_new() btrfs: qgroup: fix sleep from invalid context bug in btrfs_qgroup_inherit() tools/vm/slabinfo-gnuplot: use "grep -E" instead of "egrep" nilfs2: fix NULL pointer dereference in nilfs_palloc_commit_free_entry() arm64: Fix panic() when Spectre-v2 causes Spectre-BHB to re-allocate KVM vectors arm64: errata: Fix KVM Spectre-v2 mitigation selection for Cortex-A57/A72 ASoC: ops: Fix bounds check for _sx controls pinctrl: single: Fix potential division by zero iommu/vt-d: Fix PCI device refcount leak in dmar_dev_scope_init() tcp/udp: Fix memory leak in ipv6_renew_options(). Revert "fbdev: fb_pm2fb: Avoid potential divide by zero error" x86/tsx: Add a feature bit for TSX control MSR support x86/pm: Add enumeration check before spec MSRs save/restore setup Bluetooth: L2CAP: Fix accepting connection request for invalid SPSM x86/ioremap: Fix page aligned size calculation in __ioremap_caller() proc: avoid integer type confusion in get_proc_long proc: proc_skip_spaces() shouldn't think it is working on C strings v4l2: don't fall back to follow_pfn() if pin_user_pages_fast() fails Linux 4.9.335 Change-Id: I5a99e366191f445d4de1039f5e82812b37787842 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
187 lines
4.4 KiB
C
187 lines
4.4 KiB
C
/*
|
|
* The Industrial I/O core, software trigger functions
|
|
*
|
|
* Copyright (c) 2015 Intel Corporation
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
* the Free Software Foundation.
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/kmod.h>
|
|
#include <linux/list.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/iio/sw_trigger.h>
|
|
#include <linux/iio/configfs.h>
|
|
#include <linux/configfs.h>
|
|
|
|
static struct config_group *iio_triggers_group;
|
|
static struct config_item_type iio_trigger_type_group_type;
|
|
|
|
static struct config_item_type iio_triggers_group_type = {
|
|
.ct_owner = THIS_MODULE,
|
|
};
|
|
|
|
static LIST_HEAD(iio_trigger_types_list);
|
|
static DEFINE_MUTEX(iio_trigger_types_lock);
|
|
|
|
static
|
|
struct iio_sw_trigger_type *__iio_find_sw_trigger_type(const char *name,
|
|
unsigned len)
|
|
{
|
|
struct iio_sw_trigger_type *t = NULL, *iter;
|
|
|
|
list_for_each_entry(iter, &iio_trigger_types_list, list)
|
|
if (!strcmp(iter->name, name)) {
|
|
t = iter;
|
|
break;
|
|
}
|
|
|
|
return t;
|
|
}
|
|
|
|
int iio_register_sw_trigger_type(struct iio_sw_trigger_type *t)
|
|
{
|
|
struct iio_sw_trigger_type *iter;
|
|
int ret = 0;
|
|
|
|
mutex_lock(&iio_trigger_types_lock);
|
|
iter = __iio_find_sw_trigger_type(t->name, strlen(t->name));
|
|
if (iter)
|
|
ret = -EBUSY;
|
|
else
|
|
list_add_tail(&t->list, &iio_trigger_types_list);
|
|
mutex_unlock(&iio_trigger_types_lock);
|
|
|
|
if (ret)
|
|
return ret;
|
|
|
|
t->group = configfs_register_default_group(iio_triggers_group, t->name,
|
|
&iio_trigger_type_group_type);
|
|
if (IS_ERR(t->group)) {
|
|
mutex_lock(&iio_trigger_types_lock);
|
|
list_del(&t->list);
|
|
mutex_unlock(&iio_trigger_types_lock);
|
|
ret = PTR_ERR(t->group);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(iio_register_sw_trigger_type);
|
|
|
|
void iio_unregister_sw_trigger_type(struct iio_sw_trigger_type *t)
|
|
{
|
|
struct iio_sw_trigger_type *iter;
|
|
|
|
mutex_lock(&iio_trigger_types_lock);
|
|
iter = __iio_find_sw_trigger_type(t->name, strlen(t->name));
|
|
if (iter)
|
|
list_del(&t->list);
|
|
mutex_unlock(&iio_trigger_types_lock);
|
|
|
|
configfs_unregister_default_group(t->group);
|
|
}
|
|
EXPORT_SYMBOL(iio_unregister_sw_trigger_type);
|
|
|
|
static
|
|
struct iio_sw_trigger_type *iio_get_sw_trigger_type(const char *name)
|
|
{
|
|
struct iio_sw_trigger_type *t;
|
|
|
|
mutex_lock(&iio_trigger_types_lock);
|
|
t = __iio_find_sw_trigger_type(name, strlen(name));
|
|
if (t && !try_module_get(t->owner))
|
|
t = NULL;
|
|
mutex_unlock(&iio_trigger_types_lock);
|
|
|
|
return t;
|
|
}
|
|
|
|
struct iio_sw_trigger *iio_sw_trigger_create(const char *type, const char *name)
|
|
{
|
|
struct iio_sw_trigger *t;
|
|
struct iio_sw_trigger_type *tt;
|
|
|
|
tt = iio_get_sw_trigger_type(type);
|
|
if (!tt) {
|
|
pr_err("Invalid trigger type: %s\n", type);
|
|
return ERR_PTR(-EINVAL);
|
|
}
|
|
t = tt->ops->probe(name);
|
|
if (IS_ERR(t))
|
|
goto out_module_put;
|
|
|
|
t->trigger_type = tt;
|
|
|
|
return t;
|
|
out_module_put:
|
|
module_put(tt->owner);
|
|
return t;
|
|
}
|
|
EXPORT_SYMBOL(iio_sw_trigger_create);
|
|
|
|
void iio_sw_trigger_destroy(struct iio_sw_trigger *t)
|
|
{
|
|
struct iio_sw_trigger_type *tt = t->trigger_type;
|
|
|
|
tt->ops->remove(t);
|
|
module_put(tt->owner);
|
|
}
|
|
EXPORT_SYMBOL(iio_sw_trigger_destroy);
|
|
|
|
static struct config_group *trigger_make_group(struct config_group *group,
|
|
const char *name)
|
|
{
|
|
struct iio_sw_trigger *t;
|
|
|
|
t = iio_sw_trigger_create(group->cg_item.ci_name, name);
|
|
if (IS_ERR(t))
|
|
return ERR_CAST(t);
|
|
|
|
config_item_set_name(&t->group.cg_item, "%s", name);
|
|
|
|
return &t->group;
|
|
}
|
|
|
|
static void trigger_drop_group(struct config_group *group,
|
|
struct config_item *item)
|
|
{
|
|
struct iio_sw_trigger *t = to_iio_sw_trigger(item);
|
|
|
|
iio_sw_trigger_destroy(t);
|
|
config_item_put(item);
|
|
}
|
|
|
|
static struct configfs_group_operations trigger_ops = {
|
|
.make_group = &trigger_make_group,
|
|
.drop_item = &trigger_drop_group,
|
|
};
|
|
|
|
static struct config_item_type iio_trigger_type_group_type = {
|
|
.ct_group_ops = &trigger_ops,
|
|
.ct_owner = THIS_MODULE,
|
|
};
|
|
|
|
static int __init iio_sw_trigger_init(void)
|
|
{
|
|
iio_triggers_group =
|
|
configfs_register_default_group(&iio_configfs_subsys.su_group,
|
|
"triggers",
|
|
&iio_triggers_group_type);
|
|
return PTR_ERR_OR_ZERO(iio_triggers_group);
|
|
}
|
|
module_init(iio_sw_trigger_init);
|
|
|
|
static void __exit iio_sw_trigger_exit(void)
|
|
{
|
|
configfs_unregister_default_group(iio_triggers_group);
|
|
}
|
|
module_exit(iio_sw_trigger_exit);
|
|
|
|
MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>");
|
|
MODULE_DESCRIPTION("Industrial I/O software triggers support");
|
|
MODULE_LICENSE("GPL v2");
|