Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1615686

[PATCH 1/2] platform/x86: silead_dmi - do not treat all devices as i2c_clients

From Dmitry Torokhov <dmitry.torokhov@gmail.com>
Newsgroups linux.kernel
Subject [PATCH 1/2] platform/x86: silead_dmi - do not treat all devices as i2c_clients
Date 2017-04-04 05:30 +0200
Message-ID <tsnkm-7ED-5@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


I2C bus has both i2c clients and adapter devices, so we must be careful in
notifier code and verify that we are actually dealing with an i2c client
before using it as such.

Fixes: cef9dd85acd7 ("platform/x86: add support for devices with Silead...")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/platform/x86/silead_dmi.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/platform/x86/silead_dmi.c b/drivers/platform/x86/silead_dmi.c
index 02e11fdbf375..7f1049951d1c 100644
--- a/drivers/platform/x86/silead_dmi.c
+++ b/drivers/platform/x86/silead_dmi.c
@@ -75,9 +75,8 @@ static const struct dmi_system_id silead_ts_dmi_table[] = {
 	{ },
 };
 
-static void silead_ts_dmi_add_props(struct device *dev)
+static void silead_ts_dmi_add_props(struct i2c_client *client)
 {
-	struct i2c_client *client = to_i2c_client(dev);
 	const struct dmi_system_id *dmi_id;
 	const struct silead_ts_dmi_data *ts_data;
 	int error;
@@ -87,11 +86,13 @@ static void silead_ts_dmi_add_props(struct device *dev)
 		return;
 
 	ts_data = dmi_id->driver_data;
-	if (has_acpi_companion(dev) &&
+	if (has_acpi_companion(&client->dev) &&
 	    !strncmp(ts_data->acpi_name, client->name, I2C_NAME_SIZE)) {
-		error = device_add_properties(dev, ts_data->properties);
+		error = device_add_properties(&client->dev,
+					      ts_data->properties);
 		if (error)
-			dev_err(dev, "failed to add properties: %d\n", error);
+			dev_err(&client->dev,
+				"failed to add properties: %d\n", error);
 	}
 }
 
@@ -99,10 +100,13 @@ static int silead_ts_dmi_notifier_call(struct notifier_block *nb,
 				       unsigned long action, void *data)
 {
 	struct device *dev = data;
+	struct i2c_client *client;
 
 	switch (action) {
 	case BUS_NOTIFY_ADD_DEVICE:
-		silead_ts_dmi_add_props(dev);
+		client = i2c_verify_client(dev);
+		if (client)
+			silead_ts_dmi_add_props(client);
 		break;
 
 	default:
-- 
2.12.2.715.g7642488e1d-goog

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH 1/2] platform/x86: silead_dmi - do not treat all devices as i2c_clients Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-04-04 05:30 +0200
  Re: [PATCH 1/2] platform/x86: silead_dmi - do not treat all devices  as i2c_clients Hans de Goede <hdegoede@redhat.com> - 2017-04-04 12:00 +0200
  Re: [PATCH 1/2] platform/x86: silead_dmi - do not treat all devices  as i2c_clients Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-04-04 15:50 +0200
    Re: [PATCH 1/2] platform/x86: silead_dmi - do not treat all devices  as i2c_clients Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-04-04 18:10 +0200
      Re: [PATCH 1/2] platform/x86: silead_dmi - do not treat all devices  as i2c_clients Darren Hart <dvhart@infradead.org> - 2017-04-04 18:40 +0200
        Re: [PATCH 1/2] platform/x86: silead_dmi - do not treat all devices  as i2c_clients Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-04-04 18:40 +0200
          Re: [PATCH 1/2] platform/x86: silead_dmi - do not treat all devices  as i2c_clients Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-04-04 19:20 +0200
    Re: [PATCH 1/2] platform/x86: silead_dmi - do not treat all devices  as i2c_clients Darren Hart <dvhart@infradead.org> - 2017-04-04 18:10 +0200

csiph-web