diff options
Diffstat (limited to 'drivers/pps/pps.c')
-rw-r--r-- | drivers/pps/pps.c | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c index 6437703eb10f..7173e3ad475d 100644 --- a/drivers/pps/pps.c +++ b/drivers/pps/pps.c | |||
@@ -295,29 +295,21 @@ int pps_register_cdev(struct pps_device *pps) | |||
295 | dev_t devt; | 295 | dev_t devt; |
296 | 296 | ||
297 | mutex_lock(&pps_idr_lock); | 297 | mutex_lock(&pps_idr_lock); |
298 | /* Get new ID for the new PPS source */ | 298 | /* |
299 | if (idr_pre_get(&pps_idr, GFP_KERNEL) == 0) { | 299 | * Get new ID for the new PPS source. After idr_alloc() calling |
300 | mutex_unlock(&pps_idr_lock); | 300 | * the new source will be freely available into the kernel. |
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. | ||
307 | */ | 301 | */ |
308 | err = idr_get_new(&pps_idr, pps, &pps->id); | 302 | err = idr_alloc(&pps_idr, pps, 0, PPS_MAX_SOURCES, GFP_KERNEL); |
309 | mutex_unlock(&pps_idr_lock); | 303 | if (err < 0) { |
310 | 304 | if (err == -ENOSPC) { | |
311 | if (err < 0) | 305 | pr_err("%s: too many PPS sources in the system\n", |
312 | return err; | 306 | pps->info.name); |
313 | 307 | err = -EBUSY; | |
314 | pps->id &= MAX_IDR_MASK; | 308 | } |
315 | if (pps->id >= PPS_MAX_SOURCES) { | 309 | goto out_unlock; |
316 | pr_err("%s: too many PPS sources in the system\n", | ||
317 | pps->info.name); | ||
318 | err = -EBUSY; | ||
319 | goto free_idr; | ||
320 | } | 310 | } |
311 | pps->id = err; | ||
312 | mutex_unlock(&pps_idr_lock); | ||
321 | 313 | ||
322 | devt = MKDEV(MAJOR(pps_devt), pps->id); | 314 | devt = MKDEV(MAJOR(pps_devt), pps->id); |
323 | 315 | ||
@@ -351,8 +343,8 @@ del_cdev: | |||
351 | free_idr: | 343 | free_idr: |
352 | mutex_lock(&pps_idr_lock); | 344 | mutex_lock(&pps_idr_lock); |
353 | idr_remove(&pps_idr, pps->id); | 345 | idr_remove(&pps_idr, pps->id); |
346 | out_unlock: | ||
354 | mutex_unlock(&pps_idr_lock); | 347 | mutex_unlock(&pps_idr_lock); |
355 | |||
356 | return err; | 348 | return err; |
357 | } | 349 | } |
358 | 350 | ||