static int pcf8591_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct pcf8591_data *data; int err; data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL); if (!data) { err = -ENOMEM; goto exit; } i2c_set_clientdata(client, data); mutex_init(&data->update_lock); pcf8591_init_client(client); err = sysfs_create_group(&client->dev.kobj, &pcf8591_attr_group); if (err) goto exit_kfree; if (input_mode != 3) { err = device_create_file(&client->dev, &dev_attr_in2_input); if (err) goto exit_sysfs_remove; } if (input_mode == 0) { err = device_create_file(&client->dev, &dev_attr_in3_input); if (err) goto exit_sysfs_remove; } data->hwmon_dev = hwmon_device_register(&client->dev); if (IS_ERR(data->hwmon_dev)) { err = PTR_ERR(data->hwmon_dev); goto exit_sysfs_remove; } return 0; exit_sysfs_remove: sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); exit_kfree: kfree(data); exit: return err; }
static int pcf8591_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct pcf8591_data *data; int err; if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) { err = -ENOMEM; goto exit; } i2c_set_clientdata(client, data); mutex_init(&data->update_lock); /* Initialize the PCF8591 chip */ pcf8591_init_client(client); /* Register sysfs hooks */ err = sysfs_create_group(&client->dev.kobj, &pcf8591_attr_group); if (err) goto exit_kfree; /* Register input2 if not in "two differential inputs" mode */ if (input_mode != 3) { if ((err = device_create_file(&client->dev, &dev_attr_in2_input))) goto exit_sysfs_remove; } /* Register input3 only in "four single ended inputs" mode */ if (input_mode == 0) { if ((err = device_create_file(&client->dev, &dev_attr_in3_input))) goto exit_sysfs_remove; } data->hwmon_dev = hwmon_device_register(&client->dev); if (IS_ERR(data->hwmon_dev)) { err = PTR_ERR(data->hwmon_dev); goto exit_sysfs_remove; } return 0; exit_sysfs_remove: sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); exit_kfree: kfree(data); exit: return err; }