Skip to content

Commit

Permalink
i2c: acpi: Fix NULL Pointer dereference
Browse files Browse the repository at this point in the history
If adapter->dev.parent == NULL there is a NULL pointer dereference in
acpi_i2c_install_space_handler and acpi_i2c_remove_space_handler.

This is present since introduction of this code:
3660475 "i2c: rework kernel config I2C_ACPI" or even
da3c664 "I2C/ACPI: Clean up I2C ACPI code and Add CONFIG_I2C_ACPI"

The adapter->dev.parent == NULL case is valid for the i2c_stub,
so loading i2c_stub with ACPI_I2C_OPREGION enabled results in an oops.
This is also valid at least for i2c_tiny_usb and i2c_robotfuzz_osif.

Fix by checking whether it is null before calling ACPI_HANDLE.

Signed-off-by: Peter Huewe <[email protected]>
Acked-by: Mika Westerberg <[email protected]>
Signed-off-by: Wolfram Sang <[email protected]>
  • Loading branch information
PeterHuewe authored and Wolfram Sang committed Sep 25, 2014
1 parent 17f4a5c commit 0aef44e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions drivers/i2c/i2c-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,15 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command,

static int acpi_i2c_install_space_handler(struct i2c_adapter *adapter)
{
acpi_handle handle = ACPI_HANDLE(adapter->dev.parent);
acpi_handle handle;
struct acpi_i2c_handler_data *data;
acpi_status status;

if (!adapter->dev.parent)
return -ENODEV;

handle = ACPI_HANDLE(adapter->dev.parent);

if (!handle)
return -ENODEV;

Expand Down Expand Up @@ -407,10 +412,15 @@ static int acpi_i2c_install_space_handler(struct i2c_adapter *adapter)

static void acpi_i2c_remove_space_handler(struct i2c_adapter *adapter)
{
acpi_handle handle = ACPI_HANDLE(adapter->dev.parent);
acpi_handle handle;
struct acpi_i2c_handler_data *data;
acpi_status status;

if (!adapter->dev.parent)
return;

handle = ACPI_HANDLE(adapter->dev.parent);

if (!handle)
return;

Expand Down

0 comments on commit 0aef44e

Please sign in to comment.