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

pps: convert to idr_alloc()

Convert to the much saner new idr interface.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Rodolfo Giometti <giometti@enneenne.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Tejun Heo and committed by
Linus Torvalds
19dd2da3 05e2cefa

+15 -23
+1 -1
drivers/pps/kapi.c
··· 102 102 goto pps_register_source_exit; 103 103 } 104 104 105 - /* These initializations must be done before calling idr_get_new() 105 + /* These initializations must be done before calling idr_alloc() 106 106 * in order to avoid reces into pps_event(). 107 107 */ 108 108 pps->params.api_version = PPS_API_VERS;
+14 -22
drivers/pps/pps.c
··· 295 295 dev_t devt; 296 296 297 297 mutex_lock(&pps_idr_lock); 298 - /* Get new ID for the new PPS source */ 299 - if (idr_pre_get(&pps_idr, GFP_KERNEL) == 0) { 300 - mutex_unlock(&pps_idr_lock); 301 - return -ENOMEM; 302 - } 303 - 304 - /* Now really allocate the PPS source. 305 - * After idr_get_new() calling the new source will be freely available 306 - * into the kernel. 298 + /* 299 + * Get new ID for the new PPS source. After idr_alloc() calling 300 + * the new source will be freely available into the kernel. 307 301 */ 308 - err = idr_get_new(&pps_idr, pps, &pps->id); 309 - mutex_unlock(&pps_idr_lock); 310 - 311 - if (err < 0) 312 - return err; 313 - 314 - pps->id &= MAX_IDR_MASK; 315 - if (pps->id >= PPS_MAX_SOURCES) { 316 - pr_err("%s: too many PPS sources in the system\n", 317 - pps->info.name); 318 - err = -EBUSY; 319 - goto free_idr; 302 + err = idr_alloc(&pps_idr, pps, 0, PPS_MAX_SOURCES, GFP_KERNEL); 303 + if (err < 0) { 304 + if (err == -ENOSPC) { 305 + pr_err("%s: too many PPS sources in the system\n", 306 + pps->info.name); 307 + err = -EBUSY; 308 + } 309 + goto out_unlock; 320 310 } 311 + pps->id = err; 312 + mutex_unlock(&pps_idr_lock); 321 313 322 314 devt = MKDEV(MAJOR(pps_devt), pps->id); 323 315 ··· 343 351 free_idr: 344 352 mutex_lock(&pps_idr_lock); 345 353 idr_remove(&pps_idr, pps->id); 354 + out_unlock: 346 355 mutex_unlock(&pps_idr_lock); 347 - 348 356 return err; 349 357 } 350 358