Changes in 4.9.334 HID: hyperv: fix possible memory leak in mousevsc_probe() net: gso: fix panic on frag_list with mixed head alloc types bnxt_en: fix potentially incorrect return value for ndo_rx_flow_steer net: fman: Unregister ethernet device on removal capabilities: fix undefined behavior in bit shift for CAP_TO_MASK net: lapbether: fix issue of dev reference count leakage in lapbeth_device_event() hamradio: fix issue of dev reference count leakage in bpq_device_event() ipv6: addrlabel: fix infoleak when sending struct ifaddrlblmsg to network tipc: fix the msg->req tlv len check in tipc_nl_compat_name_table_dump_header dmaengine: mv_xor_v2: Fix a resource leak in mv_xor_v2_remove() drivers: net: xgene: disable napi when register irq failed in xgene_enet_open() net: cxgb3_main: disable napi when bind qsets failed in cxgb_up() ethernet: s2io: disable napi when start nic failed in s2io_card_up() net: mv643xx_eth: disable napi when init rxq or txq failed in mv643xx_eth_open() net: macvlan: fix memory leaks of macvlan_common_newlink ALSA: hda: fix potential memleak in 'add_widget_node' ALSA: usb-audio: Add quirk entry for M-Audio Micro nilfs2: fix deadlock in nilfs_count_free_blocks() platform/x86: hp_wmi: Fix rfkill causing soft blocked wifi btrfs: selftests: fix wrong error check in btrfs_free_dummy_root() udf: Fix a slab-out-of-bounds write bug in udf_find_entry() cert host tools: Stop complaining about deprecated OpenSSL functions dmaengine: at_hdmac: Fix at_lli struct definition dmaengine: at_hdmac: Don't start transactions at tx_submit level dmaengine: at_hdmac: Fix completion of unissued descriptor in case of errors dmaengine: at_hdmac: Don't allow CPU to reorder channel enable dmaengine: at_hdmac: Fix impossible condition dmaengine: at_hdmac: Check return code of dma_async_device_register x86/cpu: Restore AMD's DE_CFG MSR after resume drm/imx: imx-tve: Fix return type of imx_tve_connector_mode_valid Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm ASoC: core: Fix use-after-free in snd_soc_exit() serial: 8250_omap: remove wait loop from Errata i202 workaround serial: 8250: omap: Flush PM QOS work on remove tty: n_gsm: fix sleep-in-atomic-context bug in gsm_control_send ASoC: soc-utils: Remove __exit for snd_soc_util_exit() parport_pc: Avoid FIFO port location truncation pinctrl: devicetree: fix null pointer dereferencing in pinctrl_dt_to_map mISDN: fix possible memory leak in mISDN_dsp_element_register() mISDN: fix misuse of put_device() in mISDN_register_device() net: caif: fix double disconnect client in chnl_net_open() xen/pcpu: fix possible memory leak in register_pcpu() net/x25: Fix skb leak in x25_lapb_receive_frame() cifs: Fix wrong return value checking when GETFLAGS ftrace: Fix the possible incorrect kernel message ftrace: Optimize the allocation for mcount entries ring_buffer: Do not deactivate non-existant pages ALSA: usb-audio: Drop snd_BUG_ON() from snd_usbmidi_output_open() USB: serial: option: add Sierra Wireless EM9191 USB: serial: option: remove old LARA-R6 PID USB: serial: option: add u-blox LARA-R6 00B modem USB: serial: option: add u-blox LARA-L6 modem USB: serial: option: add Fibocom FM160 0x0111 composition usb: add NO_LPM quirk for Realforce 87U Keyboard usb: chipidea: fix deadlock in ci_otg_del_timer iio: adc: at91_adc: fix possible memory leak in at91_adc_allocate_trigger() iio: trigger: sysfs: fix possible memory leak in iio_sysfs_trig_init() iio: pressure: ms5611: changed hardcoded SPI speed to value limited dm ioctl: fix misbehavior if list_versions races with module loading serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs serial: 8250_lpss: Configure DMA also w/o DMA filter mmc: core: properly select voltage range without power cycle misc/vmw_vmci: fix an infoleak in vmci_host_do_receive_datagram() nilfs2: fix use-after-free bug of ns_writer on remount serial: 8250: Flush DMA Rx on RLSI tcp: cdg: allow tcp_cdg_release() to be called multiple times kcm: avoid potential race in kcm_tx_work 9p: trans_fd/p9_conn_cancel: drop client lock earlier gfs2: Check sb_bsize_shift after reading superblock gfs2: Switch from strlcpy to strscpy 9p/trans_fd: always use O_NONBLOCK read/write mm: fs: initialize fsdata passed to write_begin/write_end interface ntfs: fix use-after-free in ntfs_attr_find() ntfs: fix out-of-bounds read in ntfs_attr_find() ntfs: check overflow when iterating ATTR_RECORDs Linux 4.9.334 Change-Id: I9e6e907e472831b20a849c7765c0eb2a62694347 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
235 lines
4.9 KiB
C
235 lines
4.9 KiB
C
/*
|
|
* Copyright 2011 Analog Devices Inc.
|
|
*
|
|
* Licensed under the GPL-2.
|
|
*
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/list.h>
|
|
#include <linux/irq_work.h>
|
|
|
|
#include <linux/iio/iio.h>
|
|
#include <linux/iio/trigger.h>
|
|
|
|
struct iio_sysfs_trig {
|
|
struct iio_trigger *trig;
|
|
struct irq_work work;
|
|
int id;
|
|
struct list_head l;
|
|
};
|
|
|
|
static LIST_HEAD(iio_sysfs_trig_list);
|
|
static DEFINE_MUTEX(iio_sysfs_trig_list_mut);
|
|
|
|
static int iio_sysfs_trigger_probe(int id);
|
|
static ssize_t iio_sysfs_trig_add(struct device *dev,
|
|
struct device_attribute *attr,
|
|
const char *buf,
|
|
size_t len)
|
|
{
|
|
int ret;
|
|
unsigned long input;
|
|
|
|
ret = kstrtoul(buf, 10, &input);
|
|
if (ret)
|
|
return ret;
|
|
ret = iio_sysfs_trigger_probe(input);
|
|
if (ret)
|
|
return ret;
|
|
return len;
|
|
}
|
|
static DEVICE_ATTR(add_trigger, S_IWUSR, NULL, &iio_sysfs_trig_add);
|
|
|
|
static int iio_sysfs_trigger_remove(int id);
|
|
static ssize_t iio_sysfs_trig_remove(struct device *dev,
|
|
struct device_attribute *attr,
|
|
const char *buf,
|
|
size_t len)
|
|
{
|
|
int ret;
|
|
unsigned long input;
|
|
|
|
ret = kstrtoul(buf, 10, &input);
|
|
if (ret)
|
|
return ret;
|
|
ret = iio_sysfs_trigger_remove(input);
|
|
if (ret)
|
|
return ret;
|
|
return len;
|
|
}
|
|
|
|
static DEVICE_ATTR(remove_trigger, S_IWUSR, NULL, &iio_sysfs_trig_remove);
|
|
|
|
static struct attribute *iio_sysfs_trig_attrs[] = {
|
|
&dev_attr_add_trigger.attr,
|
|
&dev_attr_remove_trigger.attr,
|
|
NULL,
|
|
};
|
|
|
|
static const struct attribute_group iio_sysfs_trig_group = {
|
|
.attrs = iio_sysfs_trig_attrs,
|
|
};
|
|
|
|
static const struct attribute_group *iio_sysfs_trig_groups[] = {
|
|
&iio_sysfs_trig_group,
|
|
NULL
|
|
};
|
|
|
|
|
|
/* Nothing to actually do upon release */
|
|
static void iio_trigger_sysfs_release(struct device *dev)
|
|
{
|
|
}
|
|
|
|
static struct device iio_sysfs_trig_dev = {
|
|
.bus = &iio_bus_type,
|
|
.groups = iio_sysfs_trig_groups,
|
|
.release = &iio_trigger_sysfs_release,
|
|
};
|
|
|
|
static void iio_sysfs_trigger_work(struct irq_work *work)
|
|
{
|
|
struct iio_sysfs_trig *trig = container_of(work, struct iio_sysfs_trig,
|
|
work);
|
|
|
|
iio_trigger_poll(trig->trig);
|
|
}
|
|
|
|
static ssize_t iio_sysfs_trigger_poll(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
{
|
|
struct iio_trigger *trig = to_iio_trigger(dev);
|
|
struct iio_sysfs_trig *sysfs_trig = iio_trigger_get_drvdata(trig);
|
|
|
|
irq_work_queue(&sysfs_trig->work);
|
|
|
|
return count;
|
|
}
|
|
|
|
static DEVICE_ATTR(trigger_now, S_IWUSR, NULL, iio_sysfs_trigger_poll);
|
|
|
|
static struct attribute *iio_sysfs_trigger_attrs[] = {
|
|
&dev_attr_trigger_now.attr,
|
|
NULL,
|
|
};
|
|
|
|
static const struct attribute_group iio_sysfs_trigger_attr_group = {
|
|
.attrs = iio_sysfs_trigger_attrs,
|
|
};
|
|
|
|
static const struct attribute_group *iio_sysfs_trigger_attr_groups[] = {
|
|
&iio_sysfs_trigger_attr_group,
|
|
NULL
|
|
};
|
|
|
|
static const struct iio_trigger_ops iio_sysfs_trigger_ops = {
|
|
.owner = THIS_MODULE,
|
|
};
|
|
|
|
static int iio_sysfs_trigger_probe(int id)
|
|
{
|
|
struct iio_sysfs_trig *t;
|
|
int ret;
|
|
bool foundit = false;
|
|
|
|
mutex_lock(&iio_sysfs_trig_list_mut);
|
|
list_for_each_entry(t, &iio_sysfs_trig_list, l)
|
|
if (id == t->id) {
|
|
foundit = true;
|
|
break;
|
|
}
|
|
if (foundit) {
|
|
ret = -EINVAL;
|
|
goto out1;
|
|
}
|
|
t = kmalloc(sizeof(*t), GFP_KERNEL);
|
|
if (t == NULL) {
|
|
ret = -ENOMEM;
|
|
goto out1;
|
|
}
|
|
t->id = id;
|
|
t->trig = iio_trigger_alloc("sysfstrig%d", id);
|
|
if (!t->trig) {
|
|
ret = -ENOMEM;
|
|
goto free_t;
|
|
}
|
|
|
|
t->trig->dev.groups = iio_sysfs_trigger_attr_groups;
|
|
t->trig->ops = &iio_sysfs_trigger_ops;
|
|
t->trig->dev.parent = &iio_sysfs_trig_dev;
|
|
iio_trigger_set_drvdata(t->trig, t);
|
|
|
|
init_irq_work(&t->work, iio_sysfs_trigger_work);
|
|
|
|
ret = iio_trigger_register(t->trig);
|
|
if (ret)
|
|
goto out2;
|
|
list_add(&t->l, &iio_sysfs_trig_list);
|
|
__module_get(THIS_MODULE);
|
|
mutex_unlock(&iio_sysfs_trig_list_mut);
|
|
return 0;
|
|
|
|
out2:
|
|
iio_trigger_free(t->trig);
|
|
free_t:
|
|
kfree(t);
|
|
out1:
|
|
mutex_unlock(&iio_sysfs_trig_list_mut);
|
|
return ret;
|
|
}
|
|
|
|
static int iio_sysfs_trigger_remove(int id)
|
|
{
|
|
bool foundit = false;
|
|
struct iio_sysfs_trig *t;
|
|
|
|
mutex_lock(&iio_sysfs_trig_list_mut);
|
|
list_for_each_entry(t, &iio_sysfs_trig_list, l)
|
|
if (id == t->id) {
|
|
foundit = true;
|
|
break;
|
|
}
|
|
if (!foundit) {
|
|
mutex_unlock(&iio_sysfs_trig_list_mut);
|
|
return -EINVAL;
|
|
}
|
|
|
|
iio_trigger_unregister(t->trig);
|
|
irq_work_sync(&t->work);
|
|
iio_trigger_free(t->trig);
|
|
|
|
list_del(&t->l);
|
|
kfree(t);
|
|
module_put(THIS_MODULE);
|
|
mutex_unlock(&iio_sysfs_trig_list_mut);
|
|
return 0;
|
|
}
|
|
|
|
|
|
static int __init iio_sysfs_trig_init(void)
|
|
{
|
|
int ret;
|
|
device_initialize(&iio_sysfs_trig_dev);
|
|
dev_set_name(&iio_sysfs_trig_dev, "iio_sysfs_trigger");
|
|
ret = device_add(&iio_sysfs_trig_dev);
|
|
if (ret)
|
|
put_device(&iio_sysfs_trig_dev);
|
|
return ret;
|
|
}
|
|
module_init(iio_sysfs_trig_init);
|
|
|
|
static void __exit iio_sysfs_trig_exit(void)
|
|
{
|
|
device_unregister(&iio_sysfs_trig_dev);
|
|
}
|
|
module_exit(iio_sysfs_trig_exit);
|
|
|
|
MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
|
|
MODULE_DESCRIPTION("Sysfs based trigger for the iio subsystem");
|
|
MODULE_LICENSE("GPL v2");
|
|
MODULE_ALIAS("platform:iio-trig-sysfs");
|