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

Input: axp20x-pek - switch over to using attribute group

Instead of registering device attributes individually let's use attribute
groups and also devm_* infrastructure to ease cleanup.

Tested-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+36 -28
+36 -28
drivers/input/misc/axp20x-pek.c
··· 138 138 axp20x_ea->mask, idx); 139 139 if (ret != 0) 140 140 return -EINVAL; 141 + 141 142 return count; 142 143 } 143 144 144 145 static struct dev_ext_attribute axp20x_dev_attr_startup = { 145 146 .attr = __ATTR(startup, 0644, axp20x_show_ext_attr, axp20x_store_ext_attr), 146 - .var = &axp20x_pek_startup_ext_attr 147 + .var = &axp20x_pek_startup_ext_attr, 147 148 }; 148 149 149 150 static struct dev_ext_attribute axp20x_dev_attr_shutdown = { 150 151 .attr = __ATTR(shutdown, 0644, axp20x_show_ext_attr, axp20x_store_ext_attr), 151 - .var = &axp20x_pek_shutdown_ext_attr 152 + .var = &axp20x_pek_shutdown_ext_attr, 153 + }; 154 + 155 + static struct attribute *axp20x_attributes[] = { 156 + &axp20x_dev_attr_startup.attr.attr, 157 + &axp20x_dev_attr_shutdown.attr.attr, 158 + NULL, 159 + }; 160 + 161 + static const struct attribute_group axp20x_attribute_group = { 162 + .attrs = axp20x_attributes, 152 163 }; 153 164 154 165 static irqreturn_t axp20x_pek_irq(int irq, void *pwr) ··· 175 164 input_sync(idev); 176 165 177 166 return IRQ_HANDLED; 167 + } 168 + 169 + static void axp20x_remove_sysfs_group(void *_data) 170 + { 171 + struct device *dev = _data; 172 + 173 + sysfs_remove_group(&dev->kobj, &axp20x_attribute_group); 178 174 } 179 175 180 176 static int axp20x_pek_probe(struct platform_device *pdev) ··· 232 214 input_set_drvdata(idev, axp20x_pek); 233 215 234 216 error = devm_request_any_context_irq(&pdev->dev, axp20x_pek->irq_dbr, 235 - axp20x_pek_irq, 0, 236 - "axp20x-pek-dbr", idev); 217 + axp20x_pek_irq, 0, 218 + "axp20x-pek-dbr", idev); 237 219 if (error < 0) { 238 220 dev_err(axp20x->dev, "Failed to request dbr IRQ#%d: %d\n", 239 221 axp20x_pek->irq_dbr, error); 240 - 241 222 return error; 242 223 } 243 224 ··· 249 232 return error; 250 233 } 251 234 252 - error = device_create_file(&pdev->dev, &axp20x_dev_attr_startup.attr); 253 - if (error) 235 + error = sysfs_create_group(&pdev->dev.kobj, &axp20x_attribute_group); 236 + if (error) { 237 + dev_err(axp20x->dev, "Failed to create sysfs attributes: %d\n", 238 + error); 254 239 return error; 240 + } 255 241 256 - error = device_create_file(&pdev->dev, &axp20x_dev_attr_shutdown.attr); 257 - if (error) 258 - goto clear_startup_attr; 242 + error = devm_add_action(&pdev->dev, 243 + axp20x_remove_sysfs_group, &pdev->dev); 244 + if (error) { 245 + axp20x_remove_sysfs_group(&pdev->dev); 246 + dev_err(&pdev->dev, "Failed to add sysfs cleanup action: %d\n", 247 + error); 248 + return error; 249 + } 259 250 260 251 error = input_register_device(idev); 261 252 if (error) { 262 253 dev_err(axp20x->dev, "Can't register input device: %d\n", 263 254 error); 264 - goto clear_attr; 255 + return error; 265 256 } 266 257 267 258 platform_set_drvdata(pdev, axp20x_pek); 268 - 269 - return 0; 270 - 271 - clear_attr: 272 - device_remove_file(&pdev->dev, &axp20x_dev_attr_shutdown.attr); 273 - 274 - clear_startup_attr: 275 - device_remove_file(&pdev->dev, &axp20x_dev_attr_startup.attr); 276 - 277 - return error; 278 - } 279 - 280 - static int axp20x_pek_remove(struct platform_device *pdev) 281 - { 282 - device_remove_file(&pdev->dev, &axp20x_dev_attr_shutdown.attr); 283 - device_remove_file(&pdev->dev, &axp20x_dev_attr_startup.attr); 284 259 285 260 return 0; 286 261 } 287 262 288 263 static struct platform_driver axp20x_pek_driver = { 289 264 .probe = axp20x_pek_probe, 290 - .remove = axp20x_pek_remove, 291 265 .driver = { 292 266 .name = "axp20x-pek", 293 267 },