aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/chips/pcf8574.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/pcf8574.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/pcf8574.c')
-rw-r--r--drivers/i2c/chips/pcf8574.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c
index c3e6449c4481..32b25427eaba 100644
--- a/drivers/i2c/chips/pcf8574.c
+++ b/drivers/i2c/chips/pcf8574.c
@@ -105,6 +105,16 @@ static ssize_t set_write(struct device *dev, struct device_attribute *attr, cons
105 105
106static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write); 106static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write);
107 107
108static struct attribute *pcf8574_attributes[] = {
109 &dev_attr_read.attr,
110 &dev_attr_write.attr,
111 NULL
112};
113
114static const struct attribute_group pcf8574_attr_group = {
115 .attrs = pcf8574_attributes,
116};
117
108/* 118/*
109 * Real code 119 * Real code
110 */ 120 */
@@ -166,13 +176,13 @@ static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
166 pcf8574_init_client(new_client); 176 pcf8574_init_client(new_client);
167 177
168 /* Register sysfs hooks */ 178 /* Register sysfs hooks */
169 device_create_file(&new_client->dev, &dev_attr_read); 179 err = sysfs_create_group(&new_client->dev.kobj, &pcf8574_attr_group);
170 device_create_file(&new_client->dev, &dev_attr_write); 180 if (err)
181 goto exit_detach;
171 return 0; 182 return 0;
172 183
173/* OK, this is not exactly good programming practice, usually. But it is 184 exit_detach:
174 very code-efficient in this case. */ 185 i2c_detach_client(new_client);
175
176 exit_free: 186 exit_free:
177 kfree(data); 187 kfree(data);
178 exit: 188 exit:
@@ -183,6 +193,8 @@ static int pcf8574_detach_client(struct i2c_client *client)
183{ 193{
184 int err; 194 int err;
185 195
196 sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group);
197
186 if ((err = i2c_detach_client(client))) 198 if ((err = i2c_detach_client(client)))
187 return err; 199 return err;
188 200