linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [REGRESSION] i2c-acpi: Fix NULL Pointer dereference
@ 2014-09-12 19:09 Peter Huewe
  2014-09-12 19:12 ` Peter Hüwe
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Peter Huewe @ 2014-09-12 19:09 UTC (permalink / raw)
  To: Mika Westerberg
  Cc: Wolfram Sang, linux-i2c, linux-acpi, linux-kernel, Peter Huewe

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:
366047515c6e "i2c: rework kernel config I2C_ACPI" or even
da3c6647ee08 "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 <peterhuewe@gmx.de>
---
 drivers/i2c/i2c-acpi.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c-acpi.c b/drivers/i2c/i2c-acpi.c
index 0dbc18c..c456b17 100644
--- a/drivers/i2c/i2c-acpi.c
+++ b/drivers/i2c/i2c-acpi.c
@@ -308,10 +308,15 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command,
 
 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;
 
@@ -344,10 +349,15 @@ int acpi_i2c_install_space_handler(struct i2c_adapter *adapter)
 
 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;
 
-- 
1.8.5.5


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-09-24 21:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-12 19:09 [PATCH] [REGRESSION] i2c-acpi: Fix NULL Pointer dereference Peter Huewe
2014-09-12 19:12 ` Peter Hüwe
2014-09-13  6:34 ` Mika Westerberg
2014-09-24 21:06 ` Rafael J. Wysocki
2014-09-24 21:02   ` Wolfram Sang
2014-09-24 21:24     ` Rafael J. Wysocki
     [not found]       ` <2180819.4Kky9hrQa3-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2014-09-24 21:19         ` Wolfram Sang
     [not found] ` <1410548987-3558-1-git-send-email-peterhuewe-Mmb7MZpHnFY@public.gmane.org>
2014-09-24 21:27   ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).