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

counter: remove old and now unused registration API

Usage of counter_register() yields issues in device lifetime tracking. All
drivers were converted to the new API, so the old one can go away.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20211230150300.72196-24-u.kleine-koenig@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Uwe Kleine-König and committed by
Greg Kroah-Hartman
f2ee4759 02758cb2

+4 -108
+4 -96
drivers/counter/counter-core.c
··· 43 43 counter_chrdev_remove(counter); 44 44 ida_free(&counter_ida, dev->id); 45 45 46 - if (!counter->legacy_device) 47 - kfree(container_of(counter, struct counter_device_allochelper, counter)); 46 + kfree(container_of(counter, struct counter_device_allochelper, counter)); 48 47 } 49 48 50 49 static struct device_type counter_device_type = { ··· 66 67 */ 67 68 void *counter_priv(const struct counter_device *const counter) 68 69 { 69 - if (counter->legacy_device) { 70 - return counter->priv; 71 - } else { 72 - struct counter_device_allochelper *ch = 73 - container_of(counter, struct counter_device_allochelper, counter); 70 + struct counter_device_allochelper *ch = 71 + container_of(counter, struct counter_device_allochelper, counter); 74 72 75 - return &ch->privdata; 76 - } 73 + return &ch->privdata; 77 74 } 78 75 EXPORT_SYMBOL_GPL(counter_priv); 79 - 80 - /** 81 - * counter_register - register Counter to the system 82 - * @counter: pointer to Counter to register 83 - * 84 - * This function registers a Counter to the system. A sysfs "counter" directory 85 - * will be created and populated with sysfs attributes correlating with the 86 - * Counter Signals, Synapses, and Counts respectively. 87 - * 88 - * RETURNS: 89 - * 0 on success, negative error number on failure. 90 - */ 91 - int counter_register(struct counter_device *const counter) 92 - { 93 - struct device *const dev = &counter->dev; 94 - int id; 95 - int err; 96 - 97 - counter->legacy_device = true; 98 - 99 - /* Acquire unique ID */ 100 - id = ida_alloc(&counter_ida, GFP_KERNEL); 101 - if (id < 0) 102 - return id; 103 - 104 - mutex_init(&counter->ops_exist_lock); 105 - 106 - /* Configure device structure for Counter */ 107 - dev->id = id; 108 - dev->type = &counter_device_type; 109 - dev->bus = &counter_bus_type; 110 - dev->devt = MKDEV(MAJOR(counter_devt), id); 111 - if (counter->parent) { 112 - dev->parent = counter->parent; 113 - dev->of_node = counter->parent->of_node; 114 - } 115 - device_initialize(dev); 116 - 117 - err = counter_sysfs_add(counter); 118 - if (err < 0) 119 - goto err_free_id; 120 - 121 - err = counter_chrdev_add(counter); 122 - if (err < 0) 123 - goto err_free_id; 124 - 125 - err = cdev_device_add(&counter->chrdev, dev); 126 - if (err < 0) 127 - goto err_remove_chrdev; 128 - 129 - return 0; 130 - 131 - err_remove_chrdev: 132 - counter_chrdev_remove(counter); 133 - err_free_id: 134 - put_device(dev); 135 - return err; 136 - } 137 - EXPORT_SYMBOL_GPL(counter_register); 138 76 139 77 /** 140 78 * counter_alloc - allocate a counter_device ··· 181 245 wake_up(&counter->events_wait); 182 246 183 247 mutex_unlock(&counter->ops_exist_lock); 184 - 185 - if (counter->legacy_device) 186 - put_device(&counter->dev); 187 248 } 188 249 EXPORT_SYMBOL_GPL(counter_unregister); 189 250 ··· 188 255 { 189 256 counter_unregister(counter); 190 257 } 191 - 192 - /** 193 - * devm_counter_register - Resource-managed counter_register 194 - * @dev: device to allocate counter_device for 195 - * @counter: pointer to Counter to register 196 - * 197 - * Managed counter_register. The Counter registered with this function is 198 - * automatically unregistered on driver detach. This function calls 199 - * counter_register internally. Refer to that function for more information. 200 - * 201 - * RETURNS: 202 - * 0 on success, negative error number on failure. 203 - */ 204 - int devm_counter_register(struct device *dev, 205 - struct counter_device *const counter) 206 - { 207 - int err; 208 - 209 - err = counter_register(counter); 210 - if (err < 0) 211 - return err; 212 - 213 - return devm_add_action_or_reset(dev, devm_counter_release, counter); 214 - } 215 - EXPORT_SYMBOL_GPL(devm_counter_register); 216 258 217 259 static void devm_counter_put(void *counter) 218 260 {
-12
include/linux/counter.h
··· 314 314 struct counter_comp *ext; 315 315 size_t num_ext; 316 316 317 - void *priv; 318 - 319 317 struct device dev; 320 318 struct cdev chrdev; 321 319 struct list_head events_list; ··· 325 327 spinlock_t events_in_lock; 326 328 struct mutex events_out_lock; 327 329 struct mutex ops_exist_lock; 328 - 329 - /* 330 - * This can go away once all drivers are converted to 331 - * counter_alloc()/counter_add(). 332 - */ 333 - bool legacy_device; 334 330 }; 335 331 336 332 void *counter_priv(const struct counter_device *const counter); 337 - 338 - int counter_register(struct counter_device *const counter); 339 333 340 334 struct counter_device *counter_alloc(size_t sizeof_priv); 341 335 void counter_put(struct counter_device *const counter); 342 336 int counter_add(struct counter_device *const counter); 343 337 344 338 void counter_unregister(struct counter_device *const counter); 345 - int devm_counter_register(struct device *dev, 346 - struct counter_device *const counter); 347 339 struct counter_device *devm_counter_alloc(struct device *dev, 348 340 size_t sizeof_priv); 349 341 int devm_counter_add(struct device *dev,