From patchwork Thu Oct 19 10:10:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 736002 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4EC7CDB483 for ; Thu, 19 Oct 2023 10:10:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345228AbjJSKK1 (ORCPT ); Thu, 19 Oct 2023 06:10:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345212AbjJSKK0 (ORCPT ); Thu, 19 Oct 2023 06:10:26 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF415123; Thu, 19 Oct 2023 03:10:24 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPA id EACCAC000C; Thu, 19 Oct 2023 10:10:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1697710223; 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=V00s/mVGgaCRB68RBbwNCsl4DRqLwcfW3IIuO/Z+Vmg=; b=RadoXgs4AZdQ45Rq8OCGmJcQ40bBQg7gztQWIZIhduC3qK/ToTZ5eYQHiS09J8F1qNeP8F tv4Sxge0hkziPnEY6JYWltoJOytUHgzt3MJKXELQJ6SfqfdIWwLEUfUZIlaFczhKOZz/5I Wum13MlhF6qQYoNFgxNtILhGi04ePLDGiaIAbqappzd6pZzfeayBLgNSZrfxfCZPN+d46u O5dMJxlGfCOPGdcJ10KrtOu8ALmxreJsvRbHJ+kPQ55C4RBsiVS/3EMENw/dL0xu8rABod usCkvcpv3phCB9lQfoXP4gQXu8tOcuci9emdJ7kaVArJqQ5GK7a8Jl8nK9XYQg== From: Herve Codina To: Wolfram Sang , Peter Rosin , Stephen Warren , Rob Herring , Greg Kroah-Hartman , Jonathan Cameron Cc: Wolfram Sang , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Steen Hegelund , Thomas Petazzoni , Herve Codina Subject: [PATCH v2 1/3] i2c: muxes: i2c-mux-pinctrl: Use of_get_i2c_adapter_by_node() Date: Thu, 19 Oct 2023 12:10:14 +0200 Message-ID: <20231019101017.425284-2-herve.codina@bootlin.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019101017.425284-1-herve.codina@bootlin.com> References: <20231019101017.425284-1-herve.codina@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: herve.codina@bootlin.com Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org 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 underflow of the parent module refcount. Use the dedicated function, of_get_i2c_adapter_by_node(), to handle correctly the module refcount. Fixes: c4aee3e1b0de ("i2c: mux: pinctrl: remove platform_data") Signed-off-by: Herve Codina Acked-by: Peter Rosin Reviewed-by: Jonathan Cameron --- 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); From patchwork Thu Oct 19 10:10:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 736468 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1985FCDB465 for ; Thu, 19 Oct 2023 10:10:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345242AbjJSKKa (ORCPT ); Thu, 19 Oct 2023 06:10:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345237AbjJSKK3 (ORCPT ); Thu, 19 Oct 2023 06:10:29 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E6EE11F; Thu, 19 Oct 2023 03:10:26 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPA id 862ADC0010; Thu, 19 Oct 2023 10:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1697710225; 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=W7jPRQFKI6wZgsciHnAMnsGgniJttHvKS7IyImeZkgA=; b=PNSe1bRtywJ7gCCE1egZvrQC80IKxPe6enwYn8KLh9BNuZceqnxTvz6ghYJf5GWGXFRgz5 O3b2RaS72HH4iUr0gUtn9gy1hCCqcRDnf/WORf6WREciPdFPWcqdmw6oIYJCIwljYdlzcZ AAEljCWFxLr62AJp8O8xjbdWb71vFQkEkc5Uk8w6i2esSaWV0OSiNc9PgP/aZYUOtzhHdU UJfGHmpjWnsLejK5mJYprbSSXx5Q7Mdn8qFNThFvdeUatYz0zyZMPiHarxN3WTiXfoWbwj tsjsLd0ucoU4r/jH6uLDIJDzkkaqG95ephnsCpb7M1g1FWMWJaIzQEPtnujhTg== From: Herve Codina To: Wolfram Sang , Peter Rosin , Stephen Warren , Rob Herring , Greg Kroah-Hartman , Jonathan Cameron Cc: Wolfram Sang , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Steen Hegelund , Thomas Petazzoni , Herve Codina Subject: [PATCH v2 2/3] i2c: muxes: i2c-demux-pinctrl: Use of_get_i2c_adapter_by_node() Date: Thu, 19 Oct 2023 12:10:15 +0200 Message-ID: <20231019101017.425284-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019101017.425284-1-herve.codina@bootlin.com> References: <20231019101017.425284-1-herve.codina@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: herve.codina@bootlin.com Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org i2c-demux-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 underflow of the parent module refcount. Use the dedicated function, of_get_i2c_adapter_by_node(), to handle correctly the module refcount. Fixes: 50a5ba876908 ("i2c: mux: demux-pinctrl: add driver") Signed-off-by: Herve Codina Acked-by: Peter Rosin Reviewed-by: Jonathan Cameron --- drivers/i2c/muxes/i2c-demux-pinctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/muxes/i2c-demux-pinctrl.c b/drivers/i2c/muxes/i2c-demux-pinctrl.c index 22f2280eab7f..9f2e4aa28159 100644 --- a/drivers/i2c/muxes/i2c-demux-pinctrl.c +++ b/drivers/i2c/muxes/i2c-demux-pinctrl.c @@ -61,7 +61,7 @@ static int i2c_demux_activate_master(struct i2c_demux_pinctrl_priv *priv, u32 ne if (ret) goto err; - adap = of_find_i2c_adapter_by_node(priv->chan[new_chan].parent_np); + adap = of_get_i2c_adapter_by_node(priv->chan[new_chan].parent_np); if (!adap) { ret = -ENODEV; goto err_with_revert; From patchwork Thu Oct 19 10:10:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 736001 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 010D7CDB482 for ; Thu, 19 Oct 2023 10:10:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345246AbjJSKKb (ORCPT ); Thu, 19 Oct 2023 06:10:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345206AbjJSKK3 (ORCPT ); Thu, 19 Oct 2023 06:10:29 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E39BF11D; Thu, 19 Oct 2023 03:10:27 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPA id 28575C0012; Thu, 19 Oct 2023 10:10:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1697710226; 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=f2DfQVfMOTqX54BnA6Gk9Zbew9GqeeC0hjdrSJyySQk=; b=L1gjMYuaxDZELtkF3+eTQVZ2YaMlzad1cYuHCVsW3VpKNTEusFo2LUj3IADZkPPmJdLFIz 2ObVkQYrkTW4Eciqf5qzd1/sek+1I4YvPc4+OmOG/vIOM5yUIloPFfMCE6yq4GdS6kmvYA +ZOyGg+blKXU0dIMl+69tJvlrNjxgAAdebxYDcNXJopDsiTCWtYATh3MIPvGofFUWYdlAP PmCDbnYA7k4VYX/QPJ7AwHTGT6w3feTHExQ+ORt7Or7KOBKsWa5/mrvlPeijS+o1tXVU6J V8ZTHzO9b5/CDRKvoo6xdenYu1hJob+uvn5uVFdwoB606zRePxe9xaJ9GpOh2g== From: Herve Codina To: Wolfram Sang , Peter Rosin , Stephen Warren , Rob Herring , Greg Kroah-Hartman , Jonathan Cameron Cc: Wolfram Sang , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Steen Hegelund , Thomas Petazzoni , Herve Codina Subject: [PATCH v2 3/3] i2c: muxes: i2c-mux-gpmux: Use of_get_i2c_adapter_by_node() Date: Thu, 19 Oct 2023 12:10:16 +0200 Message-ID: <20231019101017.425284-4-herve.codina@bootlin.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019101017.425284-1-herve.codina@bootlin.com> References: <20231019101017.425284-1-herve.codina@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: herve.codina@bootlin.com Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org 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 underflow of the parent module refcount. Use the dedicated function, of_get_i2c_adapter_by_node(), to handle correctly the module refcount. Fixes: ac8498f0ce53 ("i2c: i2c-mux-gpmux: new driver") Signed-off-by: Herve Codina Acked-by: Peter Rosin Reviewed-by: Jonathan Cameron --- 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);