[LinuxPPS] [PATCH 03/11] pps: Clean up idr access.
George Spelvin
linux at horizon.com
Fri Feb 6 14:29:48 CET 2009
Some more minor code simplification.
---
drivers/pps/kapi.c | 30 +++++++++++++-----------------
1 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/drivers/pps/kapi.c b/drivers/pps/kapi.c
index c1129f5..1247767 100644
--- a/drivers/pps/kapi.c
+++ b/drivers/pps/kapi.c
@@ -128,7 +128,6 @@ struct pps_device *
pps_register_source(struct pps_source_info *info, int default_params)
{
struct pps_device *pps;
- int id;
int err;
/* Sanity checks */
@@ -153,42 +152,39 @@ pps_register_source(struct pps_source_info *info, int default_params)
}
/* Allocate memory for the new PPS source struct */
- pps = kzalloc(sizeof(struct pps_device), GFP_KERNEL);
+ pps = kzalloc(sizeof *pps, GFP_KERNEL);
if (pps == NULL) {
err = -ENOMEM;
goto pps_register_source_exit;
}
+ pps->params.api_version = PPS_API_VERS;
+ pps->params.mode = default_params;
+ pps->info = *info;
+
+ init_waitqueue_head(&pps->queue);
+ spin_lock_init(&pps->lock);
+ atomic_set(&pps->usage, 1);
+
/* Get new ID for the new PPS source */
if (idr_pre_get(&pps_idr, GFP_KERNEL) == 0) {
err = -ENOMEM;
goto kfree_pps;
}
-
spin_lock_irq(&pps_idr_lock);
- err = idr_get_new(&pps_idr, pps, &id);
+ err = idr_get_new(&pps_idr, pps, &pps->id);
spin_unlock_irq(&pps_idr_lock);
if (err < 0)
goto kfree_pps;
- id = id & MAX_ID_MASK;
- if (id >= PPS_MAX_SOURCES) {
+ if (pps->id >= PPS_MAX_SOURCES) {
printk(KERN_ERR "pps: %s: too many PPS sources in the system\n",
info->name);
err = -EBUSY;
goto free_idr;
}
- pps->id = id;
- pps->params.api_version = PPS_API_VERS;
- pps->params.mode = default_params;
- pps->info = *info;
-
- init_waitqueue_head(&pps->queue);
- spin_lock_init(&pps->lock);
- atomic_set(&pps->usage, 1);
-
/* Create the char device */
err = pps_register_cdev(pps);
if (err < 0) {
@@ -197,13 +193,13 @@ pps_register_source(struct pps_source_info *info, int default_params)
goto free_idr;
}
- pr_info("new PPS source %s at ID %d\n", info->name, id);
+ pr_info("new PPS source %s at ID %d\n", info->name, pps->id);
return pps;
free_idr:
spin_lock_irq(&pps_idr_lock);
- idr_remove(&pps_idr, id);
+ idr_remove(&pps_idr, pps->id);
spin_unlock_irq(&pps_idr_lock);
kfree_pps:
--
1.6.0.6
More information about the LinuxPPS
mailing list