i2c: core: Protect acpi_match_device() against NULL
Subsystems (4)
PATCH 1/1 i2c: core: Protect acpi_match_device() against NULL
The commit 09b3b246acba
("i2c: core: Allow empty id_table in ACPI case as well")
brought an additional check for ACPI match table entry, though missed NULL check for table itself.
Do it here by introducing a helper i2c_acpi_match_device().
Note, we rename some static function in i2c-core-acpi.c to distinguish with public API.
--- drivers/i2c/i2c-core-acpi.c | 19 +++++++++++++++---- drivers/i2c/i2c-core-base.c | 2 +- drivers/i2c/i2c-core.h | 9 +++++++++ 3 files changed, 25 insertions(+), 5 deletions(-)
drivers/i2c/i2c-core-acpi.c +15 -4
@@ -230,6 +230,16 @@ void i2c_acpi_register_devices(struct i2c_adapter *adap)dev_warn (&adap->dev,"failed to enumerate I2C slaves\n" ); } +const struct acpi_device_id * +i2c_acpi_match_device (const struct acpi_device_id *matches, +struct i2c_client *client) +{ +if (!(client && matches)) +return NULL ; + +return acpi_match_device (matches, &client->dev); +} +static acpi_status i2c_acpi_lookup_speed (acpi_handle handle,u32 level,void *data,void **return_value) {
@@ -289,7 +299,7 @@ u32 i2c_acpi_find_bus_speed(struct device *dev) }EXPORT_SYMBOL_GPL (i2c_acpi_find_bus_speed); -static int i2c_acpi_match_adapter (struct device *dev,void *data) +static int i2c_acpi_find_match_adapter (struct device *dev,void *data) {struct i2c_adapter *adapter =i2c_verify_adapter (dev);
@@ -299,7 +309,7 @@ static int i2c_acpi_match_adapter(struct device *dev, void *data)return ACPI_HANDLE (dev) == (acpi_handle )data; } -static int i2c_acpi_match_device (struct device *dev,void *data) +static int i2c_acpi_find_match_device (struct device *dev,void *data) {return ACPI_COMPANION (dev) == data; }
@@ -309,7 +319,7 @@ static struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)struct device *dev; dev =bus_find_device (&i2c_bus_type,NULL , handle, - i2c_acpi_match_adapter); + i2c_acpi_find_match_adapter);return dev ?i2c_verify_adapter (dev) :NULL ; }
@@ -317,7 +327,8 @@ static struct i2c_client *i2c_acpi_find_client_by_adev(struct acpi_device *adev) {struct device *dev; - dev =bus_find_device (&i2c_bus_type,NULL , adev, i2c_acpi_match_device); + dev =bus_find_device (&i2c_bus_type,NULL , adev, + i2c_acpi_find_match_device);return dev ?i2c_verify_client (dev) :NULL ; }
drivers/i2c/i2c-core-base.c +1 -1
@@ -357,7 +357,7 @@ static int i2c_device_probe(struct device *dev)* Tree or ACPI match table entry is supplied for the probing device. */ if (!driver->id_table && - !acpi_match_device (dev->driver->acpi_match_table, &client->dev) && + !i2c_acpi_match_device (dev->driver->acpi_match_table, client) && !i2c_of_match_device (dev->driver->of_match_table, client))return -ENODEV ;
drivers/i2c/i2c-core.h +9 -0
@@ -31,9 +31,18 @@ int i2c_check_addr_validity(unsigned addr, unsigned short flags);int i2c_check_7bit_addr_validity_strict (unsigned short addr);#ifdef CONFIG_ACPI +const struct acpi_device_id * +i2c_acpi_match_device (const struct acpi_device_id *matches, +struct i2c_client *client);void i2c_acpi_register_devices (struct i2c_adapter *adap);#else /* CONFIG_ACPI */ static inline void i2c_acpi_register_devices (struct i2c_adapter *adap) { } +static inline const struct acpi_device_id * +i2c_acpi_match_device (const struct acpi_device_id *matches, +struct i2c_client *client) +{ +return NULL ; +}#endif /* CONFIG_ACPI */ extern struct notifier_block i2c_acpi_notifier;
Signature · 1 line
2.11.0
Quoted 10 lines · Andy Shevchenko
The commit
09b3b246acba
("i2c: core: Allow emptyid_tablein ACPI case as well")
brought an additional check for ACPI match table entry, though missed NULL check for table itself.Do it here by introducing a helper
i2c_acpi_match_device().Note, we rename some static function in
i2c-core-acpi.cto distinguish with public API.
Wolfram, feel free to squash it into the original commit if it looks better.
Quoted 118 lines
Fixes 09b3b246acba ("i2c: core: Allow empty id_table in ACPI case aswell")
Signed-off-by Andy Shevchenko <[email protected]>---
drivers/i2c/i2c-core-acpi.c | 19 +++++++++++++++----drivers/i2c/i2c-core-base.c| 2 +- drivers/i2c/i2c-core.h | 9 +++++++++3 files changed, 25 insertions(+), 5 deletions(-)drivers/i2c/i2c-core-acpi.c +0
-0@@ -230,6 +230,16 @@ void i2c_acpi_register_devices(struct i2c_adapter *adap)
dev_warn(&adap->dev, "failed to enumerate I2C slaves\n");
}drivers/i2c/i2c-core-acpi.c +10
-0+const struct acpi_device_id * +i2c_acpi_match_device (const struct acpi_device_id *matches, + struct i2c_client *client) +{ +if (!(client && matches)) +return NULL ; + +return acpi_match_device (matches, &client->dev); +} +static
acpi_statusi2c_acpi_lookup_speed(acpi_handle handle, u32 level,
void *data, void **return_value)
{drivers/i2c/i2c-core-acpi.c +0
-0@@ -289,7 +299,7 @@ u32 i2c_acpi_find_bus_speed(struct device *dev) } EXPORT_SYMBOL_GPL(i2c_acpi_find_bus_speed);drivers/i2c/i2c-core-acpi.c +1
-1-static int i2c_acpi_match_adapter (struct device *dev,void *data) +static int i2c_acpi_find_match_adapter(struct device *dev, void*data)
{
structi2c_adapter*adapter =i2c_verify_adapter(dev);drivers/i2c/i2c-core-acpi.c +0
-0@@ -299,7 +309,7 @@ static int i2c_acpi_match_adapter(struct device *dev, void *data) return ACPI_HANDLE(dev) == (acpi_handle)data; }drivers/i2c/i2c-core-acpi.c +1
-1-static int i2c_acpi_match_device (struct device *dev,void *data) +static int i2c_acpi_find_match_device (struct device *dev,void *data){
returnACPI_COMPANION(dev)== data;
}drivers/i2c/i2c-core-acpi.c +0
-0@@ -309,7 +319,7 @@ static struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle) struct device *dev;
dev = bus_find_device(&i2c_bus_type, NULL, handle,drivers/i2c/i2c-core-acpi.c +1
-1- i2c_acpi_match_adapter); + i2c_acpi_find_match_adapter);return dev ?
i2c_verify_adapter(dev): NULL; }drivers/i2c/i2c-core-acpi.c +0
-0@@ -317,7 +327,8 @@ static struct i2c_client *i2c_acpi_find_client_by_adev(struct acpi_device *adev) { struct device *dev;drivers/i2c/i2c-core-acpi.c +0
-1- dev = bus_find_device(&i2c_bus_type, NULL, adev,
i2c_acpi_match_device);drivers/i2c/i2c-core-acpi.c +2
-0+ dev =bus_find_device (&i2c_bus_type,NULL , adev, + i2c_acpi_find_match_device);return dev ?
i2c_verify_client(dev): NULL; }drivers/i2c/i2c-core-base.c +0
-0@@ -357,7 +357,7 @@ static int i2c_device_probe(struct device *dev) * Tree or ACPI match table entry is supplied for the probingdevice.
*/
if (!driver->id_table &&drivers/i2c/i2c-core-base.c +0
-1- !acpi_match_device(dev->driver->acpi_match_table,
&client->dev) &&drivers/i2c/i2c-core-base.c +1
-0+ !i2c_acpi_match_device(dev->driver->acpi_match_table,client) && !i2c_of_match_device(dev->driver->of_match_table, client))
return-ENODEV;drivers/i2c/i2c-core.h +0
-0@@ -31,9 +31,18 @@ int i2c_check_addr_validity(unsigned addr, unsigned short flags); int i2c_check_7bit_addr_validity_strict(unsigned short addr);
#ifdefCONFIG_ACPIdrivers/i2c/i2c-core.h +3
-0+const struct acpi_device_id * +i2c_acpi_match_device (const struct acpi_device_id *matches, + struct i2c_client *client);void
i2c_acpi_register_devices(struct i2c_adapter *adap); #else /*CONFIG_ACPI*/
static inline voidi2c_acpi_register_devices(struct i2c_adapter *adap){ }drivers/i2c/i2c-core.h +6
-0+static inline const struct acpi_device_id * +i2c_acpi_match_device (const struct acpi_device_id *matches, + struct i2c_client *client) +{ +return NULL ; +}#endif /*
CONFIG_ACPI*/
extern structnotifier_blocki2c_acpi_notifier;
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
The commit
09b3b246acba
("i2c: core: Allow emptyid_tablein ACPI case as well")
brought an additional check for ACPI match table entry, though missed NULL check for table itself.
Quoted 8 lines
Quoted 5 lines
Do it here by introducing a helper
i2c_acpi_match_device().Note, we rename some static function in
i2c-core-acpi.cto distinguish with public API.Wolfram, feel free to squash it into the original commit if it looks better.
I didn't want to send Linus a branch which too many last minute fixes. That's why I dropped the original patch and would like to ask you to resend a combined patch after rc1. If it is a bugfix, we will have no problems getting it into v4.13 but it seems a bit more testing is needed.
Quoted 15 lines · Wolfram Sang
Quoted 14 lines · Andy Shevchenko
Quoted 12 lines · Andy Shevchenko
The commit
09b3b246acba
("i2c: core: Allow emptyid_tablein ACPI case as well")
brought an additional check for ACPI match table entry, though missed
NULL check for table itself.Do it here by introducing a helper
i2c_acpi_match_device().Note, we rename some static function in
i2c-core-acpi.cto distinguish
with public API.
Quoted 8 lines
Quoted 2 lines
Wolfram, feel free to squash it into the original commit if it looks better.
I didn't want to send Linus a branch which too many last minute fixes. That's why I dropped the original patch and would like to ask you to resend a combined patch after rc1. If it is a bugfix, we will have no problems getting it into v4.13 but it seems a bit more testing is needed.
Okay, let's do this way.
I may also try to convert existing users (some coccinelle script I suppose).
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy