Commit 0f07a24b authored by Jean Delvare's avatar Jean Delvare Committed by Jean Delvare

i2c: Let the user specify PCI driver data through new_id

The i2c-amd756 and i2c-viapro drivers make use of the driver_data
field of the PCI device ID. When adding device IDs dynamically (by
writing to the new_id sysfs file) you cannot set the value of this
field by default. It has to be allowed explicitly. Do that, and
check the value so that the user can't crash the kernel accidentally.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent b7a36701
...@@ -334,6 +334,10 @@ static int __devinit amd756_probe(struct pci_dev *pdev, ...@@ -334,6 +334,10 @@ static int __devinit amd756_probe(struct pci_dev *pdev,
int error; int error;
u8 temp; u8 temp;
/* driver_data might come from user-space, so check it */
if (id->driver_data > ARRAY_SIZE(chipname))
return -EINVAL;
if (amd756_ioport) { if (amd756_ioport) {
dev_err(&pdev->dev, "Only one device supported " dev_err(&pdev->dev, "Only one device supported "
"(you have a strange motherboard, btw)\n"); "(you have a strange motherboard, btw)\n");
...@@ -405,6 +409,7 @@ static struct pci_driver amd756_driver = { ...@@ -405,6 +409,7 @@ static struct pci_driver amd756_driver = {
.id_table = amd756_ids, .id_table = amd756_ids,
.probe = amd756_probe, .probe = amd756_probe,
.remove = __devexit_p(amd756_remove), .remove = __devexit_p(amd756_remove),
.dynids.use_driver_data = 1,
}; };
static int __init amd756_init(void) static int __init amd756_init(void)
......
...@@ -318,6 +318,10 @@ static int __devinit vt596_probe(struct pci_dev *pdev, ...@@ -318,6 +318,10 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
unsigned char temp; unsigned char temp;
int error = -ENODEV; int error = -ENODEV;
/* driver_data might come from user-space, so check it */
if (id->driver_data & 1 || id->driver_data > 0xff)
return -EINVAL;
/* Determine the address of the SMBus areas */ /* Determine the address of the SMBus areas */
if (force_addr) { if (force_addr) {
vt596_smba = force_addr & 0xfff0; vt596_smba = force_addr & 0xfff0;
...@@ -455,6 +459,7 @@ static struct pci_driver vt596_driver = { ...@@ -455,6 +459,7 @@ static struct pci_driver vt596_driver = {
.name = "vt596_smbus", .name = "vt596_smbus",
.id_table = vt596_ids, .id_table = vt596_ids,
.probe = vt596_probe, .probe = vt596_probe,
.dynids.use_driver_data = 1,
}; };
static int __init i2c_vt596_init(void) static int __init i2c_vt596_init(void)
......
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