From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4B6AC77B75 for ; Sun, 7 May 2023 14:19:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230452AbjEGOTI (ORCPT ); Sun, 7 May 2023 10:19:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbjEGOTH (ORCPT ); Sun, 7 May 2023 10:19:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E99AC4C25; Sun, 7 May 2023 07:19:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7FEDC60C5E; Sun, 7 May 2023 14:19:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87675C433EF; Sun, 7 May 2023 14:19:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683469144; bh=bWgS6xVM0twb9Tsnumkxrs/bEwi5vgZbTfEs1wm2qpE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=KZtfAxBTe1PzHtVUjKhzGpl/THFP1BusGfi3cHxlTOrlwR1wmEPpsxD7LW/4kO7gx B/z3nQtF7CjX2SJ/R19g7ujBU1b+Qq6nGNMeIn2cBJKAOvuc8fjdDAxsXINz2TMsKr zMQOSCjOhSC1d8JHnEvbMDKQBwN4cjO6W2u+YuW5xYrvZROsyjRxdIsGwDtk9LyqeY VfjMEybKv/lqHC/V0j9IbgGvoXdIfyevsJ/XnmIIUEz+P4XxcZFJX4gXCSGqytasEd lCWTk5f9FJC3eRoRD7cibRb09kqZfAqROOtkJ5F2wnGcQ5j1iOVWnmqegblgQi0uKo HKgCpK6aT7slw== Date: Sun, 7 May 2023 15:34:57 +0100 From: Jonathan Cameron To: Matti Vaittinen Cc: Matti Vaittinen , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Andy Shevchenko , Shreeya Patel , Zhigang Shi , Paul Gazzillo , Dmitry Osipenko , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 2/5] iio: trigger: Add simple trigger_validation helper Message-ID: <20230507153457.3b6bbfed@jic23-huawei> In-Reply-To: References: X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org On Wed, 3 May 2023 12:48:57 +0300 Matti Vaittinen wrote: > Some triggers can only be attached to the IIO device that corresponds to > the same physical device. Implement generic helper which can be used as > a validate_trigger callback for such devices. > > Suggested-by: Jonathan Cameron > Signed-off-by: Matti Vaittinen > Noticed a trivial capitalisation issue inline. Jonathan > --- > Revision history > v2: => v3: > - Fix title (space after iio:) > v2: New patch > --- > drivers/iio/industrialio-trigger.c | 22 +++++++++++++++++++++- > include/linux/iio/trigger.h | 1 + > 2 files changed, 22 insertions(+), 1 deletion(-) > > diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c > index 784dc1e00310..c616297aa754 100644 > --- a/drivers/iio/industrialio-trigger.c > +++ b/drivers/iio/industrialio-trigger.c > @@ -322,7 +322,7 @@ int iio_trigger_attach_poll_func(struct iio_trigger *trig, > * this is the case if the IIO device and the trigger device share the > * same parent device. > */ > - if (pf->indio_dev->dev.parent == trig->dev.parent) > + if (iio_validate_own_trigger(pf->indio_dev, trig)) > trig->attached_own_device = true; > > return ret; > @@ -728,6 +728,26 @@ bool iio_trigger_using_own(struct iio_dev *indio_dev) > } > EXPORT_SYMBOL(iio_trigger_using_own); > > +/** > + * iio_validate_own_trigger - Check if a trigger and IIO device belong to > + * the same device > + * @idev: the IIO device to check > + * @trig: The IIO trigger to check The / the consistency needs fixing. I'm not sure on the local / file convention, but it hopefully isn't a random mixture! > + * > + * This function can be used as the validate_trigger callback for triggers that > + * can only be attached to their own device. > + * > + * Return: 0 if both the trigger and the IIO device belong to the same > + * device, -EINVAL otherwise. > + */ > +int iio_validate_own_trigger(struct iio_dev *idev, struct iio_trigger *trig) > +{ > + if (idev->dev.parent != trig->dev.parent) > + return -EINVAL; > + return 0; > +} > +EXPORT_SYMBOL_GPL(iio_validate_own_trigger); > + > /** > * iio_trigger_validate_own_device - Check if a trigger and IIO device belong to > * the same device > diff --git a/include/linux/iio/trigger.h b/include/linux/iio/trigger.h > index 51f52c5c6092..bce3b1788199 100644 > --- a/include/linux/iio/trigger.h > +++ b/include/linux/iio/trigger.h > @@ -171,6 +171,7 @@ void iio_trigger_free(struct iio_trigger *trig); > */ > bool iio_trigger_using_own(struct iio_dev *indio_dev); > > +int iio_validate_own_trigger(struct iio_dev *idev, struct iio_trigger *trig); > int iio_trigger_validate_own_device(struct iio_trigger *trig, > struct iio_dev *indio_dev); >