Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
[safe/jmp/linux-2.6] / drivers / i2c / chips / pcf8574.c
index 6525743..32b2542 100644 (file)
@@ -65,10 +65,10 @@ static void pcf8574_init_client(struct i2c_client *client);
 
 /* This is the driver that will be inserted */
 static struct i2c_driver pcf8574_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "pcf8574",
+       .driver = {
+               .name   = "pcf8574",
+       },
        .id             = I2C_DRIVERID_PCF8574,
-       .flags          = I2C_DF_NOTIFY,
        .attach_adapter = pcf8574_attach_adapter,
        .detach_client  = pcf8574_detach_client,
 };
@@ -105,6 +105,16 @@ static ssize_t set_write(struct device *dev, struct device_attribute *attr, cons
 
 static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write);
 
+static struct attribute *pcf8574_attributes[] = {
+       &dev_attr_read.attr,
+       &dev_attr_write.attr,
+       NULL
+};
+
+static const struct attribute_group pcf8574_attr_group = {
+       .attrs = pcf8574_attributes,
+};
+
 /*
  * Real code
  */
@@ -115,7 +125,7 @@ static int pcf8574_attach_adapter(struct i2c_adapter *adapter)
 }
 
 /* This function is called by i2c_probe */
-int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
+static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
 {
        struct i2c_client *new_client;
        struct pcf8574_data *data;
@@ -127,11 +137,10 @@ int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
 
        /* OK. For now, we presume we have a valid client. We now create the
           client structure, even though we cannot fill it completely yet. */
-       if (!(data = kmalloc(sizeof(struct pcf8574_data), GFP_KERNEL))) {
+       if (!(data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL))) {
                err = -ENOMEM;
                goto exit;
        }
-       memset(data, 0, sizeof(struct pcf8574_data));
 
        new_client = &data->client;
        i2c_set_clientdata(new_client, data);
@@ -167,13 +176,13 @@ int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
        pcf8574_init_client(new_client);
 
        /* Register sysfs hooks */
-       device_create_file(&new_client->dev, &dev_attr_read);
-       device_create_file(&new_client->dev, &dev_attr_write);
+       err = sysfs_create_group(&new_client->dev.kobj, &pcf8574_attr_group);
+       if (err)
+               goto exit_detach;
        return 0;
 
-/* OK, this is not exactly good programming practice, usually. But it is
-   very code-efficient in this case. */
-
+      exit_detach:
+       i2c_detach_client(new_client);
       exit_free:
        kfree(data);
       exit:
@@ -184,6 +193,8 @@ static int pcf8574_detach_client(struct i2c_client *client)
 {
        int err;
 
+       sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group);
+
        if ((err = i2c_detach_client(client)))
                return err;