static int ds620_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device *dev = &client->dev; struct device *hwmon_dev; struct ds620_data *data; data = devm_kzalloc(dev, sizeof(struct ds620_data), GFP_KERNEL); if (!data) return -ENOMEM; data->client = client; mutex_init(&data->update_lock); /* Initialize the DS620 chip */ ds620_init_client(client); hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, data, ds620_groups); return PTR_ERR_OR_ZERO(hwmon_dev); }
static int ds620_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct ds620_data *data; int err; data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL); if (!data) { err = -ENOMEM; goto exit; } i2c_set_clientdata(client, data); mutex_init(&data->update_lock); /* Initialize the DS620 chip */ ds620_init_client(client); /* Register sysfs hooks */ err = sysfs_create_group(&client->dev.kobj, &ds620_group); if (err) goto exit_free; data->hwmon_dev = hwmon_device_register(&client->dev); if (IS_ERR(data->hwmon_dev)) { err = PTR_ERR(data->hwmon_dev); goto exit_remove_files; } dev_info(&client->dev, "temperature sensor found\n"); return 0; exit_remove_files: sysfs_remove_group(&client->dev.kobj, &ds620_group); exit_free: kfree(data); exit: return err; }