Commit e290625e authored by Mark M. Hoffman's avatar Mark M. Hoffman Committed by Greg Kroah-Hartman

[PATCH] I2C: i2c-piix4.c bugfix

This patch fixes a "Trying to release non-existent resource" error that
occurs during rmmod when the device isn't actually present.  It includes
some other cleanups too: error paths, whitespace, magic numbers, __devinit.
parent c8609416
...@@ -68,6 +68,9 @@ struct sd { ...@@ -68,6 +68,9 @@ struct sd {
#define SMBSLVEVT (0xA + piix4_smba) #define SMBSLVEVT (0xA + piix4_smba)
#define SMBSLVDAT (0xC + piix4_smba) #define SMBSLVDAT (0xC + piix4_smba)
/* count for request_region */
#define SMBIOSIZE 8
/* PCI Address Constants */ /* PCI Address Constants */
#define SMBBA 0x090 #define SMBBA 0x090
#define SMBHSTCFG 0x0D2 #define SMBHSTCFG 0x0D2
...@@ -112,14 +115,13 @@ MODULE_PARM_DESC(fix_hstcfg, ...@@ -112,14 +115,13 @@ MODULE_PARM_DESC(fix_hstcfg,
static int piix4_transaction(void); static int piix4_transaction(void);
static unsigned short piix4_smba = 0; static unsigned short piix4_smba = 0;
static struct i2c_adapter piix4_adapter; static struct i2c_adapter piix4_adapter;
/* /*
* Get DMI information. * Get DMI information.
*/ */
static int ibm_dmi_probe(void) static int __devinit ibm_dmi_probe(void)
{ {
#ifdef CONFIG_X86 #ifdef CONFIG_X86
extern int is_unsafe_smbus; extern int is_unsafe_smbus;
...@@ -129,9 +131,9 @@ static int ibm_dmi_probe(void) ...@@ -129,9 +131,9 @@ static int ibm_dmi_probe(void)
#endif #endif
} }
static int piix4_setup(struct pci_dev *PIIX4_dev, const struct pci_device_id *id) static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
const struct pci_device_id *id)
{ {
int error_return = 0;
unsigned char temp; unsigned char temp;
/* match up the function */ /* match up the function */
...@@ -144,8 +146,7 @@ static int piix4_setup(struct pci_dev *PIIX4_dev, const struct pci_device_id *id ...@@ -144,8 +146,7 @@ static int piix4_setup(struct pci_dev *PIIX4_dev, const struct pci_device_id *id
dev_err(&PIIX4_dev->dev, "IBM Laptop detected; this module " dev_err(&PIIX4_dev->dev, "IBM Laptop detected; this module "
"may corrupt your serial eeprom! Refusing to load " "may corrupt your serial eeprom! Refusing to load "
"module!\n"); "module!\n");
error_return = -EPERM; return -EPERM;
goto END;
} }
/* Determine the address of the SMBus areas */ /* Determine the address of the SMBus areas */
...@@ -163,11 +164,10 @@ static int piix4_setup(struct pci_dev *PIIX4_dev, const struct pci_device_id *id ...@@ -163,11 +164,10 @@ static int piix4_setup(struct pci_dev *PIIX4_dev, const struct pci_device_id *id
} }
} }
if (!request_region(piix4_smba, 8, "piix4-smbus")) { if (!request_region(piix4_smba, SMBIOSIZE, "piix4-smbus")) {
dev_err(&PIIX4_dev->dev, "SMB region 0x%x already in use!\n", dev_err(&PIIX4_dev->dev, "SMB region 0x%x already in use!\n",
piix4_smba); piix4_smba);
error_return = -ENODEV; return -ENODEV;
goto END;
} }
pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp); pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp);
...@@ -214,8 +214,9 @@ static int piix4_setup(struct pci_dev *PIIX4_dev, const struct pci_device_id *id ...@@ -214,8 +214,9 @@ static int piix4_setup(struct pci_dev *PIIX4_dev, const struct pci_device_id *id
} else { } else {
dev_err(&PIIX4_dev->dev, dev_err(&PIIX4_dev->dev,
"Host SMBus controller not enabled!\n"); "Host SMBus controller not enabled!\n");
error_return = -ENODEV; release_region(piix4_smba, SMBIOSIZE);
goto END; piix4_smba = 0;
return -ENODEV;
} }
} }
...@@ -231,8 +232,7 @@ static int piix4_setup(struct pci_dev *PIIX4_dev, const struct pci_device_id *id ...@@ -231,8 +232,7 @@ static int piix4_setup(struct pci_dev *PIIX4_dev, const struct pci_device_id *id
dev_dbg(&PIIX4_dev->dev, "SMBREV = 0x%X\n", temp); dev_dbg(&PIIX4_dev->dev, "SMBREV = 0x%X\n", temp);
dev_dbg(&PIIX4_dev->dev, "SMBA = 0x%X\n", piix4_smba); dev_dbg(&PIIX4_dev->dev, "SMBA = 0x%X\n", piix4_smba);
END: return 0;
return error_return;
} }
/* Another internally used function */ /* Another internally used function */
...@@ -465,7 +465,8 @@ static struct pci_device_id piix4_ids[] = { ...@@ -465,7 +465,8 @@ static struct pci_device_id piix4_ids[] = {
{ 0, } { 0, }
}; };
static int __devinit piix4_probe(struct pci_dev *dev, const struct pci_device_id *id) static int __devinit piix4_probe(struct pci_dev *dev,
const struct pci_device_id *id)
{ {
int retval; int retval;
...@@ -479,17 +480,24 @@ static int __devinit piix4_probe(struct pci_dev *dev, const struct pci_device_id ...@@ -479,17 +480,24 @@ static int __devinit piix4_probe(struct pci_dev *dev, const struct pci_device_id
snprintf(piix4_adapter.name, I2C_NAME_SIZE, snprintf(piix4_adapter.name, I2C_NAME_SIZE,
"SMBus PIIX4 adapter at %04x", piix4_smba); "SMBus PIIX4 adapter at %04x", piix4_smba);
retval = i2c_add_adapter(&piix4_adapter); if ((retval = i2c_add_adapter(&piix4_adapter))) {
dev_err(&dev->dev, "Couldn't register adapter!\n");
release_region(piix4_smba, SMBIOSIZE);
piix4_smba = 0;
}
return retval; return retval;
} }
static void __devexit piix4_remove(struct pci_dev *dev) static void __devexit piix4_remove(struct pci_dev *dev)
{ {
i2c_del_adapter(&piix4_adapter); if (piix4_smba) {
i2c_del_adapter(&piix4_adapter);
release_region(piix4_smba, SMBIOSIZE);
piix4_smba = 0;
}
} }
static struct pci_driver piix4_driver = { static struct pci_driver piix4_driver = {
.name = "piix4-smbus", .name = "piix4-smbus",
.id_table = piix4_ids, .id_table = piix4_ids,
...@@ -502,15 +510,13 @@ static int __init i2c_piix4_init(void) ...@@ -502,15 +510,13 @@ static int __init i2c_piix4_init(void)
return pci_module_init(&piix4_driver); return pci_module_init(&piix4_driver);
} }
static void __exit i2c_piix4_exit(void) static void __exit i2c_piix4_exit(void)
{ {
pci_unregister_driver(&piix4_driver); pci_unregister_driver(&piix4_driver);
release_region(piix4_smba, 8);
} }
MODULE_AUTHOR MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and "
("Frodo Looijaard <frodol@dds.nl> and Philip Edelbrock <phil@netroedge.com>"); "Philip Edelbrock <phil@netroedge.com>");
MODULE_DESCRIPTION("PIIX4 SMBus driver"); MODULE_DESCRIPTION("PIIX4 SMBus driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment