Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2791311rdb; Mon, 4 Dec 2023 07:39:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEeebQbnC+bd/+iSwyYrR66ZCvocbzLn8SEFpzn5XAcbQ78r6LySiEb7qqbeOV4nWP8tY5L X-Received: by 2002:a05:6e02:111:b0:35d:7e05:8b04 with SMTP id t17-20020a056e02011100b0035d7e058b04mr34571ilm.67.1701704358349; Mon, 04 Dec 2023 07:39:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701704358; cv=none; d=google.com; s=arc-20160816; b=hJ/BQgUvpaCMOV93YcwKRTbLX17Kym8ww2T2b9aAjZpZAd9rEVpC4xQChmBBfOj8DV YWsJOaY5VSV+omoWG6afyUoF9gIFTQlx7W5AMaYAhOWfNT0rEi4lLrSfIj6tjFbjL+nI jWcJyjV8LuBgPPOP9f9MYHtzHpFGTSqswbT6J0Ja3NusOfTLjTS49XEPFKsckNihW6U+ C5QvC20ObbI+o1Dav61mJ/GHhulM6hfOf8tb3+cUxxD7R02X8RiUVz0H78ea5Z7H/13r GBuXwsgAZgPzzDqBguFuRhmkhGstsy4uvXUfSIGRwWbSkqxucNNRol00rNOf6TJdvE2d AzgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=KRHj8v9l3kRJSyR9ga6lTdQQmlpytg3850R0ajedFW8=; fh=cdh/zE3CZkKBVPpwlAi1MOirEcAUajw2fxcnBBQCP7U=; b=Ut57SCwOwme7K7t38v3JmS4ufuSQpK46fBmmKyPsSItgDgRVFNn4IM38UQTXl/l+aJ lZrSa777GKrrQlw/zbqBMCqbf1+O2BCOzl3vPF5Eq4RX2haBpnrVd9qYg4FoGGekbGjG WcMaW4EAqC2VjsU29OMGQ1GN6mLJK5rsjNW3lJMl6PtGHpkd1m4pbRRkYysB7lNS6B7m 42CbVRqSWKfcc8L+30LmrNs+C5HvJLf6h6VM7px/y6ok06AIuURI66NobT1mrMlG6mUn 8tIuOIVCOj9kEhOxQOtvhozmDn8qriK2CeYvsW8to40LfmSz01S1BmM+LGb79G8+bEmY JQYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CVZpLFeq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id y188-20020a6364c5000000b005ab6142f1besi7973290pgb.169.2023.12.04.07.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 07:39:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CVZpLFeq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id C146D8082845; Mon, 4 Dec 2023 07:39:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234665AbjLDPjB (ORCPT + 99 others); Mon, 4 Dec 2023 10:39:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234647AbjLDPjA (ORCPT ); Mon, 4 Dec 2023 10:39:00 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E7E1F3 for ; Mon, 4 Dec 2023 07:39:06 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB0F8C433C8; Mon, 4 Dec 2023 15:39:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701704346; bh=G3X+vmde+cr11/lAMlOMQHfGd+SQv6ekjh9J8L55ZRY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CVZpLFeqSXJ+oqgWCvDcEICrbiSZaOdS+ZZIIYPJPyEynaYyEaqQBTFia3KGSAvQM LeA522/+DiQBb67g6AqvgJxMZBGqLnwdqey1BuqYfanwfE7HIyAFqZ4VtZaedSgHW7 wDysUfO7qMGadjo3YCWhj26TQx25+SnUbP1EGwAfc/7m8xr7G20oA8+EoubfK9eqAw AkduxD8F9Tkm1jEW9+WUTo5mRhBMImuICHbMqFzYahEJ4CBdo9v7p9ac0dBvnFRzDF 3GA01P9uc1n7CknA2RYxzjDIB7thFxTfDFeKSXPkvhM5IZwJ7zNO8xBfNZzTautCgc ZPzhPGWeyeFqw== Date: Mon, 4 Dec 2023 15:38:55 +0000 From: Jonathan Cameron To: Nuno Sa via B4 Relay Cc: , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Lars-Peter Clausen , Michael Hennerich Subject: Re: [PATCH 03/12] iio: add the IIO backend framework Message-ID: <20231204153855.71c9926f@jic23-huawei> In-Reply-To: <20231121-dev-iio-backend-v1-3-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> <20231121-dev-iio-backend-v1-3-6a3d542eba35@analog.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 04 Dec 2023 07:39:15 -0800 (PST) On Tue, 21 Nov 2023 11:20:16 +0100 Nuno Sa via B4 Relay wrote: > From: Nuno Sa > > This is a Framework to handle complex IIO aggregate devices. > > The typical architecture is to have one device as the frontend device which > can be "linked" against one or multiple backend devices. All the IIO and > userspace interface is expected to be registers/managed by the frontend > device which will callback into the backends when needed (to get/set > some configuration that it does not directly control). As this is first place backend / frontend terminology used (I think), make sure to give an example so people understand what sorts of IP / devices thes might be. > > The basic framework interface is pretty simple: > - Backends should register themselves with @devm_iio_backend_register() > - Frontend devices should get backends with @devm_iio_backend_get() > > Signed-off-by: Nuno Sa Looks good to me in general. I'll need to have a really close read though before we merge this as there may be sticky corners! (hopefully not) ... > +static LIST_HEAD(iio_back_list); > +static DEFINE_MUTEX(iio_back_lock); > + > +/* > + * Helper macros to properly call backend ops. The main point for these macros > + * is to properly lock the backend mutex on every call plus checking if the > + * backend device is still around (by looking at the *ops pointer). If just checking if it is around rather thank looking for a bug, then I'd suggest a lighter choice than WARN_ON_x Btw, there were some interesting discussions on lifetimes and consumer / provider models at plumbers. I think https://www.youtube.com/watch?v=bHaMMnIH6AM will be the video. Suggested the approach of not refcounting but instead allowing for a deliberate removal of access similar to your check on ops here (and the one we do in core IIO for similar purposes). Sounded interesting but I've not explored what it would really mean to switch to that model yet. > + */ > +#define iio_backend_op_call(back, op, args...) ({ \ > + struct iio_backend *__back = back; \ > + int __ret; \ > + \ > + guard(mutex)(&__back->lock); \ > + if (WARN_ON_ONCE(!__back->ops)) \ > + __ret = -ENODEV; \ > + else if (!__back->ops->op) \ > + __ret = -EOPNOTSUPP; \ > + else \ > + __ret = __back->ops->op(__back, ##args); \ > + \ > + __ret; \ > +})