Commit 6f6b35e133fe4313277b30fc1a7ea313875ea6c9

Authored by Jean Delvare
1 parent 18669eabde

macintosh: Don't assume i2c device probing always succeeds

If i2c device probing fails, then there is no driver to dereference
after calling i2c_new_device(). Stop assuming that probing will always
succeed, to avoid NULL pointer dereferences. We have an easier access
to the driver anyway.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Tested-by: Tim Shepard <shep@alum.mit.edu>
Cc: Colin Leroy <colin@colino.net>

Showing 5 changed files with 15 additions and 5 deletions Side-by-side Diff

drivers/macintosh/therm_adt746x.c
... ... @@ -124,6 +124,8 @@
124 124 return data;
125 125 }
126 126  
  127 +static struct i2c_driver thermostat_driver;
  128 +
127 129 static int
128 130 attach_thermostat(struct i2c_adapter *adapter)
129 131 {
... ... @@ -148,7 +150,7 @@
148 150 * Let i2c-core delete that device on driver removal.
149 151 * This is safe because i2c-core holds the core_lock mutex for us.
150 152 */
151   - list_add_tail(&client->detected, &client->driver->clients);
  153 + list_add_tail(&client->detected, &thermostat_driver.clients);
152 154 return 0;
153 155 }
154 156  
drivers/macintosh/therm_pm72.c
... ... @@ -286,6 +286,8 @@
286 286 },
287 287 };
288 288  
  289 +static struct i2c_driver therm_pm72_driver;
  290 +
289 291 /*
290 292 * Utility function to create an i2c_client structure and
291 293 * attach it to one of u3 adapters
... ... @@ -318,7 +320,7 @@
318 320 * Let i2c-core delete that device on driver removal.
319 321 * This is safe because i2c-core holds the core_lock mutex for us.
320 322 */
321   - list_add_tail(&clt->detected, &clt->driver->clients);
  323 + list_add_tail(&clt->detected, &therm_pm72_driver.clients);
322 324 return clt;
323 325 }
324 326  
drivers/macintosh/windfarm_lm75_sensor.c
... ... @@ -115,6 +115,8 @@
115 115 return rc;
116 116 }
117 117  
  118 +static struct i2c_driver wf_lm75_driver;
  119 +
118 120 static struct i2c_client *wf_lm75_create(struct i2c_adapter *adapter,
119 121 u8 addr, int ds1775,
120 122 const char *loc)
... ... @@ -157,7 +159,7 @@
157 159 * Let i2c-core delete that device on driver removal.
158 160 * This is safe because i2c-core holds the core_lock mutex for us.
159 161 */
160   - list_add_tail(&client->detected, &client->driver->clients);
  162 + list_add_tail(&client->detected, &wf_lm75_driver.clients);
161 163 return client;
162 164 fail:
163 165 return NULL;
drivers/macintosh/windfarm_max6690_sensor.c
... ... @@ -88,6 +88,8 @@
88 88 return rc;
89 89 }
90 90  
  91 +static struct i2c_driver wf_max6690_driver;
  92 +
91 93 static struct i2c_client *wf_max6690_create(struct i2c_adapter *adapter,
92 94 u8 addr, const char *loc)
93 95 {
... ... @@ -119,7 +121,7 @@
119 121 * Let i2c-core delete that device on driver removal.
120 122 * This is safe because i2c-core holds the core_lock mutex for us.
121 123 */
122   - list_add_tail(&client->detected, &client->driver->clients);
  124 + list_add_tail(&client->detected, &wf_max6690_driver.clients);
123 125 return client;
124 126  
125 127 fail:
drivers/macintosh/windfarm_smu_sat.c
... ... @@ -194,6 +194,8 @@
194 194 .owner = THIS_MODULE,
195 195 };
196 196  
  197 +static struct i2c_driver wf_sat_driver;
  198 +
197 199 static void wf_sat_create(struct i2c_adapter *adapter, struct device_node *dev)
198 200 {
199 201 struct i2c_board_info info;
... ... @@ -222,7 +224,7 @@
222 224 * Let i2c-core delete that device on driver removal.
223 225 * This is safe because i2c-core holds the core_lock mutex for us.
224 226 */
225   - list_add_tail(&client->detected, &client->driver->clients);
  227 + list_add_tail(&client->detected, &wf_sat_driver.clients);
226 228 }
227 229  
228 230 static int wf_sat_probe(struct i2c_client *client,