Message ID | 20231019073533.386563-2-herve.codina@bootlin.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp217207vqb; Thu, 19 Oct 2023 00:37:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE439l+mfPr4fotaMbZqyH7wwbxP9zLswci/4MRQQ7gPJ+mjmpbAwGQXggUUZTseLl73aOC X-Received: by 2002:a05:6830:2693:b0:6b5:ee8f:73af with SMTP id l19-20020a056830269300b006b5ee8f73afmr1732091otu.5.1697701043175; Thu, 19 Oct 2023 00:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697701043; cv=none; d=google.com; s=arc-20160816; b=WeoGPrpBcFQnfHdBJw7nnhMY9cTA0N1kNWEycuMlDjsQCYgsORe9GRW02prCi//LdA yLVeNAF3hLOyUR58mnJvF7x+sQfalPACq3SGfViv/albZ4ux2j0WB3PD9PiJbcL8JaN1 DxA6S0STycCLdM0FqQ7ey13tyrUtaCUImPQ+N0Oqu2kamZhJVKeAfnnoU3Lv0LlJehCu 8LbeEZrgJd0DiMo4E9ug76w+vfhCfkQj2fn5NNEiN8Jo8QKvNuD+ImU+XXqEmXOrJ4pB JEqlJ+KmbmUNEArIKk/F03tYws1AVVSOKrhxlvdD6JPZh5+AyABNKrD3W6HCEDVeGjVm 0NZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VljKvcZf/EXnYo0tKS/DyDEGs7c3doXtHpGuUWARKus=; fh=vOhmkbio3vldgRDpkNvRPbxSZ54ZZOuVH6tekc4/rDo=; b=SFwk9HHBWAnOb5Jqw/r3SK57Qvym0dt8nfzxWG3fWM8pZf2IGMmUAz8irQH615m7zi nqZZDohyuJQXWnYHsDplC3avUJ6aat84RihDIIgTU7+9ZbALSn104pjFv1G9W+CAnvHI nKAVGEpNgWr8LqH8myDwkmW3Swg0rneBDF9cz6qMOTx5nst+ApN0iIPgYGCPmv7nEV+l koFD6xpxHuuzbAz280K3D2H9YT1XHEJYojJo/CIyyK3L2VuJ/RUQDhCuDJbhrkDJycyU 12PrT3zXeKs3UNbpgVhiBOioFm58PwLX+EHtVy03o2ckEL8jVmAvlgbrLZYT5lqGKE3r qMUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=TnGO04pl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id fa40-20020a056a002d2800b0068fdfe29f0asi5803138pfb.88.2023.10.19.00.37.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 00:37:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=TnGO04pl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 0C02D80A58CE; Thu, 19 Oct 2023 00:36:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235202AbjJSHfz (ORCPT <rfc822;zwp10758@gmail.com> + 24 others); Thu, 19 Oct 2023 03:35:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232740AbjJSHfp (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 19 Oct 2023 03:35:45 -0400 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E851123; Thu, 19 Oct 2023 00:35:39 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPA id B29E460015; Thu, 19 Oct 2023 07:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1697700938; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VljKvcZf/EXnYo0tKS/DyDEGs7c3doXtHpGuUWARKus=; b=TnGO04pllN2NdXN8HvmX5Ctmryt7kpBynSUXqeKzaKMbLJqBcYTmT+EZSR5fdav2iKFd89 T8M/NYGVRxeJ3W2eWtlNX94F7P4F6VhOCfasDtJLsZCNfeBG0mVgnP7E3xKWS3uvivyjG6 B1P6bEe4XlpGTrKQ4F/WWnRmCQRjvXQ/cuPuq3ccwaL7VEPipuW+e3ScGSKIdWxKpnjvz6 KrUDWW2tsrhad9MbkUlCH2JpPz+tnq83WGPcLRMeV/Dketbb8G8ezzPR+kedMDISV+Nmv2 TgiNszAXGbrmA+s/4qKQhZ+FvMQfUPjlFBCQuei5S5gAtlpdMITwBvVPdJkJ7g== From: Herve Codina <herve.codina@bootlin.com> To: Wolfram Sang <wsa+renesas@sang-engineering.com>, Peter Rosin <peda@axentia.se> Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Allan Nielsen <allan.nielsen@microchip.com>, Horatiu Vultur <horatiu.vultur@microchip.com>, Steen Hegelund <steen.hegelund@microchip.com>, Thomas Petazzoni <thomas.petazzoni@bootlin.com>, Herve Codina <herve.codina@bootlin.com> Subject: [PATCH 1/3] i2c: muxes: i2c-mux-pinctrl: Use of_get_i2c_adapter_by_node() Date: Thu, 19 Oct 2023 09:35:28 +0200 Message-ID: <20231019073533.386563-2-herve.codina@bootlin.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019073533.386563-1-herve.codina@bootlin.com> References: <20231019073533.386563-1-herve.codina@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: herve.codina@bootlin.com X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 19 Oct 2023 00:36:09 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780168568849595388 X-GMAIL-MSGID: 1780168568849595388 |
Series |
Fix i2c mux module refcount issues
|
|
Commit Message
Herve Codina
Oct. 19, 2023, 7:35 a.m. UTC
i2c-mux-pinctrl uses the pair of_find_i2c_adapter_by_node() /
i2c_put_adapter(). These pair alone is not correct to properly lock the
I2C parent adapter.
Indeed, i2c_put_adapter() decrements the module refcount while
of_find_i2c_adapter_by_node() does not increment it. This leads to an
overflow over zero of the parent adapter user counter.
Use the dedicated function, of_get_i2c_adapter_by_node(), to handle
correctly the module refcount.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
drivers/i2c/muxes/i2c-mux-pinctrl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Hi! 2023-10-19 at 09:35, Herve Codina wrote: > i2c-mux-pinctrl uses the pair of_find_i2c_adapter_by_node() / > i2c_put_adapter(). These pair alone is not correct to properly lock the > I2C parent adapter. > > Indeed, i2c_put_adapter() decrements the module refcount while > of_find_i2c_adapter_by_node() does not increment it. This leads to an > overflow over zero of the parent adapter user counter. Perhaps "... underflow of the parent module refcount."? > > Use the dedicated function, of_get_i2c_adapter_by_node(), to handle > correctly the module refcount. > > Signed-off-by: Herve Codina <herve.codina@bootlin.com> Good find, and sorry about that! Fixes: c4aee3e1b0de ("i2c: mux: pinctrl: remove platform_data") Acked-by: Peter Rosin <peda@axentia.se> Cheers, Peter > --- > drivers/i2c/muxes/i2c-mux-pinctrl.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/i2c/muxes/i2c-mux-pinctrl.c b/drivers/i2c/muxes/i2c-mux-pinctrl.c > index 18236b9fa14a..6ebca7bfd8a2 100644 > --- a/drivers/i2c/muxes/i2c-mux-pinctrl.c > +++ b/drivers/i2c/muxes/i2c-mux-pinctrl.c > @@ -62,7 +62,7 @@ static struct i2c_adapter *i2c_mux_pinctrl_parent_adapter(struct device *dev) > dev_err(dev, "Cannot parse i2c-parent\n"); > return ERR_PTR(-ENODEV); > } > - parent = of_find_i2c_adapter_by_node(parent_np); > + parent = of_get_i2c_adapter_by_node(parent_np); > of_node_put(parent_np); > if (!parent) > return ERR_PTR(-EPROBE_DEFER);
Hi Peter, On Thu, 19 Oct 2023 11:25:35 +0200 Peter Rosin <peda@axentia.se> wrote: > Hi! > > 2023-10-19 at 09:35, Herve Codina wrote: > > i2c-mux-pinctrl uses the pair of_find_i2c_adapter_by_node() / > > i2c_put_adapter(). These pair alone is not correct to properly lock the > > I2C parent adapter. > > > > Indeed, i2c_put_adapter() decrements the module refcount while > > of_find_i2c_adapter_by_node() does not increment it. This leads to an > > overflow over zero of the parent adapter user counter. > > Perhaps "... underflow of the parent module refcount."? Yes, will be changed in the next iteration. > > > > > Use the dedicated function, of_get_i2c_adapter_by_node(), to handle > > correctly the module refcount. > > > > Signed-off-by: Herve Codina <herve.codina@bootlin.com> > > Good find, and sorry about that! > > Fixes: c4aee3e1b0de ("i2c: mux: pinctrl: remove platform_data") > Acked-by: Peter Rosin <peda@axentia.se> > Will be added in the next iteration. Thanks for the review, Hervé
diff --git a/drivers/i2c/muxes/i2c-mux-pinctrl.c b/drivers/i2c/muxes/i2c-mux-pinctrl.c index 18236b9fa14a..6ebca7bfd8a2 100644 --- a/drivers/i2c/muxes/i2c-mux-pinctrl.c +++ b/drivers/i2c/muxes/i2c-mux-pinctrl.c @@ -62,7 +62,7 @@ static struct i2c_adapter *i2c_mux_pinctrl_parent_adapter(struct device *dev) dev_err(dev, "Cannot parse i2c-parent\n"); return ERR_PTR(-ENODEV); } - parent = of_find_i2c_adapter_by_node(parent_np); + parent = of_get_i2c_adapter_by_node(parent_np); of_node_put(parent_np); if (!parent) return ERR_PTR(-EPROBE_DEFER);