linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Daniel Baluta <daniel.baluta@intel.com>,
	jic23@kernel.org, jlbec@evilplan.org, linux-iio@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Cc: knaack.h@gmx.de, linux-kernel@vger.kernel.org,
	octavian.purdila@intel.com, pebolle@tiscali.nl,
	patrick.porlan@intel.com, adriana.reus@intel.com,
	constantin.musca@intel.com, marten@intuitiveaerial.com,
	cristina.opriceana@gmail.com, pmeerw@pmeerw.net, hch@lst.de,
	viro@zeniv.linux.org.uk, akpm@linux-foundation.org
Subject: Re: [PATCH v7 4/5] iio: trigger: Introduce IIO hrtimer based trigger
Date: Mon, 31 Aug 2015 17:13:10 +0200	[thread overview]
Message-ID: <55E46F06.8050908@metafoo.de> (raw)
In-Reply-To: <1439246562-17515-5-git-send-email-daniel.baluta@intel.com>

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@intuitiveaerial.com>");
> +MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>");
> +MODULE_DESCRIPTION("Periodic hrtimer trigger for the IIO subsystem");
> +MODULE_LICENSE("GPL v2");
> 


  parent reply	other threads:[~2015-08-31 15:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-10 22:42 [PATCH v7 0/5] Add initial configfs support for IIO Daniel Baluta
     [not found] ` <1439246562-17515-1-git-send-email-daniel.baluta-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-08-10 22:42   ` [PATCH v7 1/5] configfs: Allow dynamic group (un)registration Daniel Baluta
2015-08-31 16:02     ` Lars-Peter Clausen
2015-08-10 22:42 ` [PATCH v7 2/5] iio: core: Introduce IIO configfs support Daniel Baluta
2015-08-10 22:42 ` [PATCH v7 3/5] iio: core: Introduce IIO software triggers Daniel Baluta
2015-08-17 11:31   ` Vladimir Barinov
     [not found]   ` <1439246562-17515-4-git-send-email-daniel.baluta-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-08-31 14:41     ` Lars-Peter Clausen
2015-08-10 22:42 ` [PATCH v7 4/5] iio: trigger: Introduce IIO hrtimer based trigger Daniel Baluta
     [not found]   ` <1439246562-17515-5-git-send-email-daniel.baluta-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-08-17 12:45     ` Vladimir Barinov
2015-08-17 12:49       ` Daniel Baluta
2015-08-31 14:57       ` Lars-Peter Clausen
     [not found]         ` <55E46B45.8040909-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2015-09-02 12:16           ` Vladimir Barinov
2015-08-31 15:13   ` Lars-Peter Clausen [this message]
2015-08-10 22:42 ` [PATCH v7 5/5] iio: Documentation: Add IIO configfs documentation Daniel Baluta
     [not found]   ` <1439246562-17515-6-git-send-email-daniel.baluta-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-08-17 12:01     ` Vladimir Barinov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55E46F06.8050908@metafoo.de \
    --to=lars@metafoo.de \
    --cc=adriana.reus@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=constantin.musca@intel.com \
    --cc=cristina.opriceana@gmail.com \
    --cc=daniel.baluta@intel.com \
    --cc=hch@lst.de \
    --cc=jic23@kernel.org \
    --cc=jlbec@evilplan.org \
    --cc=knaack.h@gmx.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marten@intuitiveaerial.com \
    --cc=octavian.purdila@intel.com \
    --cc=patrick.porlan@intel.com \
    --cc=pebolle@tiscali.nl \
    --cc=pmeerw@pmeerw.net \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).