[PATCH v2 01/12] i2c: allow setting the parent device and OF node through the adapter struct

Andreas Kemnade andreas at kemnade.info
Mon Mar 2 08:56:40 PST 2026


On Mon, 2 Mar 2026 16:59:28 +0100
Andreas Kemnade <andreas at kemnade.info> wrote:

> On Mon, 2 Mar 2026 03:08:24 -0800
> Bartosz Golaszewski <brgl at kernel.org> wrote:
> 
> > On Mon, 2 Mar 2026 11:38:27 +0100, Kalle Niemi <kaleposti at gmail.com> said:  
> > > On 3/2/26 10:55, Bartosz Golaszewski wrote:    
> > >> On Mon, Mar 2, 2026 at 8:47 AM Kalle Niemi <kaleposti at gmail.com> wrote:    
> > >>> 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 at oss.qualcomm.com>
> > >>>> ---    
> > >>> 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".    
> > >> Wolfram: well, now it would actually be useful to know which commit
> > >> exactly is the culprit so maybe splitting the changes is not a bad
> > >> idea after all.
> > >> Kalle: which i2c bus driver fails here? Any errors in kernel log?
> > >> Bart    
> > >
> > > Hello Bart,
> > >
> > > i2c-1 and i2c-2 are failing. I am not seeing any i2c errors in kernel log. I got two failures without the dmesg available (this is bugged test sequence, and not a kernel crash), but those got the same stdout message "Could not open file ...." as all others.
> > >
> > > -Kalle
> > >    
> > 
> > I meant what driver are you using but I suppose it's i2c-omap.
> > 
> > Can you try the following change and let me know if it fixes the issue?
> > 
> > diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> > index dd8cec9b04c6..01656f82d2c6 100644
> > --- a/drivers/i2c/i2c-core-base.c
> > +++ b/drivers/i2c/i2c-core-base.c
> > @@ -1548,6 +1548,11 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
> >  	if (adap->timeout == 0)
> >  		adap->timeout = HZ;
> > 
> > +	if (!adap->dev.parent)
> > +		adap->dev.parent = adap->parent;
> > +	if (!adap->dev.of_node)
> > +		adap->dev.of_node = adap->of_node;
> > +
> >  	/* register soft irqs for Host Notify */
> >  	res = i2c_setup_host_notify_irq_domain(adap);
> >  	if (res) {
> > @@ -1561,11 +1566,6 @@ 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.
> >   
> No changes here. Devices probe, bus indexes are still shifted.
> If I take that into account, i2cget still works.
> 
> But I think there is no defined order anyways. So if
> I would add e.g. usb device provoding i2c busses early than
> omap-i2c for some odd reason, things were messed anyways.
> 
> On the other hand, just having numbers skipped seems to be odd.
> 
ok, looked around further,
We have aliases, so numbers should be static


i2c_add_adapter calls i2c_register_adapter() as the
last thing, but needs to determine the number earlier.

This seems to help:

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index dd8cec9b04c6..e22d784202b8 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1657,10 +1657,9 @@ static int __i2c_add_numbered_adapter(struct i2c_adapter *adap)
  */
 int i2c_add_adapter(struct i2c_adapter *adapter)
 {
-	struct device *dev = &adapter->dev;
 	int id;
 
-	id = of_alias_get_id(dev->of_node, "i2c");
+	id = of_alias_get_id(adapter->of_node, "i2c");
 	if (id >= 0) {
 		adapter->nr = id;
 		return __i2c_add_numbered_adapter(adapter);

> Regards,
> Andreas
> 
> 




More information about the linux-arm-kernel mailing list