Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (lm70) Convert to use devm_hwmon_device_register_with_groups

Use devm_hwmon_device_register_with_groups API to attach attributes
to hwmon device, simplify code, and reduce code size.

Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

+14 -48
+14 -48
drivers/hwmon/lm70.c
··· 47 47 #define LM70_CHIP_LM74 3 /* NS LM74 */ 48 48 49 49 struct lm70 { 50 - struct device *hwmon_dev; 50 + struct spi_device *spi; 51 51 struct mutex lock; 52 52 unsigned int chip; 53 53 }; ··· 56 56 static ssize_t lm70_sense_temp(struct device *dev, 57 57 struct device_attribute *attr, char *buf) 58 58 { 59 - struct spi_device *spi = to_spi_device(dev); 59 + struct lm70 *p_lm70 = dev_get_drvdata(dev); 60 + struct spi_device *spi = p_lm70->spi; 60 61 int status, val = 0; 61 62 u8 rxbuf[2]; 62 63 s16 raw = 0; 63 - struct lm70 *p_lm70 = spi_get_drvdata(spi); 64 64 65 65 if (mutex_lock_interruptible(&p_lm70->lock)) 66 66 return -ERESTARTSYS; ··· 121 121 122 122 static DEVICE_ATTR(temp1_input, S_IRUGO, lm70_sense_temp, NULL); 123 123 124 - static ssize_t lm70_show_name(struct device *dev, struct device_attribute 125 - *devattr, char *buf) 126 - { 127 - return sprintf(buf, "%s\n", to_spi_device(dev)->modalias); 128 - } 124 + static struct attribute *lm70_attrs[] = { 125 + &dev_attr_temp1_input.attr, 126 + NULL 127 + }; 129 128 130 - static DEVICE_ATTR(name, S_IRUGO, lm70_show_name, NULL); 129 + ATTRIBUTE_GROUPS(lm70); 131 130 132 131 /*----------------------------------------------------------------------*/ 133 132 134 133 static int lm70_probe(struct spi_device *spi) 135 134 { 136 135 int chip = spi_get_device_id(spi)->driver_data; 136 + struct device *hwmon_dev; 137 137 struct lm70 *p_lm70; 138 - int status; 139 138 140 139 /* signaling is SPI_MODE_0 */ 141 140 if (spi->mode & (SPI_CPOL | SPI_CPHA)) ··· 148 149 149 150 mutex_init(&p_lm70->lock); 150 151 p_lm70->chip = chip; 152 + p_lm70->spi = spi; 151 153 152 - spi_set_drvdata(spi, p_lm70); 153 - 154 - status = device_create_file(&spi->dev, &dev_attr_temp1_input); 155 - if (status) 156 - goto out_dev_create_temp_file_failed; 157 - status = device_create_file(&spi->dev, &dev_attr_name); 158 - if (status) 159 - goto out_dev_create_file_failed; 160 - 161 - /* sysfs hook */ 162 - p_lm70->hwmon_dev = hwmon_device_register(&spi->dev); 163 - if (IS_ERR(p_lm70->hwmon_dev)) { 164 - dev_dbg(&spi->dev, "hwmon_device_register failed.\n"); 165 - status = PTR_ERR(p_lm70->hwmon_dev); 166 - goto out_dev_reg_failed; 167 - } 168 - 169 - return 0; 170 - 171 - out_dev_reg_failed: 172 - device_remove_file(&spi->dev, &dev_attr_name); 173 - out_dev_create_file_failed: 174 - device_remove_file(&spi->dev, &dev_attr_temp1_input); 175 - out_dev_create_temp_file_failed: 176 - return status; 154 + hwmon_dev = devm_hwmon_device_register_with_groups(&spi->dev, 155 + spi->modalias, 156 + p_lm70, lm70_groups); 157 + return PTR_ERR_OR_ZERO(hwmon_dev); 177 158 } 178 - 179 - static int lm70_remove(struct spi_device *spi) 180 - { 181 - struct lm70 *p_lm70 = spi_get_drvdata(spi); 182 - 183 - hwmon_device_unregister(p_lm70->hwmon_dev); 184 - device_remove_file(&spi->dev, &dev_attr_temp1_input); 185 - device_remove_file(&spi->dev, &dev_attr_name); 186 - 187 - return 0; 188 - } 189 - 190 159 191 160 static const struct spi_device_id lm70_ids[] = { 192 161 { "lm70", LM70_CHIP_LM70 }, ··· 172 205 }, 173 206 .id_table = lm70_ids, 174 207 .probe = lm70_probe, 175 - .remove = lm70_remove, 176 208 }; 177 209 178 210 module_spi_driver(lm70_driver);