[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <55E46F06.8050908@metafoo.de>
Date: Mon, 31 Aug 2015 17:13:10 +0200
From: Lars-Peter Clausen <lars@...afoo.de>
To: Daniel Baluta <daniel.baluta@...el.com>, jic23@...nel.org,
jlbec@...lplan.org, linux-iio@...r.kernel.org,
linux-fsdevel@...r.kernel.org
CC: knaack.h@....de, linux-kernel@...r.kernel.org,
octavian.purdila@...el.com, pebolle@...cali.nl,
patrick.porlan@...el.com, adriana.reus@...el.com,
constantin.musca@...el.com, marten@...uitiveaerial.com,
cristina.opriceana@...il.com, pmeerw@...erw.net, hch@....de,
viro@...iv.linux.org.uk, akpm@...ux-foundation.org
Subject: Re: [PATCH v7 4/5] iio: trigger: Introduce IIO hrtimer based trigger
On 08/11/2015 12:42 AM, Daniel Baluta wrote:
[...]
> +
> +static struct iio_sw_trigger *iio_trig_hrtimer_probe(const char *name)
> +{
> + struct iio_hrtimer_info *trig_info;
> + int ret;
> +
> + trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL);
> + if (!trig_info)
> + return ERR_PTR(-ENOMEM);
> +
> + trig_info->swt.trigger = iio_trigger_alloc("%s", name);
> + if (!trig_info->swt.trigger) {
> + ret = -ENOMEM;
> + goto err_free_trig_info;
> + }
> +
> + iio_trigger_set_drvdata(trig_info->swt.trigger, trig_info);
> + trig_info->swt.trigger->ops = &iio_hrtimer_trigger_ops;
> + trig_info->swt.trigger->dev.groups = iio_hrtimer_attr_groups;
> +
> + hrtimer_init(&trig_info->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
> + trig_info->timer.function = iio_hrtimer_trig_handler;
> +
> + trig_info->sampling_frequency = HRTIMER_DEFAULT_SAMPLING_FREQUENCY;
> + trig_info->period = ktime_set(0, NSEC_PER_SEC /
> + trig_info->sampling_frequency);
> +
> + ret = iio_trigger_register(trig_info->swt.trigger);
I think it makes sense to move the register and unregister to the swt core.
This is something you'd always want to do as the last step in the probe and
the first step in the remove function.
> + if (ret)
> + goto err_free_trigger;
> +
> + iio_swt_group_init_type_name(&trig_info->swt, name, &iio_hrtimer_type);
> + return &trig_info->swt;
> +err_free_trigger:
> + iio_trigger_free(trig_info->swt.trigger);
> +err_free_trig_info:
> + kfree(trig_info);
> +
> + return ERR_PTR(ret);
> +}
> +
> +static int iio_trig_hrtimer_remove(struct iio_sw_trigger *swt)
> +{
> + struct iio_hrtimer_info *trig_info;
> +
> + trig_info = iio_trigger_get_drvdata(swt->trigger);
> +
> + iio_trigger_unregister(swt->trigger);
> +
> + /* cancel the timer after unreg to make sure no one rearms it */
> + hrtimer_cancel(&trig_info->timer);
> + iio_trigger_free(swt->trigger);
> + kfree(trig_info);
> +
> + return 0;
> +}
> +
> +const struct iio_sw_trigger_ops iio_trig_hrtimer_ops = {
static
> + .probe = iio_trig_hrtimer_probe,
> + .remove = iio_trig_hrtimer_remove,
> +};
> +
> +struct iio_sw_trigger_type iio_trig_hrtimer = {
static
> + .name = "hrtimer",
> + .owner = THIS_MODULE,
> + .ops = &iio_trig_hrtimer_ops,
> +};
> +
> +module_iio_sw_trigger_driver(iio_trig_hrtimer);
> +
> +MODULE_AUTHOR("Marten Svanfeldt <marten@...uitiveaerial.com>");
> +MODULE_AUTHOR("Daniel Baluta <daniel.baluta@...el.com>");
> +MODULE_DESCRIPTION("Periodic hrtimer trigger for the IIO subsystem");
> +MODULE_LICENSE("GPL v2");
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists