aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/chips/max6875.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2006-09-03 16:20:24 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2006-09-26 18:38:51 -0400
commit7d9db67febf67dd76329a9dd8f97cf4611a8ac2e (patch)
tree6354fa99b17f89c8f26ccf7c440d0d29096f2dc2 /drivers/i2c/chips/max6875.c
parentb32d20dc8b187e03605f091dbde9a78676a2a642 (diff)
i2c: __must_check fixes (chip drivers)
i2c: __must_check fixes (chip drivers) Check for error on sysfs file creation. Delete sysfs files on device removal. The approach taken for the most complex case (pcf8591) is similar to what Mark M. Hoffman proposed for hardware monitoring chip drivers. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Ben Gardner <bgardner@wabtec.com> Cc: Aurelien Jarno <aurelien@aurel32.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/i2c/chips/max6875.c')
-rw-r--r--drivers/i2c/chips/max6875.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index 88d2ddee4490..76645c142977 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -199,8 +199,7 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
199 mutex_init(&data->update_lock); 199 mutex_init(&data->update_lock);
200 200
201 /* Init fake client data */ 201 /* Init fake client data */
202 /* set the client data to the i2c_client so that it will get freed */ 202 i2c_set_clientdata(fake_client, NULL);
203 i2c_set_clientdata(fake_client, fake_client);
204 fake_client->addr = address | 1; 203 fake_client->addr = address | 1;
205 fake_client->adapter = adapter; 204 fake_client->adapter = adapter;
206 fake_client->driver = &max6875_driver; 205 fake_client->driver = &max6875_driver;
@@ -214,13 +213,17 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
214 goto exit_kfree2; 213 goto exit_kfree2;
215 214
216 if ((err = i2c_attach_client(fake_client)) != 0) 215 if ((err = i2c_attach_client(fake_client)) != 0)
217 goto exit_detach; 216 goto exit_detach1;
218 217
219 sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr); 218 err = sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr);
219 if (err)
220 goto exit_detach2;
220 221
221 return 0; 222 return 0;
222 223
223exit_detach: 224exit_detach2:
225 i2c_detach_client(fake_client);
226exit_detach1:
224 i2c_detach_client(real_client); 227 i2c_detach_client(real_client);
225exit_kfree2: 228exit_kfree2:
226 kfree(fake_client); 229 kfree(fake_client);
@@ -229,14 +232,24 @@ exit_kfree1:
229 return err; 232 return err;
230} 233}
231 234
235/* Will be called for both the real client and the fake client */
232static int max6875_detach_client(struct i2c_client *client) 236static int max6875_detach_client(struct i2c_client *client)
233{ 237{
234 int err; 238 int err;
239 struct max6875_data *data = i2c_get_clientdata(client);
240
241 /* data is NULL for the fake client */
242 if (data)
243 sysfs_remove_bin_file(&client->dev.kobj, &user_eeprom_attr);
235 244
236 err = i2c_detach_client(client); 245 err = i2c_detach_client(client);
237 if (err) 246 if (err)
238 return err; 247 return err;
239 kfree(i2c_get_clientdata(client)); 248
249 if (data) /* real client */
250 kfree(data);
251 else /* fake client */
252 kfree(client);
240 return 0; 253 return 0;
241} 254}
242 255