Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp831237rdb; Sat, 7 Oct 2023 00:37:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+QqZ9gd8VdaCTQhpnUcYCf8vNMctCqP2t5pN1abpZxm+tkouR06EHTufwcMW7MKH4dV8s X-Received: by 2002:a92:cd8d:0:b0:34f:6fd3:f865 with SMTP id r13-20020a92cd8d000000b0034f6fd3f865mr12032365ilb.18.1696664279584; Sat, 07 Oct 2023 00:37:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696664279; cv=none; d=google.com; s=arc-20160816; b=gcQO6IwI+URgmpQqx+8JeE25LQyk/oG7l4RHrlbvlrYccD6H756kqNsRL1mtMaVZG9 +8R6hdgAF0hfOiUgWw11ZHMaNgIJoPbCgB4uHiHkW9kZwnzdoqrJPBPywkZW025AM1z2 HdxdkBK2v8cFR66O+/vB5DeRK0Xp+OWDbVj/xWNWPZjz0+tser3YtnpCayAxa9ylEK6l m3TiI/O9QOBgllNm4TxsmIMNb+b8PanQ2d08k8b2+2hk1wBkIzRXcHGKKnlXSuZ3baJz 8ogOLSC8Z6s1QAIciqH4lO+/S6iBNgzsUB2n/1btTIzZGNSj4H7ECCEinJ2MXPLUTZfM U0xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=FVTCI4ODPafxYQbXQMeXHfwyw0cDGR8VaiIVaILmq9c=; fh=8zzPHVF/p9r0cc6oSFRH8dycuoc95V92ffiysEQGGYk=; b=e2DmN9T2Ai2Cr+18CuM6oM/y/8h0rPJXBGIxGf7p461me01WsyMwFzMmAGKr9V9sXJ KZFaBjYAIlLUhFY2esFv6nPLWgZOLdSZZZcsOi5qTt/QCYW1lFUJSJ7yrK+I1xuEXy5I xWPPn7lugI1/vxWQVKb4olFJvqqMaudBIi0tICqwRL9JxWmV088I1AiigpOEE4Qfh9Mh K3BW6UQENUmRETziQ6Ao2Mdj0l803xWDuXJ0+KQzF+JQVCJybxNpvCjIIlrSuC7pJCI0 Px1zc6PS1/dKC8T2OILYWM5WdJHDhn6SWBwmlpTaNdVO+zKCyiVelYmnGYvJz2GsvQpR wRJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id hk15-20020a17090b224f00b002684bc84493si6023097pjb.131.2023.10.07.00.37.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 00:37:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 2A03780BB5D8; Sat, 7 Oct 2023 00:37:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343684AbjJGHgT (ORCPT + 99 others); Sat, 7 Oct 2023 03:36:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343632AbjJGHgS (ORCPT ); Sat, 7 Oct 2023 03:36:18 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D19F0B9; Sat, 7 Oct 2023 00:36:16 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="363258789" X-IronPort-AV: E=Sophos;i="6.03,205,1694761200"; d="scan'208";a="363258789" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2023 00:36:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="876236536" X-IronPort-AV: E=Sophos;i="6.03,205,1694761200"; d="scan'208";a="876236536" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga004.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2023 00:36:14 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.97-RC1) (envelope-from ) id 1qp1r9-00000003Xnq-2voy; Sat, 07 Oct 2023 10:36:11 +0300 Date: Sat, 7 Oct 2023 10:36:11 +0300 From: Andy Shevchenko To: Bartosz Golaszewski Cc: Linus Walleij , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Dipen Patel , Bartosz Golaszewski Subject: Re: [RFC/RFT PATCH] gpiolib: reverse-assign the fwnode to struct gpio_chip Message-ID: References: <20231006115147.18559-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=2.6 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Sat, 07 Oct 2023 00:37:57 -0700 (PDT) X-Spam-Level: ** On Fri, Oct 06, 2023 at 09:07:49PM +0200, Bartosz Golaszewski wrote: > On Fri, Oct 6, 2023 at 3:24 PM Andy Shevchenko wrote: > > > > On Fri, Oct 06, 2023 at 01:51:47PM +0200, Bartosz Golaszewski wrote: > > > From: Bartosz Golaszewski > > > > > > struct gpio_chip is not only used to carry the information needed to > > > set-up a GPIO device but is also used in all GPIOLIB callbacks and is > > > passed to the matching functions of lookup helpers. > > > > > > In that last case, it is currently impossible to match a GPIO device by > > > fwnode unless it was explicitly assigned to the chip in the provider > > > code. If the fwnode is taken from the parent device, the pointer in > > > struct gpio_chip will remain NULL. > > > > > > If we have a parent device but gc->fwnode was not assigned by the > > > provider, let's assign it ourselves so that lookup by fwnode can work in > > > all cases. ... > > > + gc->fwnode = parent_fwnode; > > > > Ah, this is basically reverts my commit, the whole idea of which was to go > > towards constant struct gpio_chip object that is supplied by a provider. > > Then this idea was wrong in the first place and that goal will never > be achieved. Why not? You always can have internal opaque data structure that takes constant object from the provider. > Whether that's a correct approach is questionable but > struct gpio_chip has become so much more than a simple config > structure and - given how ubiquitous GPIO providers are throughout the > different subsystems of the kernel - it'll stay that way unless we're > ready to rebuild every GPIO provider in linux. > The best we can do now is at least make its usage safe. Meaning: it's > a structure with which providers will interact using GPIOLIB callbacks > which will in turn assure that during the execution of any function > taking struct gpio_chip as argument, it will remain alive and > protected from concurrent access. > > The providers however will continue to use gpio_chip for many > purposes. One of such purposes is matching the GPIO device BY its > backing gpio_chip structure. It not having the same fwnode in this > particular case is an inconsistency rather than design IMO. > > I don't see any good reason for it not having the fwnode assigned. I see it clearly that we don't need to go this dead end. The fwnode used by GPIO devices is not semantically the same as fwnode that is supplied by the provider. Moreover, your patch will bring a clear layering violation since it changes the member behind the owner's back. > User calling gpio_device_find() will have to jump through hoops in > order to match the device by fwnode (include gpiolib.h and dereference > gpiodev?) but it could be very easily facilitated by just assigning it > at registration-time - just like we assign a whole bunch of other > pointers and data structures. No, please do not do this hack with fwnode. -- With Best Regards, Andy Shevchenko