@@ -43,8 +43,7 @@ static void counter_device_release(struct device *dev)
4343 counter_chrdev_remove (counter );
4444 ida_free (& counter_ida , dev -> id );
4545
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 ));
4847}
4948
5049static struct device_type counter_device_type = {
@@ -67,76 +66,13 @@ static dev_t counter_devt;
6766 */
6867void * counter_priv (const struct counter_device * const counter )
6968{
70- if (counter -> legacy_device ) {
71- return counter -> priv ;
72- } else {
73- struct counter_device_allochelper * ch =
74- container_of (counter , struct counter_device_allochelper , counter );
69+ struct counter_device_allochelper * ch =
70+ container_of (counter , struct counter_device_allochelper , counter );
7571
76- return & ch -> privdata ;
77- }
72+ return & ch -> privdata ;
7873}
7974EXPORT_SYMBOL_GPL (counter_priv );
8075
81- /**
82- * counter_register - register Counter to the system
83- * @counter: pointer to Counter to register
84- *
85- * This function registers a Counter to the system. A sysfs "counter" directory
86- * will be created and populated with sysfs attributes correlating with the
87- * Counter Signals, Synapses, and Counts respectively.
88- *
89- * RETURNS:
90- * 0 on success, negative error number on failure.
91- */
92- int counter_register (struct counter_device * const counter )
93- {
94- struct device * const dev = & counter -> dev ;
95- int id ;
96- int err ;
97-
98- counter -> legacy_device = true;
99-
100- /* Acquire unique ID */
101- id = ida_alloc (& counter_ida , GFP_KERNEL );
102- if (id < 0 )
103- return id ;
104-
105- mutex_init (& counter -> ops_exist_lock );
106-
107- /* Configure device structure for Counter */
108- dev -> id = id ;
109- dev -> type = & counter_device_type ;
110- dev -> bus = & counter_bus_type ;
111- dev -> devt = MKDEV (MAJOR (counter_devt ), id );
112- if (counter -> parent ) {
113- dev -> parent = counter -> parent ;
114- dev -> of_node = counter -> parent -> of_node ;
115- }
116- device_initialize (dev );
117-
118- err = counter_sysfs_add (counter );
119- if (err < 0 )
120- goto err_free_id ;
121-
122- err = counter_chrdev_add (counter );
123- if (err < 0 )
124- goto err_free_id ;
125-
126- err = cdev_device_add (& counter -> chrdev , dev );
127- if (err < 0 )
128- goto err_remove_chrdev ;
129-
130- return 0 ;
131-
132- err_remove_chrdev :
133- counter_chrdev_remove (counter );
134- err_free_id :
135- put_device (dev );
136- return err ;
137- }
138- EXPORT_SYMBOL_GPL (counter_register );
139-
14076/**
14177 * counter_alloc - allocate a counter_device
14278 * @sizeof_priv: size of the driver private data
@@ -245,9 +181,6 @@ void counter_unregister(struct counter_device *const counter)
245181 wake_up (& counter -> events_wait );
246182
247183 mutex_unlock (& counter -> ops_exist_lock );
248-
249- if (counter -> legacy_device )
250- put_device (& counter -> dev );
251184}
252185EXPORT_SYMBOL_GPL (counter_unregister );
253186
@@ -256,31 +189,6 @@ static void devm_counter_release(void *counter)
256189 counter_unregister (counter );
257190}
258191
259- /**
260- * devm_counter_register - Resource-managed counter_register
261- * @dev: device to allocate counter_device for
262- * @counter: pointer to Counter to register
263- *
264- * Managed counter_register. The Counter registered with this function is
265- * automatically unregistered on driver detach. This function calls
266- * counter_register internally. Refer to that function for more information.
267- *
268- * RETURNS:
269- * 0 on success, negative error number on failure.
270- */
271- int devm_counter_register (struct device * dev ,
272- struct counter_device * const counter )
273- {
274- int err ;
275-
276- err = counter_register (counter );
277- if (err < 0 )
278- return err ;
279-
280- return devm_add_action_or_reset (dev , devm_counter_release , counter );
281- }
282- EXPORT_SYMBOL_GPL (devm_counter_register );
283-
284192static void devm_counter_put (void * counter )
285193{
286194 counter_put (counter );
0 commit comments