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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8DBFCC3DA7F for ; Wed, 7 Aug 2024 13:30:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=cVTsGVO8WsmaD67opd83BfGFsRJNsmaLrq0szd22Jso=; b=YWBp/1igLJfiylQMxD0L/DslLi 3Qua+Bs9cdnXZHl6LP+tTsEQYkoz8MhGXWQWQ6KIiUJKcIA7IdvUFh5eUUA4LcHMEfLjjM0z6Z5Fl kbrjTxlTbPVe9eauMHKSQy/tYo9XVcTjQ5dzAp6Kf4Fp+OdTUMkDl0xgBhseTJBrgVcyz21DoyjNj lgDVNQAdjnyAfNa+QubshceUloyJjQKJ0XKNM3Re2fbYczOoHeWGApKbvRdSTu5cxDPYxyJ+1RcD8 W2srcAb6HJPiaS306TA29hcwP7h3dKXpaa4GGAn5bOwvh61paIhwcewRBQsb3TjkgyiG89Nq/AEtP DgoV4T/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbgk0-000000059DD-1EyE; Wed, 07 Aug 2024 13:30:12 +0000 Received: from relay9-d.mail.gandi.net ([217.70.183.199]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbgjR-00000005934-16jX for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 13:29:39 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 1BF49FF803; Wed, 7 Aug 2024 13:29:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723037373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cVTsGVO8WsmaD67opd83BfGFsRJNsmaLrq0szd22Jso=; b=QKrFc1+1fIuGLesvgymIYwFwPnJVb+rjl/ZP2BoUrhJkQHOAu3stwDe1XaFP5f1eyJMV7Z wFUrzvoCkJYAueAKr2mIol3f3K3XFnHB3lxhNmt73ny2WI/AA+vHckq86dKEJbVn8ZVTVP fopVlsEIQ58rnvRhdDkm7fmuAUlvS2UPUxpGQt4oct1orI9nBrxSWPSwmG9Ie8+QR78NQ+ VQLK1LZZBKe5OaArKNDpzmXOn7Q0AyHGbd1bW8c7tpMilCRP7IHd69jdY9f1enEjVKs75E WeC790m5b+uinjI8a4yCuVB45CSGfeUpl4gkjgfMvqsnv0jz1uiwlbo14cMdBg== Date: Wed, 7 Aug 2024 15:29:27 +0200 From: Herve Codina To: Andy Shevchenko Cc: Geert Uytterhoeven , Simon Horman , Lee Jones , Arnd Bergmann , Derek Kiernan , Dragan Cvetic , Greg Kroah-Hartman , Bjorn Helgaas , Philipp Zabel , Lars Povlsen , Steen Hegelund , Daniel Machon , UNGLinuxDriver@microchip.com, Rob Herring , Saravana Kannan , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Horatiu Vultur , Andrew Lunn , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Allan Nielsen , Luca Ceresoli , Thomas Petazzoni , =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: Re: [PATCH v4 3/8] mfd: syscon: Add reference counting and device managed support Message-ID: <20240807152927.22e40284@bootlin.com> In-Reply-To: References: <20240805101725.93947-1-herve.codina@bootlin.com> <20240805101725.93947-4-herve.codina@bootlin.com> Organization: Bootlin X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: herve.codina@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_062938_053317_B6949190 X-CRM114-Status: GOOD ( 26.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Andy, On Mon, 5 Aug 2024 22:20:56 +0200 Andy Shevchenko wrote: > On Mon, Aug 5, 2024 at 12:19 PM 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 > > retrieves? Indeed, will be fixed. > > > 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. > > ... > > > - if (!syscon) > > + if (!syscon) { > > syscon = of_syscon_register(np, check_res); > > + if (IS_ERR(syscon)) > > + return ERR_CAST(syscon); > > + } else { > > + syscon_get(syscon); > > + } > > if (syscon) > return syscon_get(); > > ? > > > + return syscon; Yes and further more, I will remove also the unneeded IS_ERR() and ERR_CAST(). This will lead to just: if (syscon) return syscon_get(syscon); return of_syscon_register(np, check_res); > > ... > > > +static struct regmap *__devm_syscon_get(struct device *dev, > > + struct syscon *syscon) > > +{ > > + struct syscon **ptr; > > + > > + if (IS_ERR(syscon)) > > + return ERR_CAST(syscon); > > + > > + ptr = devres_alloc(devm_syscon_release, sizeof(struct syscon *), GFP_KERNEL); > > + if (!ptr) { > > + syscon_put(syscon); > > + return ERR_PTR(-ENOMEM); > > + } > > + > > + *ptr = syscon; > > + devres_add(dev, ptr); > > + > > + return syscon->regmap; > > Can't the devm_add_action_or_reset() be used in this case? If so, > perhaps a comment to explain why? There is no reason to avoid the use of devm_add_action_or_reset() here. So, I will use it in the next iteration. Thanks for your review. Best regards, Hervé