Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753521AbbHaPNS (ORCPT ); Mon, 31 Aug 2015 11:13:18 -0400 Received: from smtp-out-225.synserver.de ([212.40.185.225]:1025 "EHLO smtp-out-200.synserver.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753471AbbHaPNP (ORCPT ); Mon, 31 Aug 2015 11:13:15 -0400 X-SynServer-TrustedSrc: 1 X-SynServer-AuthUser: lars@metafoo.de X-SynServer-PPID: 6450 Message-ID: <55E46F06.8050908@metafoo.de> Date: Mon, 31 Aug 2015 17:13:10 +0200 From: Lars-Peter Clausen User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.8.0 MIME-Version: 1.0 To: Daniel Baluta , 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 References: <1439246562-17515-1-git-send-email-daniel.baluta@intel.com> <1439246562-17515-5-git-send-email-daniel.baluta@intel.com> In-Reply-To: <1439246562-17515-5-git-send-email-daniel.baluta@intel.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2763 Lines: 94 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 "); > +MODULE_AUTHOR("Daniel Baluta "); > +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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/