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 X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30C1AC43461 for ; Fri, 23 Apr 2021 15:12:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0418961463 for ; Fri, 23 Apr 2021 15:12:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242953AbhDWPN3 (ORCPT ); Fri, 23 Apr 2021 11:13:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242963AbhDWPN3 (ORCPT ); Fri, 23 Apr 2021 11:13:29 -0400 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56190C061574 for ; Fri, 23 Apr 2021 08:12:51 -0700 (PDT) Received: by mail-oi1-x236.google.com with SMTP id v6so21672692oiv.3 for ; Fri, 23 Apr 2021 08:12:51 -0700 (PDT) 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=ObtCFyu1lxrPCFSgoh4NgfCuSYVXboqEwODlVJ1EKvI=; b=DaGiJ/QYUDjhqCMpf3AGbghtfWxCFA62bxDROcqSkUHOAZwGWSLMsALpnd/x6wP0z+ DZpGEan86jPhPdfNikC5zz3TQ2VEFkCZDch9NaxaUXuRX31Wt6DQf3HPqsSL9WG2lkUh dkxsFtLiOCRhwG7OPIrxQowcXHoEyAE4BeIadEYqe4CuKd88Ben4bQ9aWwDln6X6KEVN u0McF18b47lFDh8bpnZc4bcy2Rd8Zsp/6KfNPqBlDy+bLqTnhiwaCK4ede5HllTREAjx wf9eYHiYNrn85IM+yl8tCmd3n7vgJ/cscLzVfmXhyFBf235qPJOlnBvX7SDtDq4jH52R kdsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ObtCFyu1lxrPCFSgoh4NgfCuSYVXboqEwODlVJ1EKvI=; b=GxjZhChNuUp1ZNLDqotUjQjZTMaG5dx+B7sRw77b5nc4n7jSTMu6kCDZdGPSe8uOAK PY1Q2BASpfOAooq2nonueKGwXiM80YyKd+N4cGNRy2Xa/wDZ2FLDrIW9R+Oa3B6L+0Wp 7HXgxe5G6MVHrvpcGDkJldD9lFf0ZnC25BBs6BU7ap43uljaZrqUajhSBx7FxOMQRlHv ISMBh7+jorYoM+5J1V5KmFCYuzpkEIdAeRILu6OIdM5v9WGSkSpoi+H9OTK+JRErEI5f NCLT9QxoYGheXSsRqMwZHIMaZXQe+SVZ3qqd4A/7dL2QiKYpE9MFvcdkF7SBmpeXT6Gj i4yA== X-Gm-Message-State: AOAM5338r62P22zt1VHfVniONrN2eNkxU6NuMJgQ5Pq0oh4D7MTLgcoV nZAFEaFVtRrTW9+/JZoyZgp1Sw== X-Google-Smtp-Source: ABdhPJzXAb/hpVXGVKnRkSPipF2bDQHNGTN4HtZ+Whgs/tUaVIWd8s3Cbs+BY52N8zwzBcQCdpa2vw== X-Received: by 2002:aca:49d2:: with SMTP id w201mr4532456oia.154.1619190770043; Fri, 23 Apr 2021 08:12:50 -0700 (PDT) Received: from builder.lan (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id k24sm1300408oic.51.2021.04.23.08.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Apr 2021 08:12:49 -0700 (PDT) Date: Fri, 23 Apr 2021 10:12:47 -0500 From: Bjorn Andersson To: Douglas Anderson , Wolfram Sang Cc: Andrzej Hajda , Neil Armstrong , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Sam Ravnborg , Stephen Boyd , robdclark@chromium.org, Maarten Lankhorst , Stanislav Lisovskiy , Steev Klimaszewski , linux-arm-msm@vger.kernel.org, Linus W , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 21/27] i2c: i2c-core-of: Fix corner case of finding adapter by node Message-ID: References: <20210416223950.3586967-1-dianders@chromium.org> <20210416153909.v4.21.Ib7e3a4af2f3e2cb3bd8e4adbac3bcfc966f27791@changeid> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210416153909.v4.21.Ib7e3a4af2f3e2cb3bd8e4adbac3bcfc966f27791@changeid> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org On Fri 16 Apr 17:39 CDT 2021, Douglas Anderson wrote: > The of_find_i2c_adapter_by_node() could end up failing to find an > adapter in certain conditions. Specifically it's possible that > of_dev_or_parent_node_match() could end up finding an I2C client in > the list and cause bus_find_device() to stop early even though an I2C > adapter was present later in the list. > > Let's move the i2c_verify_adapter() into the predicate function to > prevent this. Now we'll properly skip over the I2C client and be able > to find the I2C adapter. > > This issue has always been a potential problem if a single device tree > node could represent both an I2C client and an adapter. I believe this > is a sane thing to do if, for instance, an I2C-connected DP bridge > chip is present. The bridge chip is an I2C client but it can also > provide an I2C adapter (DDC tunneled over AUX channel). We don't want > to have to create a sub-node just so a panel can link to it with the > "ddc-i2c-bus" property. > > I believe that this problem got worse, however, with commit > e814e688413a ("i2c: of: Try to find an I2C adapter matching the > parent"). Starting at that commit it would be even easier to > accidentally miss finding the adapter. > Reviewed-by: Bjorn Andersson > Signed-off-by: Douglas Anderson > --- > This commit is sorta just jammed into the middle of my series. It has > no dependencies on the earlier patches in the series and I think it > can land independently in the i2c tree. Later patches in the series > won't work right without this one, but they won't crash. If we can't > find the i2c bus we'll just fall back to the hardcoded panel modes > which, at least today, all panels have. > @Wolfram, I know it's late, but perhaps you could consider picking this up for 5.13? It has no dependencies on the other patches in the series and would simplify merging the rest in the next cycle. Regards, Bjorn > I'll also note that part of me wonders if we should actually fix this > further to run two passes through everything: first look to see if we > find an exact match and only look at the parent pointer if there is no > match. I don't currently have a need for that and it's a slightly > bigger change, but it seems conceivable that it could affect someone? > > (no changes since v1) > > drivers/i2c/i2c-core-of.c | 17 ++++++++++------- > 1 file changed, 10 insertions(+), 7 deletions(-) > > diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c > index 3ed74aa4b44b..de0bf5fce3a2 100644 > --- a/drivers/i2c/i2c-core-of.c > +++ b/drivers/i2c/i2c-core-of.c > @@ -124,6 +124,14 @@ static int of_dev_or_parent_node_match(struct device *dev, const void *data) > return 0; > } > > +static int of_i2c_adapter_match(struct device *dev, const void *data) > +{ > + if (!of_dev_or_parent_node_match(dev, data)) > + return 0; > + > + return !!i2c_verify_adapter(dev); > +} > + > /* must call put_device() when done with returned i2c_client device */ > struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) > { > @@ -146,18 +154,13 @@ EXPORT_SYMBOL(of_find_i2c_device_by_node); > struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node) > { > struct device *dev; > - struct i2c_adapter *adapter; > > dev = bus_find_device(&i2c_bus_type, NULL, node, > - of_dev_or_parent_node_match); > + of_i2c_adapter_match); > if (!dev) > return NULL; > > - adapter = i2c_verify_adapter(dev); > - if (!adapter) > - put_device(dev); > - > - return adapter; > + return to_i2c_adapter(dev); > } > EXPORT_SYMBOL(of_find_i2c_adapter_by_node); > > -- > 2.31.1.368.gbe11c130af-goog >