Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3465917pxp; Tue, 8 Mar 2022 15:11:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzImkrqHE6NBsZnGcZmVlCP2a0tt6RL9jbugsgFt0CfK8k/B8aMofUFGzQUmUIOuWt1YdVO X-Received: by 2002:a17:903:40c3:b0:151:c8a2:1c46 with SMTP id t3-20020a17090340c300b00151c8a21c46mr20075698pld.141.1646781092397; Tue, 08 Mar 2022 15:11:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646781092; cv=none; d=google.com; s=arc-20160816; b=RpbHf2ZNeDnkeNx5+vkrBby1ZluwgyhISjBaxgkfoGqNrHoNfWkqJRXfQWQPdRI9ht pKRrh1w9W0SLSaXyYT5oVW4I/b32oLdmt5mt88WzOv+96fPY3mFALGMUHKv3C8nISS7J jIIs0bfnkbXTiOWOJDJU7h8sPfmPmwT675ao5mBq95vpt7zMiSwxvWTyJvi3YJiJjeIi jBhi4M/gjwvTnXebMDNyB53WTqYBHygHqtArGxRhm8FCV1RT2fJKS4YCUsUFs26/dEwJ TN+97p2VrTO87GjJT3il122v4tMzpvOvTTJ5Ple1oh+Ab8TcNDdY5wqcEgbJW32ELE99 i00Q== 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=Jb3LOlMf5pk1D9PjLVHGSfg0goBFbrUHnygCupUhgZI=; b=k+kWDxBMKx7LDOUat6FiU+1+l/kEKFEkqXA49vCO1uko6XuFx6hgNwfvR4rqkPWtgN +tJlb2gbiQFrm5/cDb/8PJQIduzat7jR7ND6NK1Bm/ZP+jorw0yVmJYpvpyrCmGsYof9 TrWMjicIUbj2hwGntM36mmGsV1WaFzCBSPnl1tD0qMCYLhi53ogsnqbJDk7ne+CRZUeA mF+jd2IpciRBOo2yH3OUffjpvQkuksl8q0/5pYUYw10sIwwr9AMVr2pz0kwAS7LhofWh U0JzUOtB/UJcCZJwjIff1xqP6bxAbjixDIGe+Hxabv6hSHHCe0Emgsbq2xBroeVV72x0 J8bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iNQpsc5C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s3-20020a17090aad8300b001bf09dd7efasi3503029pjq.128.2022.03.08.15.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 15:11:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iNQpsc5C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C75385AEF1; Tue, 8 Mar 2022 15:08:01 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241756AbiCGTMn (ORCPT + 99 others); Mon, 7 Mar 2022 14:12:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234144AbiCGTMl (ORCPT ); Mon, 7 Mar 2022 14:12:41 -0500 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49AE35641B for ; Mon, 7 Mar 2022 11:11:46 -0800 (PST) Received: by mail-ot1-x32c.google.com with SMTP id w17-20020a056830111100b005b22c584b93so3624660otq.11 for ; Mon, 07 Mar 2022 11:11:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Jb3LOlMf5pk1D9PjLVHGSfg0goBFbrUHnygCupUhgZI=; b=iNQpsc5C47zsL+rwea5Gp9oqE5D8fpUxVHM/oEeqnouFvmu3EH516OlUb2UAnzE9j7 0fKrEb4VlNgNhBDOxV3WTDoN9IjJv7auS6de717hqUuXbO8rfTXzlEGqnVyfSBYs4TRo JbHNYrXbasfzo6mbe5OoZ43yxlqsM24sjqZeKJddKqh+lHn/8ULKrgyJODzAudqWEF2M dZQJtvb/W71PecwPK8ychQ5EwhbpQfCJL6Yz3j/4KX4p5jnGKQKdzSlKW5WRYZOJA82r SQi+26rzzx5f0ztSOvpa211LBscQiorvpyq+3U7Wca8GeWz9ACEhPQLS8pKIgqhbMLjM 9itg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Jb3LOlMf5pk1D9PjLVHGSfg0goBFbrUHnygCupUhgZI=; b=YJiYLklzSmyIORJCDgpC/DjWciLckXgBICxfhFB8+QafHm9/mgbNJAuPvGK68sX2xz it+AlX/ng23qwgJt7JDrrbXXdxipaF8zPOLD9YFYDYLXqgZP9+Fp1d9uctIzRhN+q61y LkAeAM9CQP6JpxPyRjIAf/vTeEP2wYdkzXnIZlciNQp9VPECbRiby6up52ATnJkG+heT DKvHh9fl60lKyV67ci1WW4gtx6xSdnB4duoKEECFTnhCZuaH3fXP5nHQxf7PLi5dqyYh 7TRXd8CGGrnO7JNcH9trYNpsP5x2sqKpGKyeIQ3r0+w8de1oTPVY6CYlGfTnqq8rnIot d47Q== X-Gm-Message-State: AOAM533rksMR1laniYeYK5WgriW9IJXTcstts2opMT3n0HWtzbU/228j 2qzby4G9z+txkYZYzmKpKZJnxQ== X-Received: by 2002:a9d:2045:0:b0:5b2:1052:93fd with SMTP id n63-20020a9d2045000000b005b2105293fdmr6358924ota.259.1646680305167; Mon, 07 Mar 2022 11:11:45 -0800 (PST) Received: from ripper ([2600:1700:a0:3dc8:205:1bff:fec0:b9b3]) by smtp.gmail.com with ESMTPSA id k15-20020a056808068f00b002d91362e56esm6764310oig.1.2022.03.07.11.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 11:11:44 -0800 (PST) Date: Mon, 7 Mar 2022 11:13:28 -0800 From: Bjorn Andersson To: Andy Shevchenko Cc: Rob Herring , Daniel Scally , Heikki Krogerus , Sakari Ailus , "Rafael J. Wysocki" , Hans de Goede , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Dmitry Baryshkov Subject: Re: [PATCH v4 1/7] device property: Helper to match multiple connections Message-ID: References: <20220307034040.1111107-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Mon 07 Mar 02:05 PST 2022, Andy Shevchenko wrote: > On Sun, Mar 06, 2022 at 07:40:34PM -0800, Bjorn Andersson wrote: > > In some cases multiple connections with the same connection id > > needs to be resolved from a fwnode graph. > > > > One such example is when separate hardware is used for performing muxing > > and/or orientation switching of the SuperSpeed and SBU lines in a USB > > Type-C connector. In this case the connector needs to belong to a graph > > with multiple matching remote endpoints, and the Type-C controller needs > > to be able to resolve them both. > > > > Add a new API that allows this kind of lookup. > > Thanks for the update! > > First of all, I have noticed that subject misses the verb, something like Add > or Introduce. > Will update accordingly. > ... > > > +/** > > + * fwnode_connection_find_matches - Find connections from a device node > > + * @fwnode: Device node with the connection > > + * @con_id: Identifier for the connection > > + * @data: Data for the match function > > + * @match: Function to check and convert the connection description > > + * @matches: Array of pointers to fill with matches > > (Optional) array... > Ditto. > > + * @matches_len: Length of @matches > > + * > > + * Find up to @matches_len connections with unique identifier @con_id between > > + * @fwnode and other device nodes. @match will be used to convert the > > + * connection description to data the caller is expecting to be returned > > + * through the @matches array. > > > + * If @matches is NULL @matches_len is ignored and the total number of resolved > > + * matches is returned. > > I would require matches_len to be 0, see below. > > > + * Return: Number of matches resolved, or negative errno. > > + */ > > +int fwnode_connection_find_matches(struct fwnode_handle *fwnode, > > + const char *con_id, void *data, > > + devcon_match_fn_t match, > > + void **matches, unsigned int matches_len) > > +{ > > + unsigned int count_graph; > > + unsigned int count_ref; > > + > > + if (!fwnode || !match) > > + return -EINVAL; > > + > > + count_graph = fwnode_graph_devcon_matches(fwnode, con_id, data, match, > > + matches, matches_len); > > > + if (matches) { > > + matches += count_graph; > > + matches_len -= count_graph; > > + } > > So, the valid case is matches != NULL and matches_len == 0. For example, when > we have run something previously on the buffer and it becomes full. > > In this case we have carefully handle this case. > > if (matches) { > matches += count_graph; > if (matches_len) > matches_len -= count_graph; When matches is non-NULL, both the sub-functions are limited by matches_len and as such count_graph <= matches_len. As such matches_len >= 0. In the event that the originally passed matches_len was 0, then count_graph will be 0 and matches_len will remain 0. I therefor don't see that this additional check changes things. > } > > Seems it can be also > > if (matches) > matches += count_graph; > > if (matches_len) > matches_len -= count_graph; We covered the case of matches && (matches_len || !matches_len) above. For the case of !matches && matches_len, this added conditional would cause matches_len to be extra ignored by keeping it at 0, but per kernel-doc and implementation we ignore all other values already. Note that this is in contrast from vsnprintf() where the code will continue to produce results, only store the first "matches_len" entires and return the final count. Unfortunately we can't follow such semantics here, instead it is clearly documented in the kernel-doc that @matches_len is ignored when @matches is NULL. So unless I'm missing something I don't see what you gain over keeping the check on only matches. > > That said, do we have a test cases for this? > I looked briefly at adding some kunit tests for this, but was discourage by the prospect of building up the graphs to run the tests against. Regards, Bjorn > > + count_ref = fwnode_devcon_matches(fwnode, con_id, data, match, > > + matches, matches_len); > > + > > + return count_graph + count_ref; > > +} > > -- > With Best Regards, > Andy Shevchenko > >