Re: [PATCH v2 01/12] i2c: allow setting the parent device and OF node through the adapter struct
From: Kalle Niemi
Date: Mon Mar 02 2026 - 02:47:28 EST
On 2/23/26 11:05, Bartosz Golaszewski wrote:
In order to stop i2c bus drivers from dereferencing the struct device
embedded in struct i2c_adapter, let's allow configuring the parent
device and OF-node of the adapter directly through dedicated fields.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
---
drivers/i2c/i2c-core-base.c | 5 +++++
include/linux/i2c.h | 4 ++++
2 files changed, 9 insertions(+)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 9c46147e3506d15d53b9b7d6b592709de56e41b9..dd8cec9b04c64b8340d20e018ab5ba28f1f7f5c9 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1561,6 +1561,11 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
adap->dev.type = &i2c_adapter_type;
device_initialize(&adap->dev);
+ if (!adap->dev.parent)
+ adap->dev.parent = adap->parent;
+ if (!adap->dev.of_node)
+ adap->dev.of_node = adap->of_node;
+
/*
* This adapter can be used as a parent immediately after device_add(),
* setup runtime-pm (especially ignore-children) before hand.
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 20fd41b51d5c85ee1665395c07345faafd8e2fca..72677f29aff161530bc3c497d1e07144a44eb9e4 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -761,6 +761,10 @@ struct i2c_adapter {
struct irq_domain *host_notify_domain;
struct regulator *bus_regulator;
+ /* Device configuration. */
+ struct device *parent;
+ struct device_node *of_node;
+
struct dentry *debugfs;
/* 7bit address space */
Hello,
Automated driver test system bisected this commit to be the first bad commit, linux-next next-20260227 was tested. Failed tests include driver tests for ROHM PMIC and accelerometers, which are connected to BeagleBone Black.
The failed driver tests all fail to first i2cget and the tests stop there: "Could not open file '/dev/i2c-2' or 'dev/i2c/2': No such file or directory".
BR
Kalle Niemi