i2c: i801: Use PCI bus rescan mutex to protect P2SB access
PATCH 1/1 i2c: i801: Use PCI bus rescan mutex to protect P2SB access
As pointed out by Andy in [0] using a local mutex here isn't strictly wrong but not sufficient. We should hold the PCI rescan lock for P2SB operations.
[0] https://www.spinics.net/lists/linux-i2c/msg52717.html
--- drivers/i2c/busses/i2c-i801.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-i801.c +2 -3
@@ -1493,7 +1493,6 @@ static struct platform_device * i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev, struct resource *tco_res) { - static DEFINE_MUTEX(p2sb_mutex); struct resource *res;unsigned int devfn;u64 base64_addr;
@@ -1506,7 +1505,7 @@ i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev,* enumerated by the PCI subsystem, so we need to unhide/hide it * to lookup the P2SB BAR. */ -mutex_lock (&p2sb_mutex); +pci_lock_rescan_remove (); devfn =PCI_DEVFN (PCI_SLOT (pci_dev->devfn),1 );
@@ -1524,7 +1523,7 @@ i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev,/* Hide the P2SB device, if it was hidden before */ if (hidden)pci_bus_write_config_byte (pci_dev->bus, devfn,0xe1 , hidden); -mutex_unlock (&p2sb_mutex); +pci_unlock_rescan_remove (); res = &tco_res[1 ];if (pci_dev->device ==PCI_DEVICE_ID_INTEL_DNV_SMBUS )
Signature · 1 line
2.33.0
Quoted 3 lines · Heiner Kallweit
As pointed out by Andy in [0] using a local mutex here isn't strictly wrong but not sufficient. We should hold the PCI rescan lock for P2SB operations.
Thanks!
Quoted 42 lines
[0] https://www.spinics.net/lists/linux-i2c/msg52717.html
Fixes 1a987c69ce2c ("i2c: i801: make p2sb_spinlock a mutex")Reported-by Andy Shevchenko <[email protected]>Signed-off-by Heiner Kallweit <[email protected]>--- drivers/i2c/busses/i2c-i801.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/i2c/busses/i2c-i801.c +2
-3@@ -1493,7 +1493,6 @@ static struct platform_device * i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev, struct resource *tco_res) { - static DEFINE_MUTEX(p2sb_mutex); struct resource *res;unsigned int devfn;u64 base64_addr;@@ -1506,7 +1505,7 @@ i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev,* enumerated by the PCI subsystem, so we need to unhide/hide it * to lookup the P2SB BAR. */ -mutex_lock (&p2sb_mutex); +pci_lock_rescan_remove (); devfn =PCI_DEVFN (PCI_SLOT (pci_dev->devfn),1 );@@ -1524,7 +1523,7 @@ i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev,/* Hide the P2SB device, if it was hidden before */ if (hidden)pci_bus_write_config_byte (pci_dev->bus, devfn,0xe1 , hidden); -mutex_unlock (&p2sb_mutex); +pci_unlock_rescan_remove (); res = &tco_res[1 ];if (pci_dev->device ==PCI_DEVICE_ID_INTEL_DNV_SMBUS )Signature · 1 line
2.33.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Heiner,
Quoted 35 lines · Heiner Kallweit
As pointed out by Andy in [0] using a local mutex here isn't strictly wrong but not sufficient. We should hold the PCI rescan lock for P2SB operations.
[0] https://www.spinics.net/lists/linux-i2c/msg52717.html
Fixes 1a987c69ce2c ("i2c: i801: make p2sb_spinlock a mutex")Reported-by Andy Shevchenko <[email protected]>Signed-off-by Heiner Kallweit <[email protected]>--- drivers/i2c/busses/i2c-i801.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/i2c/busses/i2c-i801.c +1
-2@@ -1493,7 +1493,6 @@ static struct platform_device * i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev, struct resource *tco_res) { - static DEFINE_MUTEX(p2sb_mutex); struct resource *res;unsigned int devfn;u64 base64_addr;@@ -1506,7 +1505,7 @@ i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev,* enumerated by the PCI subsystem, so we need to unhide/hide it * to lookup the P2SB BAR. */ -mutex_lock (&p2sb_mutex); +pci_lock_rescan_remove (); devfn =PCI_DEVFN (PCI_SLOT (pci_dev->devfn),1 );
drivers/i2c/busses/i2c-i801.c i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev, · line 1529
Quoted 8 lines
drivers/i2c/busses/i2c-i801.c +1
-1@@ -1524,7 +1523,7 @@ i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev,/* Hide the P2SB device, if it was hidden before */ if (hidden)pci_bus_write_config_byte (pci_dev->bus, devfn,0xe1 , hidden); -mutex_unlock (&p2sb_mutex); +pci_unlock_rescan_remove (); res = &tco_res[1 ];if (pci_dev->device ==PCI_DEVICE_ID_INTEL_DNV_SMBUS )
Looks good to me.
Signature · 2 lines
Jean Delvare SUSE L3 Support
Wolfram Sang
AppliedQuoted 9 lines · Heiner Kallweit
As pointed out by Andy in [0] using a local mutex here isn't strictly wrong but not sufficient. We should hold the PCI rescan lock for P2SB operations.
[0] https://www.spinics.net/lists/linux-i2c/msg52717.html
Fixes 1a987c69ce2c ("i2c: i801: make p2sb_spinlock a mutex")Reported-by Andy Shevchenko <[email protected]>Signed-off-by Heiner Kallweit <[email protected]>
Applied to for-next, thanks!