4
4
*
5
5
* Copyright (C) 2010 OMICRON electronics GmbH
6
6
*/
7
- #include <linux/idr.h>
8
7
#include <linux/device.h>
9
8
#include <linux/err.h>
10
9
#include <linux/init.h>
16
15
#include <linux/syscalls.h>
17
16
#include <linux/uaccess.h>
18
17
#include <linux/debugfs.h>
18
+ #include <linux/xarray.h>
19
19
#include <uapi/linux/sched/types.h>
20
20
21
21
#include "ptp_private.h"
@@ -34,7 +34,7 @@ const struct class ptp_class = {
34
34
35
35
static dev_t ptp_devt ;
36
36
37
- static DEFINE_IDA (ptp_clocks_map );
37
+ static DEFINE_XARRAY_ALLOC (ptp_clocks_map );
38
38
39
39
/* time stamp event queue operations */
40
40
@@ -204,7 +204,7 @@ static void ptp_clock_release(struct device *dev)
204
204
bitmap_free (tsevq -> mask );
205
205
kfree (tsevq );
206
206
debugfs_remove (ptp -> debugfs_root );
207
- ida_free (& ptp_clocks_map , ptp -> index );
207
+ xa_erase (& ptp_clocks_map , ptp -> index );
208
208
kfree (ptp );
209
209
}
210
210
@@ -236,38 +236,42 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
236
236
{
237
237
struct ptp_clock * ptp ;
238
238
struct timestamp_event_queue * queue = NULL ;
239
- int err = 0 , index , major = MAJOR (ptp_devt );
239
+ int err , index , major = MAJOR (ptp_devt );
240
240
char debugfsname [16 ];
241
241
size_t size ;
242
242
243
243
if (info -> n_alarm > PTP_MAX_ALARMS )
244
244
return ERR_PTR (- EINVAL );
245
245
246
246
/* Initialize a clock structure. */
247
- err = - ENOMEM ;
248
247
ptp = kzalloc (sizeof (struct ptp_clock ), GFP_KERNEL );
249
- if (ptp == NULL )
248
+ if (!ptp ) {
249
+ err = - ENOMEM ;
250
250
goto no_memory ;
251
+ }
251
252
252
- index = ida_alloc_max (& ptp_clocks_map , MINORMASK , GFP_KERNEL );
253
- if ( index < 0 ) {
254
- err = index ;
253
+ err = xa_alloc (& ptp_clocks_map , & index , ptp , xa_limit_31b ,
254
+ GFP_KERNEL );
255
+ if ( err )
255
256
goto no_slot ;
256
- }
257
257
258
258
ptp -> clock .ops = ptp_clock_ops ;
259
259
ptp -> info = info ;
260
260
ptp -> devid = MKDEV (major , index );
261
261
ptp -> index = index ;
262
262
INIT_LIST_HEAD (& ptp -> tsevqs );
263
263
queue = kzalloc (sizeof (* queue ), GFP_KERNEL );
264
- if (!queue )
264
+ if (!queue ) {
265
+ err = - ENOMEM ;
265
266
goto no_memory_queue ;
267
+ }
266
268
list_add_tail (& queue -> qlist , & ptp -> tsevqs );
267
269
spin_lock_init (& ptp -> tsevqs_lock );
268
270
queue -> mask = bitmap_alloc (PTP_MAX_CHANNELS , GFP_KERNEL );
269
- if (!queue -> mask )
271
+ if (!queue -> mask ) {
272
+ err = - ENOMEM ;
270
273
goto no_memory_bitmap ;
274
+ }
271
275
bitmap_set (queue -> mask , 0 , PTP_MAX_CHANNELS );
272
276
spin_lock_init (& queue -> lock );
273
277
mutex_init (& ptp -> pincfg_mux );
@@ -381,7 +385,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
381
385
list_del (& queue -> qlist );
382
386
kfree (queue );
383
387
no_memory_queue :
384
- ida_free (& ptp_clocks_map , index );
388
+ xa_erase (& ptp_clocks_map , index );
385
389
no_slot :
386
390
kfree (ptp );
387
391
no_memory :
@@ -514,7 +518,7 @@ static void __exit ptp_exit(void)
514
518
{
515
519
class_unregister (& ptp_class );
516
520
unregister_chrdev_region (ptp_devt , MINORMASK + 1 );
517
- ida_destroy (& ptp_clocks_map );
521
+ xa_destroy (& ptp_clocks_map );
518
522
}
519
523
520
524
static int __init ptp_init (void )
0 commit comments