From patchwork Mon Apr 24 13:08:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 87026 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2738419vqo; Mon, 24 Apr 2023 06:18:10 -0700 (PDT) X-Google-Smtp-Source: AKy350buRxrchOhzQpMeSC/7WjZtubAy/NzNt5H99RrJY1SvQ8Opo4Hu1bgVq6IskdeTpfGU6lFx X-Received: by 2002:a17:903:32d1:b0:1a6:dc1f:6230 with SMTP id i17-20020a17090332d100b001a6dc1f6230mr16556348plr.55.1682342289738; Mon, 24 Apr 2023 06:18:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682342289; cv=none; d=google.com; s=arc-20160816; b=l9Nb+O7hCZ9NTR3bOifrxeF3oFnxwZfMbbunFYNzKJKRXltEUL6ZERbqDG/4RzvYjO QxIofZa2+FOUevqMr5//LFNM/T0tYYp+uQ9AX7kOxpGIaNA7S5Pa7pKZwt7q94CK+BZs v5ZDjSCOPtxXLeajpiFY9/5FtvRzjCaBHreQkKZyvz6KFHsjy36TY5vfrmqzbySsYBR1 NvlFUNp7cL7Gi5mU5+eRHeGHYMntbRs2MOwPB0apO+LORTFuE+Bpd38wC8LORnnj8dzH PgLlMn/now1I9SKvvtl0M5N95HMThblsz31mhyzI0N4jxFimb8ASyaTAKKTQvsxMIo/u dbHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WL7uFoeDkdqYpddaEcXID1doFO9TkVEZpq0BEErd21g=; b=jeAENOU5agVpeB5+chOOk/s0RhaIhjyjZ7Efuhxq32n9QPNF/upEZeh1fPZa4lFQM0 JEsSt8z3pIhyvc9r0qtg9ANVvV1SBmr+LJCSq+4gSQScPuF18GeIH2xBO3z9HPZMe6yH 6aMTuC3+VCNMBbRJq6085d6Ol/+1uumjpFzGLivCNiMROzENOcVvjLm9J1lsgaxnT/mt TvCvZZFcj8lWqFWKefrsBSW+ukCfWsTq8p9twPbdHjJ4Lmm0zy/pjBZyZwYKlRjQvWmP FHcGdy5sujN7siarkEsfY9D6GDZ+wyCI2HPBbcedyAyPhnNoVufLMy1/AgcXKiV4jCD8 qR3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=PdGRKMWx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ko5-20020a17090307c500b001a04202f77bsi10951400plb.431.2023.04.24.06.17.49; Mon, 24 Apr 2023 06:18:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=PdGRKMWx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231824AbjDXNIp (ORCPT + 99 others); Mon, 24 Apr 2023 09:08:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231855AbjDXNIk (ORCPT ); Mon, 24 Apr 2023 09:08:40 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C716468A; Mon, 24 Apr 2023 06:08:25 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2a8b766322bso41796691fa.1; Mon, 24 Apr 2023 06:08:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682341704; x=1684933704; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=WL7uFoeDkdqYpddaEcXID1doFO9TkVEZpq0BEErd21g=; b=PdGRKMWxs2qOVRcCun4w0093CaT+iYNmy+cQXgFBU33KYpeXLRcuJ07z+trXW9ZnlJ fHk0M6vxp/Morfe53VdYTDEzpC9/yjbGKfPaWqTGjChHi8PRbrB2uMJBlOR24AC3htON SI4ABy6AWt44Z4BTeZYPkswXWLsJerT2oEZbAm/X5Yc/cORT++AWRANjuPpyFpJWbljZ Uoyk0MS7g7lztQrSNZgZA77JrvqeXhkiiurTQH27O9y4Npa20Zh6dD+q5J0gT6AA2OKM 6AQAU5GtVmwG46Q8d6VgRxxW+QmvZ8clsPtkJ+lmk9LSioL0jSqZn9Zm7q2yf9vSwttE PyVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682341704; x=1684933704; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WL7uFoeDkdqYpddaEcXID1doFO9TkVEZpq0BEErd21g=; b=lUmp+juA0rweR6Ygulfz6irBwaU0yS2JUBxI5f1n3mEo1IAWNImlpwqFvkGUneu9J/ 4GNo6zSrqH+NA3GcIe4JBaeiR/pZmxFKAFk9IoF3w+4GQIXy+5aiZq0Ih6U6DGezvWpH VP93ENmT/H7FwE3dbeQrrLvUVjOOBxNVmrWKwk6Ziq7KAhba9NZ1Xd4sFF/lZOuk7IzF 3L3LH1gu6hTgOp9qW1Ed/XW/unZvn4Gw+zrrPjnZAvJYMxFRjR/gauP+qX+Pa7i8OPjx BdZDE+2ortFMaPXDA1+bKwQZ+RTOId4J977rex46kOBEyy0G+9WxtQKKyaCVYIGZLCGX XQFw== X-Gm-Message-State: AAQBX9e0A7QlBhv3Ha48176/yQPYw77lJyfBb9tgZGxMyCq8JCxFYQQV p/r0Pc6NC5JS5v8QZP3cCKc= X-Received: by 2002:a2e:7e03:0:b0:2a7:a3b4:7747 with SMTP id z3-20020a2e7e03000000b002a7a3b47747mr2428968ljc.29.1682341703516; Mon, 24 Apr 2023 06:08:23 -0700 (PDT) Received: from fedora (62-78-225-252.bb.dnainternet.fi. [62.78.225.252]) by smtp.gmail.com with ESMTPSA id h22-20020a2e9ed6000000b002a8ab13b813sm1746248ljk.41.2023.04.24.06.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 06:08:22 -0700 (PDT) Date: Mon, 24 Apr 2023 16:08:19 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Matti Vaittinen , Andy Shevchenko , Zhigang Shi , Shreeya Patel , Paul Gazzillo , Dmitry Osipenko , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/5] iio:trigger: Add simple trigger_validation helper Message-ID: <91fffd0001e8efef90f43fa03026dc0e5e30b4e4.1682340947.git.mazziesaccount@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764063748488631792?= X-GMAIL-MSGID: =?utf-8?q?1764063748488631792?= 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 --- Revision history 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 + * + * 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);