i2c-piix4: Fully initialize SB800 before it is registered
PATCH 1/1 i2c-piix4: Fully initialize SB800 before it is registered
This closes a race window where I2C device drivers attempt to access I2C buses which aren't fully initialized yet.
--- drivers/i2c/busses/i2c-piix4.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/i2c/busses/i2c-piix4.c +9 -10
@@ -627,6 +627,7 @@ static struct i2c_adapter *piix4_main_adstatic struct i2c_adapter *piix4_aux_adapter;static int piix4_add_adapter (struct pci_dev *dev,unsigned short smba, +bool sb800_main,unsigned short port,const char *name,struct i2c_adapter **padap) {struct i2c_adapter *adap;
@@ -641,7 +642,8 @@ static int piix4_add_adapter(struct pci_ adap->owner =THIS_MODULE ; adap->class =I2C_CLASS_HWMON |I2C_CLASS_SPD ; - adap->algo = &smbus_algorithm; + adap->algo = sb800_main ? &piix4_smbus_algorithm_sb800 + : &smbus_algorithm; adapdata =kzalloc (sizeof (*adapdata),GFP_KERNEL );if (adapdata ==NULL ) {
@@ -651,6 +653,8 @@ static int piix4_add_adapter(struct pci_ } adapdata->smba = smba; + adapdata->sb800_main = sb800_main; + adapdata->port = port;/* set up the sysfs linkage to our parent device */ adap->dev.parent = &dev->dev;
@@ -680,17 +684,11 @@ static int piix4_add_adapters_sb800(struint retval;for (port =0 ; port <PIIX4_MAX_ADAPTERS ; port++) { - retval =piix4_add_adapter (dev, smba, + retval =piix4_add_adapter (dev, smba, true, port, piix4_main_port_names_sb800[port], &piix4_main_adapters[port]);if (retval <0 ) goto error; - - piix4_main_adapters[port]->algo = &piix4_smbus_algorithm_sb800; - - adapdata =i2c_get_adapdata (piix4_main_adapters[port]); - adapdata->sb800_main = true; - adapdata->port = port; }return retval;
@@ -748,7 +746,7 @@ static int piix4_probe(struct pci_dev *dreturn retval;/* Try to register main SMBus adapter, give up if we can't */ - retval =piix4_add_adapter (dev, retval,"main" , + retval =piix4_add_adapter (dev, retval, false,0 ,"main" , &piix4_main_adapters[0 ]);if (retval <0 )return retval;
@@ -775,7 +773,8 @@ static int piix4_probe(struct pci_dev *dif (retval >0 ) {/* Try to add the aux adapter if it exists, * piix4_add_adapter will clean up if this fails */ -piix4_add_adapter (dev, retval, piix4_aux_port_name_sb800, +piix4_add_adapter (dev, retval, false,0 , + piix4_aux_port_name_sb800, &piix4_aux_adapter); }
Signature · 2 lines
Jean Delvare SUSE L3 Support
Hi Jean,
Quoted 5 lines
Am 25.01.2016 um 12:17 schrieb Jean Delvare <[email protected]>:
This closes a race window where I2C device drivers attempt to access I2C buses which aren't fully initialized yet.
I’m not sure if it’s common to offer tags as first-time contributor, but feel free to add
Quoted 81 lines
Signed-off-by Jean Delvare <[email protected]>Cc Mika Westerberg <[email protected]>Cc Christian Fetzer <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Wolfram Sang <[email protected]>---
drivers/i2c/busses/i2c-piix4.c| 19 +++++++++----------1 file changed, 9 insertions(+), 10 deletions(-)drivers/i2c/busses/i2c-piix4.c +9
-10@@ -627,6 +627,7 @@ static struct i2c_adapter *piix4_main_adstatic struct i2c_adapter *piix4_aux_adapter;static int piix4_add_adapter (struct pci_dev *dev,unsigned short smba, +bool sb800_main,unsigned short port,const char *name,struct i2c_adapter **padap) {struct i2c_adapter *adap;@@ -641,7 +642,8 @@ static int piix4_add_adapter(struct pci_ adap->owner =THIS_MODULE ; adap->class =I2C_CLASS_HWMON |I2C_CLASS_SPD ; - adap->algo = &smbus_algorithm; + adap->algo = sb800_main ? &piix4_smbus_algorithm_sb800 + : &smbus_algorithm; adapdata =kzalloc (sizeof (*adapdata),GFP_KERNEL );if (adapdata ==NULL ) {@@ -651,6 +653,8 @@ static int piix4_add_adapter(struct pci_ } adapdata->smba = smba; + adapdata->sb800_main = sb800_main; + adapdata->port = port;/* set up the sysfs linkage to our parent device */ adap->dev.parent = &dev->dev;@@ -680,17 +684,11 @@ static int piix4_add_adapters_sb800(struint retval;for (port =0 ; port <PIIX4_MAX_ADAPTERS ; port++) { - retval =piix4_add_adapter (dev, smba, + retval =piix4_add_adapter (dev, smba, true, port, piix4_main_port_names_sb800[port], &piix4_main_adapters[port]);if (retval <0 ) goto error; - - piix4_main_adapters[port]->algo = &piix4_smbus_algorithm_sb800; - - adapdata =i2c_get_adapdata (piix4_main_adapters[port]); - adapdata->sb800_main = true; - adapdata->port = port; }return retval;@@ -748,7 +746,7 @@ static int piix4_probe(struct pci_dev *dreturn retval;/* Try to register main SMBus adapter, give up if we can't */ - retval =piix4_add_adapter (dev, retval,"main" , + retval =piix4_add_adapter (dev, retval, false,0 ,"main" , &piix4_main_adapters[0 ]);if (retval <0 )return retval;@@ -775,7 +773,8 @@ static int piix4_probe(struct pci_dev *dif (retval >0 ) {/* Try to add the aux adapter if it exists, * piix4_add_adapter will clean up if this fails */ -piix4_add_adapter (dev, retval, piix4_aux_port_name_sb800, +piix4_add_adapter (dev, retval, false,0 , + piix4_aux_port_name_sb800, &piix4_aux_adapter); }Signature · 3 lines
-- Jean Delvare SUSE L3 Support
Quoted 2 lines
I’m not sure if it’s common to offer tags as first-time contributor, but feel free to add
Sure, it is! It is extremly helpful for me as a maintainer if someone who reported a problem confirms that the problem is gone now.
Quoted 1 line
Tested-by Christian Fetzer <[email protected]>
Thanks a lot!
Wolfram
Wolfram Sang
AppliedQuoted 8 lines · Jean Delvare
This closes a race window where I2C device drivers attempt to access I2C buses which aren't fully initialized yet.
Signed-off-by Jean Delvare <[email protected]>Cc Mika Westerberg <[email protected]>Cc Christian Fetzer <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Wolfram Sang <[email protected]>
Applied to for-current, thanks!