From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 4B1BE33937A for ; Wed, 22 Jul 2026 10:30:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784716234; cv=none; b=YspUh5YyOVYALEMrWNSmekHNyrQCh2jr4s6tfHNBpIIxtJJDf8OAfBJIyZrYirC7BlT/fwz28xHI3zBzPndTG6pEzddrHDSfjB4Qcn1B1LDEnJa2AUUmJBiep3LF74efh6lk91MxGbqSdf9ALswi5S7OgO50oWfBk0gHEMFkRFc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784716234; c=relaxed/simple; bh=L0BQnRjjmwNPhEZeuNkJTZu8YMoA+JlZ9TPm2t+3H9M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=krpheYc4anNYkRRbch3K65sHmC1IrhUVQqcKatmG+QAlQ3hPEOyxyl4VNRIEBJCy68T/AiljUw/2DAbbbLnlYPbOlXPNiJUpUAsHjs2JjTPz1X1EGeiTy8QW3W8MBxd1gxh0pkGjv7lYwXoxWU5nyvOCg2qedBDbpzTLpOej6Wo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gUjELcEe; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gUjELcEe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49F3D1F00A3E; Wed, 22 Jul 2026 10:30:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784716232; bh=KWbJkpZ4j2mYHK1C30avAe7rpoihQIHt7F/xqeL5iBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gUjELcEepAx83tA9iG/vbjrVGzKanA3ny0wxHcAev2MpUN4/9ctBEo1MRMPt3hVMC n3dGNslPfYhU1CNf9JNzFtzVN7XllPIZL3rG3PcR5GmjJHezVg3b/a+NDH82U4Sv1g 65iHe6H02SSt6go5PHHqPYzkn50jPhzEeMZ4UeWnZBhFt2IBawVEXhdsWe65SW2934 imk1Tw0RDtj+puC7D82+kCnXDVN/A+tXnuScTO9+dSG9sVeA4RKvpempzT0S5pAtMV m5gehg1JKbgPIU/aKcc7+Jin/fWKs+rpuVKW1OqB//YIaL8Civ/wsqG1N25sV9dLrB baNQY/ne3A3/A== From: Sasha Levin To: stable@vger.kernel.org Cc: Hans de Goede , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Andi Shyti , Wolfram Sang , Sasha Levin Subject: [PATCH 5.10.y 3/7] i2c: core: Setup i2c_adapter runtime-pm before calling device_add() Date: Wed, 22 Jul 2026 06:30:24 -0400 Message-ID: <20260722103029.890864-3-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260722103029.890864-1-sashal@kernel.org> References: <2026071657-book-manhandle-a0e6@gregkh> <20260722103029.890864-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Hans de Goede [ Upstream commit 60f68597024d5af727c8a5f5f3b11f246265192b ] Platform glue code, which is not build into the kernel and thus cannot use i2c_register_board_info() may want to use bus_register_notifier() to listen for i2c-adapters to show up on which the platform code needs to manually instantiate platform specific i2c_clients. This results in calling i2c_new_client_device() from the bus notifier which happens near the device_add() call. If the i2c-core has not yet setup runtime-pm (specifically the no-callbacks and ignore-children flags) for the device embedded inside struct i2c_adapter and the driver for the i2c_client calls pm_runtime_set_active() this will trigger the following error inside __pm_runtime_set_status(): "runtime PM trying to activate child device %s but parent (%s) is not active\n" and the i2c_client's runtime-status will not be updated. Split the device_register() call for the adapter into device_initialize() and device_add() and move the pm-runtime init calls inbetween these 2 calls so that the runtime-status can be correctly set when a driver binds from the bus-notifier. Note the moved pm-runtime init calls just override the initial value of some flags in struct device set by device_initialize() and calling these before device_add() is safe. Reviewed-by: Pali Rohár Reviewed-by: Andi Shyti Signed-off-by: Hans de Goede Acked-by: Wolfram Sang Signed-off-by: Andi Shyti Stable-dep-of: 158efa411c57 ("i2c: core: fix adapter probe deferral loop") Signed-off-by: Sasha Levin --- drivers/i2c/i2c-core-base.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 7228ac451dd0f0..1200f5fe41e1fa 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1458,7 +1458,17 @@ static int i2c_register_adapter(struct i2c_adapter *adap) dev_set_name(&adap->dev, "i2c-%d", adap->nr); adap->dev.bus = &i2c_bus_type; adap->dev.type = &i2c_adapter_type; - res = device_register(&adap->dev); + device_initialize(&adap->dev); + + /* + * This adapter can be used as a parent immediately after device_add(), + * setup runtime-pm (especially ignore-children) before hand. + */ + pm_runtime_no_callbacks(&adap->dev); + pm_suspend_ignore_children(&adap->dev, true); + pm_runtime_enable(&adap->dev); + + res = device_add(&adap->dev); if (res) { pr_err("adapter '%s': can't register device (%d)\n", adap->name, res); goto out_list; @@ -1468,10 +1478,6 @@ static int i2c_register_adapter(struct i2c_adapter *adap) if (res) goto out_reg; - pm_runtime_no_callbacks(&adap->dev); - pm_suspend_ignore_children(&adap->dev, true); - pm_runtime_enable(&adap->dev); - res = i2c_init_recovery(adap); if (res == -EPROBE_DEFER) goto out_reg; -- 2.53.0