Message ID | 20231019073533.386563-4-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 fe16csp217216vqb; Thu, 19 Oct 2023 00:37:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJ0Ga9uS9QQ1e3NMEWwSrR0Ck0v+/cT6vjdqAw5bwz2+hc/y/9qkF2pBN5v50Ltg34PeU/ X-Received: by 2002:a05:6870:d87:b0:1ea:137:7dba with SMTP id mj7-20020a0568700d8700b001ea01377dbamr1682672oab.10.1697701043993; 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=rjsveI1S+dEVmwyvI93SP1IyuYxl881beA/q4TCE6eOfDxfbMynBYko4R48DekZ4Q1 E6O0N1uI0FC3/ZTJgt3Hg2a2iqlU8mMzZFZPnIduj5qC+yJIWXGM3VHOvPCK6Fb6g5ND JBUQCOG2c39hEGgd0yPzy0/KSjLQZGH1VAgneOEmAnEIhxKHPD9a3i4XVg15hbigTClF KXKhSVUr1yTlCQQjvhH9LOAzJIzJX2BqiLPaY2koGQAYBLbROCz6n6oO/1IxADcVO+vh 4E6ufYEtqazbREKM9qPr4sQcCi1A1KOcghMeDxxOGXJYnurXjb1rl2KhFHwLgeHCrPD2 hBZQ== 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=wFxDhOHA1nOXegi4jc03C6n7+wwkMRGPrbKDfHusrSk=; fh=vOhmkbio3vldgRDpkNvRPbxSZ54ZZOuVH6tekc4/rDo=; b=jzzcN4TCyBV/cK7zxiqiVgDQDJIsa1thZakBORnI2FFejJektHJb/21T8fbp5Ws1NL unOzObUZv8B2WjtUcg1Af4T/2Ti5GwXQpo2xLMearQV56GLWcp3IPzu+9HC2s1bNQxjD EsVM77gZGkjO9QUf6ezAg/TzbqDBkA7MikLVO1lZORCQ/caZ6Z1ydeNI6z0oAvfZm746 Yh9g6Jf/f5h9J7SIJUGd6Vm9N+N23i9XzF6tb6rZTGkec7P8ThkvDRNfpbVgfU3LAVi9 QWNafmqBdTNt5v5I/U2IYZAgOkML8PREctupoHWMt0JqwT6kk/HqkWQlMs8zVyfz4WEN Ay8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=oIZDd51e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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. [23.128.96.33]) by mx.google.com with ESMTPS id t64-20020a638143000000b00578bab760desi3792547pgd.278.2023.10.19.00.37.23 (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 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=oIZDd51e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 45F688057DB4; Thu, 19 Oct 2023 00:36:26 -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 S235060AbjJSHft (ORCPT <rfc822;zwp10758@gmail.com> + 24 others); Thu, 19 Oct 2023 03:35:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232810AbjJSHfo (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 19 Oct 2023 03:35:44 -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 DFBE4126; Thu, 19 Oct 2023 00:35:41 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPA id BECF76001A; Thu, 19 Oct 2023 07:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1697700940; 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=wFxDhOHA1nOXegi4jc03C6n7+wwkMRGPrbKDfHusrSk=; b=oIZDd51e4WPDovOewLVpzqon29hf6yqKMU4ml/UupSHOM0hr7uGRWapYHOWcoPUh+AYRcp RoYh6KyVzV+fFk/c5u/5uvEPAT90V1hu2D00E1ftPqL8bHD04k8PnE362UOfYH+GLwcVkD +99+4hRHNILhBrp2RWIyD7TTu3RXLj5n46D4XaW0RdTp+Lip8i7c3Kba12b9US1a2hiWp7 WneLhRMx+9AQEWl/f921YBMV5bEx/P+jMwKFOb5iHyXgj4ZvhM4aLW+XqtMvXTQSNILcTl yl2aqUvlAQASPzCBmD2UQX/WKxDekAaFEG8L1ZnGAga5zCB8rm/uR6pU7E7NaQ== 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 3/3] i2c: muxes: i2c-mux-gpmux: Use of_get_i2c_adapter_by_node() Date: Thu, 19 Oct 2023 09:35:30 +0200 Message-ID: <20231019073533.386563-4-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:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780168569687147305 X-GMAIL-MSGID: 1780168569687147305 |
Series |
Fix i2c mux module refcount issues
|
|
Commit Message
Herve Codina
Oct. 19, 2023, 7:35 a.m. UTC
i2c-mux-gpmux 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-gpmux.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Hi! 2023-10-19 at 09:35, Herve Codina wrote: > i2c-mux-gpmux 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: ac8498f0ce53 ("i2c: i2c-mux-gpmux: new driver") Acked-by: Peter Rosin <peda@axentia.se> Cheers, Peter > --- > drivers/i2c/muxes/i2c-mux-gpmux.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/i2c/muxes/i2c-mux-gpmux.c b/drivers/i2c/muxes/i2c-mux-gpmux.c > index baccf4bfaf02..8305661e1253 100644 > --- a/drivers/i2c/muxes/i2c-mux-gpmux.c > +++ b/drivers/i2c/muxes/i2c-mux-gpmux.c > @@ -52,7 +52,7 @@ static struct i2c_adapter *mux_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:26:41 +0200 Peter Rosin <peda@axentia.se> wrote: > Hi! > > 2023-10-19 at 09:35, Herve Codina wrote: > > i2c-mux-gpmux 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: ac8498f0ce53 ("i2c: i2c-mux-gpmux: new driver") > 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-gpmux.c b/drivers/i2c/muxes/i2c-mux-gpmux.c index baccf4bfaf02..8305661e1253 100644 --- a/drivers/i2c/muxes/i2c-mux-gpmux.c +++ b/drivers/i2c/muxes/i2c-mux-gpmux.c @@ -52,7 +52,7 @@ static struct i2c_adapter *mux_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);