Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp83286lqm; Tue, 30 Apr 2024 13:35:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU7KUnyMZKCrK9RKJdN/b2A+tT64KeNAK/9cUaik779VJdGNQYrpOtE5mvHNkBRw08c9t/kKzgGsNDmcRJETCIgSWC19VhpcWL01zntrQ== X-Google-Smtp-Source: AGHT+IGt+V7lMdhfb2QYqLFjmLPAofNeaIrvtXpMyAe+oy5I6ZD6H9N8w8QAkAy3tbjAuy8tsiB+ X-Received: by 2002:a17:90a:c886:b0:2b2:a04b:cf4a with SMTP id u6-20020a17090ac88600b002b2a04bcf4amr549519pjt.25.1714509304700; Tue, 30 Apr 2024 13:35:04 -0700 (PDT) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id nc5-20020a17090b37c500b002acc88c41c3si13488pjb.144.2024.04.30.13.35.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 13:35:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164710-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=iamRaAMj; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-164710-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164710-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EF059285F50 for ; Tue, 30 Apr 2024 20:35:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 226881A0AFF; Tue, 30 Apr 2024 20:34:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iamRaAMj" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 342D2179B2; Tue, 30 Apr 2024 20:34:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714509293; cv=none; b=P6qbj/yk/+5H/0pzILK1ewOqC9PtUEUsKdkh/bV4BK8sz4EQHh3VqY/9xVzja9fnU4c5TZ/gavNLr8GTmAiSSiRX0tMvT70dXWuvLK2+XNJZpwjcEnQOCpRf2Q+p72hMsERB/dGLcdeVUDuKJjzD0MHTRQ5cJPwv46f9hKYhlkw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714509293; c=relaxed/simple; bh=HtcQHmj985eQ+dg3uqxVTbR5cUoWPjp4+IhThC+KEug=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FqKbcnHHFrfRrifzRL3BLrX93q+ViL/VRbYQzz7W3xc7GI8OVWB6llAr4NUF11+2ebGd+svWZU2UCVS/xrcwA/qVo+CSL/CSXXFpw/TsGLc7GwVH1LX8Ip2sXsKmHOmwchr7S9YJTC2/+P0mdIi5dtxqqOctd0s2JBsUUVioYFM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iamRaAMj; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43DA5C4AF17; Tue, 30 Apr 2024 20:34:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714509292; bh=HtcQHmj985eQ+dg3uqxVTbR5cUoWPjp4+IhThC+KEug=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iamRaAMjbqYlRtYkrz98dWDUYhZmMcb96S8p7LdlmCtD4/yhJ8PQjUQr1Btp+8gJx /6Ch4UmQM5/8EwAfTSUpsknGmRvk/dbKCpr1Pi1Ey1/c9twfezgVcvmFu/YocQjYIC SUZIGp0RKKIKQ8IwXL33Mm7XKs2nHJVMonNJ1bTV/3EOg/+L0TZVZw2+xt2uuvLc98 wUxV/fK8Ts91A178VA8EhaC6AInd5GNuVtvHlJZrwN4NNZ0YAJ7rnbyk/sT8/G5Xfz mXGtJY5YxB7RnPbnatdptWWdxXgCXge1K2zSbKP6Z+2QCbZ5VVL9pVxK8m2qcPsLz5 i9Wr//FfNBRZw== Date: Tue, 30 Apr 2024 21:34:43 +0100 From: Simon Horman To: Herve Codina Cc: Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Lee Jones , Arnd Bergmann , Horatiu Vultur , UNGLinuxDriver@microchip.com, Andrew Lunn , Heiner Kallweit , Russell King , Saravana Kannan , Bjorn Helgaas , Philipp Zabel , Lars Povlsen , Steen Hegelund , Daniel Machon , Alexandre Belloni , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Allan Nielsen , Luca Ceresoli , Thomas Petazzoni , =?utf-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: Re: [PATCH 01/17] mfd: syscon: Add reference counting and device managed support Message-ID: <20240430203443.GG2575892@kernel.org> References: <20240430083730.134918-1-herve.codina@bootlin.com> <20240430083730.134918-2-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240430083730.134918-2-herve.codina@bootlin.com> On Tue, Apr 30, 2024 at 10:37:10AM +0200, Herve Codina wrote: > From: Clément Léger > > Syscon releasing is not supported. > Without release function, unbinding a driver that uses syscon whether > explicitly or due to a module removal left the used syscon in a in-use > state. > > For instance a syscon_node_to_regmap() call from a consumer retrieve a > syscon regmap instance. Internally, syscon_node_to_regmap() can create > syscon instance and add it to the existing syscon list. No API is > available to release this syscon instance, remove it from the list and > free it when it is not used anymore. > > Introduce reference counting in syscon in order to keep track of syscon > usage using syscon_{get,put}() and add a device managed version of > syscon_regmap_lookup_by_phandle(), to automatically release the syscon > instance on the consumer removal. > > Signed-off-by: Clément Léger > Signed-off-by: Herve Codina .. > diff --git a/include/linux/mfd/syscon.h b/include/linux/mfd/syscon.h > index c315903f6dab..164b9bcb49c3 100644 > --- a/include/linux/mfd/syscon.h > +++ b/include/linux/mfd/syscon.h > @@ -15,6 +15,7 @@ > #include > > struct device_node; > +struct device; > > #ifdef CONFIG_MFD_SYSCON > struct regmap *device_node_to_regmap(struct device_node *np); > @@ -28,6 +29,11 @@ struct regmap *syscon_regmap_lookup_by_phandle_args(struct device_node *np, > unsigned int *out_args); > struct regmap *syscon_regmap_lookup_by_phandle_optional(struct device_node *np, > const char *property); > +void syscon_put_regmap(struct regmap *regmap); > + > +struct regmap *devm_syscon_regmap_lookup_by_phandle(struct device *dev, > + struct device_node *np, > + const char *property); > #else > static inline struct regmap *device_node_to_regmap(struct device_node *np) > { > @@ -67,6 +73,18 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle_optional( > return NULL; > } > > +static intline void syscon_put_regmap(struct regmap *regmap) intline -> inline > +{ > +} ..