From: Tejun Heo <[email protected]> In sub_alloc(), when bitmap search fails, it goes up one level to continue search. This is done by updating the id cursor and searching the upper level again. If the cursor was at the end of the upper level, we need to go further than that. This wasn't implemented and when that happens the part of the cursor which indexes into the upper level wraps and sub_alloc() ends up searching the wrong bitmap. It allocates id which doesn't match the actual slot. This patch fixes this by restarting from the top if the search needs to go higher than one level. Signed-off-by: Tejun Heo <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> --- lib/idr.c | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index 305117c..7b5a59c 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -100,10 +100,11 @@ static int sub_alloc(struct idr *idp, void *ptr, int *starting_id) int n, m, sh; struct idr_layer *p, *new; struct idr_layer *pa[MAX_LEVEL]; - int l, id; + int l, id, oid; long bm; id = *starting_id; + restart: p = idp->top; l = idp->layers; pa[l--] = NULL; @@ -117,12 +118,23 @@ static int sub_alloc(struct idr *idp, void *ptr, int *starting_id) if (m == IDR_SIZE) { /* no space available go back to previous layer. */ l++; + oid = id; id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1; + + /* if already at the top layer, we need to grow */ if (!(p = pa[l])) { *starting_id = id; return -2; } - continue; + + /* If we need to go up one layer, continue the + * loop; otherwise, restart from the top. + */ + sh = IDR_BITS * (l + 1); + if (oid >> sh == id >> sh) + continue; + else + goto restart; } if (m != n) { sh = IDR_BITS*l; -- 1.5.2.2 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
- Follow-Ups:
- [PATCH 20/61] idr: separate out idr_mark_full()
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 20/61] idr: separate out idr_mark_full()
- References:
- [GIT PATCH] sysfs and driver core patches for 2.6.22
- From: Greg KH <[email protected]>
- [PATCH 01/61] Rules on how to use sysfs in userspace programs
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 02/61] debugfs: add rename for debugfs files
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 03/61] DMI-based module autoloading
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 04/61] Driver core: add missing kset uevent
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 05/61] sysdev: use mutex instead of semaphore
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 06/61] Power Management: use mutexes instead of semaphores
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 07/61] PM: Remove pm_parent from struct dev_pm_info
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 08/61] PM: Remove saved_state from struct dev_pm_info
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 09/61] PM: Simplify suspend_device
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 10/61] Driver core: include linux/mutex.h from attribute_container.c
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 11/61] driver core: properly get driver in device_release_driver
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 12/61] driver core: fix kernel doc of device_release_driver
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 13/61] Driver core: fix devres_release_all() return value
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 14/61] PM: Remove prev_state from struct dev_pm_info
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 15/61] PM: Remove power_state.event checks from suspend core code
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 16/61] PM: Do not check parent state in suspend and resume core code
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 17/61] PM: do not use saved_state from struct dev_pm_info on ARM
- From: Greg Kroah-Hartman <[email protected]>
- [PATCH 18/61] Driver core: coding style cleanup
- From: Greg Kroah-Hartman <[email protected]>
- [GIT PATCH] sysfs and driver core patches for 2.6.22
- Prev by Date: [PATCH 18/61] Driver core: coding style cleanup
- Next by Date: [PATCH 20/61] idr: separate out idr_mark_full()
- Previous by thread: [PATCH 18/61] Driver core: coding style cleanup
- Next by thread: [PATCH 20/61] idr: separate out idr_mark_full()
- Index(es):