Commit fbd9af16 authored by Guenter Roeck's avatar Guenter Roeck

hwmon: (tmp102) Introduce dev variable in probe function

The pointer to client->dev is used several times in the probe function.
Simplify code by introducing a separate variable for it.
Reviewed-by: default avatarJean Delvare <jdelvare@suse.de>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent aa9bcdda
...@@ -162,17 +162,18 @@ static const struct attribute_group tmp102_attr_group = { ...@@ -162,17 +162,18 @@ static const struct attribute_group tmp102_attr_group = {
static int tmp102_probe(struct i2c_client *client, static int tmp102_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct device *dev = &client->dev;
struct tmp102 *tmp102; struct tmp102 *tmp102;
int status; int status;
if (!i2c_check_functionality(client->adapter, if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_WORD_DATA)) { I2C_FUNC_SMBUS_WORD_DATA)) {
dev_err(&client->dev, dev_err(dev,
"adapter doesn't support SMBus word transactions\n"); "adapter doesn't support SMBus word transactions\n");
return -ENODEV; return -ENODEV;
} }
tmp102 = devm_kzalloc(&client->dev, sizeof(*tmp102), GFP_KERNEL); tmp102 = devm_kzalloc(dev, sizeof(*tmp102), GFP_KERNEL);
if (!tmp102) if (!tmp102)
return -ENOMEM; return -ENOMEM;
...@@ -180,54 +181,53 @@ static int tmp102_probe(struct i2c_client *client, ...@@ -180,54 +181,53 @@ static int tmp102_probe(struct i2c_client *client,
status = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG); status = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG);
if (status < 0) { if (status < 0) {
dev_err(&client->dev, "error reading config register\n"); dev_err(dev, "error reading config register\n");
return status; return status;
} }
tmp102->config_orig = status; tmp102->config_orig = status;
status = i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, status = i2c_smbus_write_word_swapped(client, TMP102_CONF_REG,
TMP102_CONFIG); TMP102_CONFIG);
if (status < 0) { if (status < 0) {
dev_err(&client->dev, "error writing config register\n"); dev_err(dev, "error writing config register\n");
goto fail_restore_config; goto fail_restore_config;
} }
status = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG); status = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG);
if (status < 0) { if (status < 0) {
dev_err(&client->dev, "error reading config register\n"); dev_err(dev, "error reading config register\n");
goto fail_restore_config; goto fail_restore_config;
} }
status &= ~TMP102_CONFIG_RD_ONLY; status &= ~TMP102_CONFIG_RD_ONLY;
if (status != TMP102_CONFIG) { if (status != TMP102_CONFIG) {
dev_err(&client->dev, "config settings did not stick\n"); dev_err(dev, "config settings did not stick\n");
status = -ENODEV; status = -ENODEV;
goto fail_restore_config; goto fail_restore_config;
} }
tmp102->last_update = jiffies - HZ; tmp102->last_update = jiffies - HZ;
mutex_init(&tmp102->lock); mutex_init(&tmp102->lock);
status = sysfs_create_group(&client->dev.kobj, &tmp102_attr_group); status = sysfs_create_group(&dev->kobj, &tmp102_attr_group);
if (status) { if (status) {
dev_dbg(&client->dev, "could not create sysfs files\n"); dev_dbg(dev, "could not create sysfs files\n");
goto fail_restore_config; goto fail_restore_config;
} }
tmp102->hwmon_dev = hwmon_device_register(&client->dev); tmp102->hwmon_dev = hwmon_device_register(dev);
if (IS_ERR(tmp102->hwmon_dev)) { if (IS_ERR(tmp102->hwmon_dev)) {
dev_dbg(&client->dev, "unable to register hwmon device\n"); dev_dbg(dev, "unable to register hwmon device\n");
status = PTR_ERR(tmp102->hwmon_dev); status = PTR_ERR(tmp102->hwmon_dev);
goto fail_remove_sysfs; goto fail_remove_sysfs;
} }
tmp102->tz = thermal_zone_of_sensor_register(&client->dev, 0, tmp102->tz = thermal_zone_of_sensor_register(dev, 0, dev,
&client->dev,
tmp102_read_temp, NULL); tmp102_read_temp, NULL);
if (IS_ERR(tmp102->tz)) if (IS_ERR(tmp102->tz))
tmp102->tz = NULL; tmp102->tz = NULL;
dev_info(&client->dev, "initialized\n"); dev_info(dev, "initialized\n");
return 0; return 0;
fail_remove_sysfs: fail_remove_sysfs:
sysfs_remove_group(&client->dev.kobj, &tmp102_attr_group); sysfs_remove_group(&dev->kobj, &tmp102_attr_group);
fail_restore_config: fail_restore_config:
i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, i2c_smbus_write_word_swapped(client, TMP102_CONF_REG,
tmp102->config_orig); tmp102->config_orig);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment