i2c: provide and use i2c_adapter_set_node()
Subsystems (11)
v2 cover i2c: provide and use i2c_adapter_set_node()
It's been another year of discussing the object life-time problems at conferences. I2C is one of the offenders and its problems are more complex than those of some other subsystems. It seems the revocable[1] API may make its way into the kernel this year but even with it in place, I2C won't be able to use it as there's currently nothing to *revoke*. The struct device is embedded within the i2c_adapter struct whose lifetime is tied to the provider device being bound to its driver.
Fixing this won't be fast and easy but nothing's going to happen if we don't start chipping away at it. The ultimate goal in order to be able to use an SRCU-based solution (revocable or otherwise) is to convert the embedded struct device in struct i2c_adapter into an __rcu pointer that can be *revoked*. To that end we need to hide all dereferences of adap->dev in drivers.
I2C drivers use device_set_node() to assign a firmware node directly to the struct device embedded in i2c_adapter. In order to hide the direct
dereferencing: provide a dedicated interface that wraps the call to device_set_node() but takes the adapter as argument instead.
---
Changes in v2:
- add patches replacing ACPI_COMPANION_SET() with i2c_adapter_set_node()
- rebased on top of v7.0-rc1
- collected tags
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Bartosz Golaszewski (9):
i2c: provide i2c_adapter_set_node()
i2c: designware-common: use i2c_adapter_set_node()
i2c: gpio: use i2c_adapter_set_node()
i2c: ljca: use i2c_adapter_set_node()
i2c: ls2x: use i2c_adapter_set_node()
i2c: rzv2m: use i2c_adapter_set_node()
i2c: usbio: use i2c_adapter_set_node()
i2c: designware-amdisp: use i2c_adapter_set_node()
i2c: viai2c-zhaoxin: use i2c_adapter_set_node()
drivers/i2c/busses/i2c-designware-amdisp.c | 2 +- drivers/i2c/busses/i2c-designware-common.c | 2 +- drivers/i2c/busses/i2c-gpio.c | 2 +- drivers/i2c/busses/i2c-ljca.c | 2 +- drivers/i2c/busses/i2c-ls2x.c | 2 +- drivers/i2c/busses/i2c-rzv2m.c | 2 +- drivers/i2c/busses/i2c-usbio.c | 2 +- drivers/i2c/busses/i2c-viai2c-zhaoxin.c | 2 +- include/linux/i2c.h | 7 +++++++ 9 files changed, 15 insertions(+), 8 deletions(-)
---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20251223-i2c-ada-dev-set-node-0636a8d3666c
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
PATCH v2 1/9 i2c: provide i2c_adapter_set_node()
Provide a wrapper around device_set_node() that takes the i2c_adapter as argument. This allows us to hide more dereferencing of the embedded struct device as part of working towards fixing the object lifetime issues in i2c.
--- include/linux/i2c.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/linux/i2c.h +7 -0
@@ -29,6 +29,7 @@ extern const struct device_type i2c_client_type;/* --- General options ------------------------------------------------ */ +struct fwnode_handle ;struct i2c_msg ;struct i2c_adapter ;struct i2c_client ;
@@ -778,6 +779,12 @@ static inline void i2c_set_adapdata(struct i2c_adapter *adap, void *data)dev_set_drvdata (&adap->dev, data); } +static inline void i2c_adapter_set_node (struct i2c_adapter *adap, +struct fwnode_handle *fwnode) +{ +device_set_node (&adap->dev, fwnode); +} +static inline struct i2c_adapter *i2c_parent_is_i2c_adapter (const struct i2c_adapter *adapter) {
Signature · 1 line
2.47.3
PATCH v2 2/9 i2c: designware-common: use i2c_adapter_set_node()
In reply to Bartosz GolaszewskiUse the dedicated wrapper for setting the fwnode of the i2c_adapter. This allows us to hide the dereferencing of the embedded struct device.
--- drivers/i2c/busses/i2c-designware-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-common.c +1 -1
@@ -882,7 +882,7 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)unsigned long irq_flags;int ret; -device_set_node (&dev->adapter.dev,dev_fwnode (dev->dev)); +i2c_adapter_set_node (adap,dev_fwnode (dev->dev)); ret =i2c_dw_init_regmap (dev);if (ret)
Signature · 1 line
2.47.3
PATCH v2 3/9 i2c: gpio: use i2c_adapter_set_node()
In reply to Bartosz GolaszewskiUse the dedicated wrapper for setting the fwnode of the i2c_adapter. This allows us to hide the dereferencing of the embedded struct device.
--- drivers/i2c/busses/i2c-gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-gpio.c +1 -1
@@ -426,7 +426,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) adap->algo_data = bit_data; adap->class =I2C_CLASS_HWMON ; adap->dev.parent = dev; -device_set_node (&adap->dev, fwnode); +i2c_adapter_set_node (adap, fwnode); adap->nr = pdev->id; ret =i2c_bit_add_numbered_bus (adap);
Signature · 1 line
2.47.3
PATCH v2 4/9 i2c: ljca: use i2c_adapter_set_node()
In reply to Bartosz GolaszewskiUse the dedicated wrapper for setting the fwnode of the i2c_adapter. This allows us to hide the dereferencing of the embedded struct device.
--- drivers/i2c/busses/i2c-ljca.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-ljca.c +1 -1
@@ -294,7 +294,7 @@ static int ljca_i2c_probe(struct auxiliary_device *auxdev,dev_name (&auxdev->dev),dev_name (auxdev->dev.parent), ljca_i2c->i2c_info->id); -device_set_node (&ljca_i2c->adap.dev,dev_fwnode (&auxdev->dev)); +i2c_adapter_set_node (&ljca_i2c->adap,dev_fwnode (&auxdev->dev));i2c_set_adapdata (&ljca_i2c->adap, ljca_i2c);auxiliary_set_drvdata (auxdev, ljca_i2c);
Signature · 1 line
2.47.3
PATCH v2 5/9 i2c: ls2x: use i2c_adapter_set_node()
In reply to Bartosz GolaszewskiUse the dedicated wrapper for setting the fwnode of the i2c_adapter. This allows us to hide the dereferencing of the embedded struct device.
--- drivers/i2c/busses/i2c-ls2x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-ls2x.c +1 -1
@@ -312,7 +312,7 @@ static int ls2x_i2c_probe(struct platform_device *pdev) adap->owner =THIS_MODULE ; adap->algo = &ls2x_i2c_algo; adap->timeout =msecs_to_jiffies (100 ); -device_set_node (&adap->dev,dev_fwnode (dev)); +i2c_adapter_set_node (adap,dev_fwnode (dev));i2c_set_adapdata (adap, priv);strscpy (adap->name, pdev->name,sizeof (adap->name));init_completion (&priv->cmd_complete);
Signature · 1 line
2.47.3
PATCH v2 6/9 i2c: rzv2m: use i2c_adapter_set_node()
In reply to Bartosz GolaszewskiUse the dedicated wrapper for setting the fwnode of the i2c_adapter. This allows us to hide the dereferencing of the embedded struct device.
--- drivers/i2c/busses/i2c-rzv2m.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-rzv2m.c +1 -1
@@ -451,7 +451,7 @@ static int rzv2m_i2c_probe(struct platform_device *pdev) adap->quirks = &rzv2m_i2c_quirks; adap->dev.parent = dev; adap->owner =THIS_MODULE ; -device_set_node (&adap->dev,dev_fwnode (dev)); +i2c_adapter_set_node (adap,dev_fwnode (dev));i2c_set_adapdata (adap, priv);strscpy (adap->name, pdev->name,sizeof (adap->name));init_completion (&priv->msg_tia_done);
Signature · 1 line
2.47.3
PATCH v2 7/9 i2c: usbio: use i2c_adapter_set_node()
In reply to Bartosz GolaszewskiUse the dedicated wrapper for setting the fwnode of the i2c_adapter. This allows us to hide the dereferencing of the embedded struct device.
--- drivers/i2c/busses/i2c-usbio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-usbio.c +1 -1
@@ -278,7 +278,7 @@ static int usbio_i2c_probe(struct auxiliary_device *adev,snprintf (i2c->adap.name,sizeof (i2c->adap.name),"%s.%d" ,USBIO_I2C_CLIENT , i2c->adev->id); -device_set_node (&i2c->adap.dev,dev_fwnode (&adev->dev)); +i2c_adapter_set_node (&i2c->adap,dev_fwnode (&adev->dev));auxiliary_set_drvdata (adev, i2c);i2c_set_adapdata (&i2c->adap, i2c);
Signature · 1 line
2.47.3
PATCH v2 8/9 i2c: designware-amdisp: use i2c_adapter_set_node()
In reply to Bartosz GolaszewskiUse the dedicated wrapper for setting the fwnode of the i2c_adapter. This allows us to hide the dereferencing of the embedded struct device.
--- drivers/i2c/busses/i2c-designware-amdisp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-amdisp.c +1 -1
@@ -61,7 +61,7 @@ static int amd_isp_dw_i2c_plat_probe(struct platform_device *pdev) adap = &isp_i2c_dev->adapter; adap->owner =THIS_MODULE ;scnprintf (adap->name,sizeof (adap->name),AMDISP_I2C_ADAP_NAME ); -ACPI_COMPANION_SET (&adap->dev,ACPI_COMPANION (&pdev->dev)); +i2c_adapter_set_node (adap,dev_fwnode (&pdev->dev)); adap->dev.of_node = pdev->dev.of_node;/* use dynamically allocated adapter id */ adap->nr =-1 ;
Signature · 1 line
2.47.3
Andy Shevchenko
reviewerRe: [PATCH v2 8/9] i2c: designware-amdisp: use i2c_adapter_set_node()
Quoted 2 lines · Bartosz Golaszewski
Use the dedicated wrapper for setting the fwnode of the
i2c_adapter. This allows us to hide the dereferencing of the embedded struct device.
This should be united with patch 2.
For this kind of patches I would not make the split like this.
But if Andi is okay to take as is, I won't object (this is minor thing).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 8/9] i2c: designware-amdisp: use i2c_adapter_set_node()
Quoted 10 lines · Andy Shevchenko
Quoted 2 lines · Bartosz Golaszewski
Use the dedicated wrapper for setting the fwnode of the
i2c_adapter. This allows us to hide the dereferencing of the embedded struct device.This should be united with patch 2.
For this kind of patches I would not make the split like this.But if Andi is okay to take as is, I won't object (this is minor thing).
Gah, I folded this into this series but forgot to squash it into the original designware patch. It can be squashed in-tree by Wolfram or I can resend it.
Bart
Wolfram Sang
maintainerRe: [PATCH v2 8/9] i2c: designware-amdisp: use i2c_adapter_set_node()
Quoted 4 lines
Gah, I folded this into this series but forgot to squash it into the original designware patch. It can be squashed in-tree by Wolfram or I can resend it.
Everything got squashed anyhow ;)
PATCH v2 9/9 i2c: viai2c-zhaoxin: use i2c_adapter_set_node()
In reply to Bartosz GolaszewskiUse the dedicated wrapper for setting the fwnode of the i2c_adapter. This allows us to hide the dereferencing of the embedded struct device.
--- drivers/i2c/busses/i2c-viai2c-zhaoxin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-viai2c-zhaoxin.c +1 -1
@@ -323,7 +323,7 @@ static int zxi2c_probe(struct platform_device *pdev) adap->algo = &zxi2c_algorithm; adap->quirks = &zxi2c_quirks; adap->dev.parent = &pdev->dev; -ACPI_COMPANION_SET (&adap->dev,ACPI_COMPANION (&pdev->dev)); +i2c_adapter_set_node (adap,dev_fwnode (&pdev->dev));snprintf (adap->name,sizeof (adap->name),"zhaoxin-%s-%s" ,dev_name (pdev->dev.parent),dev_name (i2c->dev));i2c_set_adapdata (adap, i2c);
Signature · 1 line
2.47.3
Quoted 15 lines · Bartosz Golaszewski
It's been another year of discussing the object life-time problems at conferences. I2C is one of the offenders and its problems are more complex than those of some other subsystems. It seems the revocable[1] API may make its way into the kernel this year but even with it in place, I2C won't be able to use it as there's currently nothing to *revoke*. The struct device is embedded within the
i2c_adapterstruct whose lifetime is tied to the provider device being bound to its driver.Fixing this won't be fast and easy but nothing's going to happen if we don't start chipping away at it. The ultimate goal in order to be able to use an SRCU-based solution (revocable or otherwise) is to convert the embedded struct device in struct
i2c_adapterinto an__rcupointer that can be *revoked*. To that end we need to hide all dereferences ofadap->devin drivers.
Quoted 7 lines
I2C drivers use
device_set_node()to assign a firmware node directly to the struct device embedded ini2c_adapter. In order to hide the direct
dereferencing: provide a dedicated interface that wraps the call todevice_set_node()but takes the adapter as argument instead.
Applied to for-current, squashed...
Quoted 4 lines
---
Changes in v2:
- add patches replacingACPI_COMPANION_SET()withi2c_adapter_set_node()
- rebased on top of v7.0-rc1
... and resolved another merge conflict :/
But despite this minor hickup, thanks a ton for your work! Looking forward to your follow-up patches.
Happy hacking!