diff options
| author | Timur Tabi <timur@freescale.com> | 2007-05-08 15:46:36 -0400 |
|---|---|---|
| committer | Kumar Gala <galak@kernel.crashing.org> | 2007-05-10 00:01:43 -0400 |
| commit | 4c35630ccda56ed494f6102d2e147fefe14b78d2 (patch) | |
| tree | 4f04754fb0ec6978923b3c1e0318997e420f6551 | |
| parent | 742226c579c573c24386aaf41969a01ee058b97e (diff) | |
[POWERPC] Change rheap functions to use ulongs instead of pointers
The rheap allocation functions return a pointer, but the actual value is based
on how the heap was initialized, and so it can be anything, e.g. an offset
into a buffer. A ulong is a better representation of the value returned by
the allocation functions.
This patch changes all of the relevant rheap functions to use a unsigned long
integers instead of a pointer. In case of an error, the value returned is
a negative error code that has been cast to an unsigned long. The caller can
use the IS_ERR_VALUE() macro to check for this.
All code which calls the rheap functions is updated accordingly. Macros
IS_MURAM_ERR() and IS_DPERR(), have been deleted in favor of IS_ERR_VALUE().
Also added error checking to rh_attach_region().
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
| -rw-r--r-- | arch/powerpc/lib/rheap.c | 117 | ||||
| -rw-r--r-- | arch/powerpc/sysdev/commproc.c | 20 | ||||
| -rw-r--r-- | arch/powerpc/sysdev/cpm2_common.c | 21 | ||||
| -rw-r--r-- | arch/powerpc/sysdev/qe_lib/qe.c | 29 | ||||
| -rw-r--r-- | arch/powerpc/sysdev/qe_lib/ucc_fast.c | 5 | ||||
| -rw-r--r-- | arch/powerpc/sysdev/qe_lib/ucc_slow.c | 7 | ||||
| -rw-r--r-- | arch/ppc/8xx_io/commproc.c | 22 | ||||
| -rw-r--r-- | arch/ppc/lib/rheap.c | 95 | ||||
| -rw-r--r-- | arch/ppc/syslib/cpm2_common.c | 23 | ||||
| -rw-r--r-- | drivers/net/fs_enet/mac-scc.c | 2 | ||||
| -rw-r--r-- | drivers/net/ucc_geth.c | 30 | ||||
| -rw-r--r-- | drivers/serial/cpm_uart/cpm_uart_cpm1.c | 4 | ||||
| -rw-r--r-- | drivers/serial/cpm_uart/cpm_uart_cpm2.c | 4 | ||||
| -rw-r--r-- | include/asm-powerpc/qe.h | 13 | ||||
| -rw-r--r-- | include/asm-ppc/commproc.h | 13 | ||||
| -rw-r--r-- | include/asm-ppc/cpm2.h | 13 | ||||
| -rw-r--r-- | include/asm-ppc/rheap.h | 20 |
17 files changed, 221 insertions, 217 deletions
diff --git a/arch/powerpc/lib/rheap.c b/arch/powerpc/lib/rheap.c index 6c5c5dd183ee..b2f6dcc59600 100644 --- a/arch/powerpc/lib/rheap.c +++ b/arch/powerpc/lib/rheap.c | |||
| @@ -133,7 +133,7 @@ static rh_block_t *get_slot(rh_info_t * info) | |||
| 133 | info->empty_slots--; | 133 | info->empty_slots--; |
| 134 | 134 | ||
| 135 | /* Initialize */ | 135 | /* Initialize */ |
| 136 | blk->start = NULL; | 136 | blk->start = 0; |
| 137 | blk->size = 0; | 137 | blk->size = 0; |
| 138 | blk->owner = NULL; | 138 | blk->owner = NULL; |
| 139 | 139 | ||
| @@ -158,7 +158,7 @@ static void attach_free_block(rh_info_t * info, rh_block_t * blkn) | |||
| 158 | 158 | ||
| 159 | /* We assume that they are aligned properly */ | 159 | /* We assume that they are aligned properly */ |
| 160 | size = blkn->size; | 160 | size = blkn->size; |
| 161 | s = (unsigned long)blkn->start; | 161 | s = blkn->start; |
| 162 | e = s + size; | 162 | e = s + size; |
| 163 | 163 | ||
| 164 | /* Find the blocks immediately before and after the given one | 164 | /* Find the blocks immediately before and after the given one |
| @@ -170,7 +170,7 @@ static void attach_free_block(rh_info_t * info, rh_block_t * blkn) | |||
| 170 | list_for_each(l, &info->free_list) { | 170 | list_for_each(l, &info->free_list) { |
| 171 | blk = list_entry(l, rh_block_t, list); | 171 | blk = list_entry(l, rh_block_t, list); |
| 172 | 172 | ||
| 173 | bs = (unsigned long)blk->start; | 173 | bs = blk->start; |
| 174 | be = bs + blk->size; | 174 | be = bs + blk->size; |
| 175 | 175 | ||
| 176 | if (next == NULL && s >= bs) | 176 | if (next == NULL && s >= bs) |
| @@ -188,10 +188,10 @@ static void attach_free_block(rh_info_t * info, rh_block_t * blkn) | |||
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | /* Now check if they are really adjacent */ | 190 | /* Now check if they are really adjacent */ |
| 191 | if (before != NULL && s != (unsigned long)before->start + before->size) | 191 | if (before && s != (before->start + before->size)) |
| 192 | before = NULL; | 192 | before = NULL; |
| 193 | 193 | ||
| 194 | if (after != NULL && e != (unsigned long)after->start) | 194 | if (after && e != after->start) |
| 195 | after = NULL; | 195 | after = NULL; |
| 196 | 196 | ||
| 197 | /* No coalescing; list insert and return */ | 197 | /* No coalescing; list insert and return */ |
| @@ -216,7 +216,7 @@ static void attach_free_block(rh_info_t * info, rh_block_t * blkn) | |||
| 216 | 216 | ||
| 217 | /* Grow the after block backwards */ | 217 | /* Grow the after block backwards */ |
| 218 | if (before == NULL && after != NULL) { | 218 | if (before == NULL && after != NULL) { |
| 219 | after->start = (int8_t *)after->start - size; | 219 | after->start -= size; |
| 220 | after->size += size; | 220 | after->size += size; |
| 221 | return; | 221 | return; |
| 222 | } | 222 | } |
| @@ -321,14 +321,14 @@ void rh_init(rh_info_t * info, unsigned int alignment, int max_blocks, | |||
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | /* Attach a free memory region, coalesces regions if adjuscent */ | 323 | /* Attach a free memory region, coalesces regions if adjuscent */ |
| 324 | int rh_attach_region(rh_info_t * info, void *start, int size) | 324 | int rh_attach_region(rh_info_t * info, unsigned long start, int size) |
| 325 | { | 325 | { |
| 326 | rh_block_t *blk; | 326 | rh_block_t *blk; |
| 327 | unsigned long s, e, m; | 327 | unsigned long s, e, m; |
| 328 | int r; | 328 | int r; |
| 329 | 329 | ||
| 330 | /* The region must be aligned */ | 330 | /* The region must be aligned */ |
| 331 | s = (unsigned long)start; | 331 | s = start; |
| 332 | e = s + size; | 332 | e = s + size; |
| 333 | m = info->alignment - 1; | 333 | m = info->alignment - 1; |
| 334 | 334 | ||
| @@ -338,9 +338,12 @@ int rh_attach_region(rh_info_t * info, void *start, int size) | |||
| 338 | /* Round end down */ | 338 | /* Round end down */ |
| 339 | e = e & ~m; | 339 | e = e & ~m; |
| 340 | 340 | ||
| 341 | if (IS_ERR_VALUE(e) || (e < s)) | ||
| 342 | return -ERANGE; | ||
| 343 | |||
| 341 | /* Take final values */ | 344 | /* Take final values */ |
| 342 | start = (void *)s; | 345 | start = s; |
| 343 | size = (int)(e - s); | 346 | size = e - s; |
| 344 | 347 | ||
| 345 | /* Grow the blocks, if needed */ | 348 | /* Grow the blocks, if needed */ |
| 346 | r = assure_empty(info, 1); | 349 | r = assure_empty(info, 1); |
| @@ -358,7 +361,7 @@ int rh_attach_region(rh_info_t * info, void *start, int size) | |||
| 358 | } | 361 | } |
| 359 | 362 | ||
| 360 | /* Detatch given address range, splits free block if needed. */ | 363 | /* Detatch given address range, splits free block if needed. */ |
| 361 | void *rh_detach_region(rh_info_t * info, void *start, int size) | 364 | unsigned long rh_detach_region(rh_info_t * info, unsigned long start, int size) |
| 362 | { | 365 | { |
| 363 | struct list_head *l; | 366 | struct list_head *l; |
| 364 | rh_block_t *blk, *newblk; | 367 | rh_block_t *blk, *newblk; |
| @@ -366,10 +369,10 @@ void *rh_detach_region(rh_info_t * info, void *start, int size) | |||
| 366 | 369 | ||
| 367 | /* Validate size */ | 370 | /* Validate size */ |
| 368 | if (size <= 0) | 371 | if (size <= 0) |
| 369 | return ERR_PTR(-EINVAL); | 372 | return (unsigned long) -EINVAL; |
| 370 | 373 | ||
| 371 | /* The region must be aligned */ | 374 | /* The region must be aligned */ |
| 372 | s = (unsigned long)start; | 375 | s = start; |
| 373 | e = s + size; | 376 | e = s + size; |
| 374 | m = info->alignment - 1; | 377 | m = info->alignment - 1; |
| 375 | 378 | ||
| @@ -380,34 +383,34 @@ void *rh_detach_region(rh_info_t * info, void *start, int size) | |||
| 380 | e = e & ~m; | 383 | e = e & ~m; |
| 381 | 384 | ||
| 382 | if (assure_empty(info, 1) < 0) | 385 | if (assure_empty(info, 1) < 0) |
| 383 | return ERR_PTR(-ENOMEM); | 386 | return (unsigned long) -ENOMEM; |
| 384 | 387 | ||
| 385 | blk = NULL; | 388 | blk = NULL; |
| 386 | list_for_each(l, &info->free_list) { | 389 | list_for_each(l, &info->free_list) { |
| 387 | blk = list_entry(l, rh_block_t, list); | 390 | blk = list_entry(l, rh_block_t, list); |
| 388 | /* The range must lie entirely inside one free block */ | 391 | /* The range must lie entirely inside one free block */ |
| 389 | bs = (unsigned long)blk->start; | 392 | bs = blk->start; |
| 390 | be = (unsigned long)blk->start + blk->size; | 393 | be = blk->start + blk->size; |
| 391 | if (s >= bs && e <= be) | 394 | if (s >= bs && e <= be) |
| 392 | break; | 395 | break; |
| 393 | blk = NULL; | 396 | blk = NULL; |
| 394 | } | 397 | } |
| 395 | 398 | ||
| 396 | if (blk == NULL) | 399 | if (blk == NULL) |
| 397 | return ERR_PTR(-ENOMEM); | 400 | return (unsigned long) -ENOMEM; |
| 398 | 401 | ||
| 399 | /* Perfect fit */ | 402 | /* Perfect fit */ |
| 400 | if (bs == s && be == e) { | 403 | if (bs == s && be == e) { |
| 401 | /* Delete from free list, release slot */ | 404 | /* Delete from free list, release slot */ |
| 402 | list_del(&blk->list); | 405 | list_del(&blk->list); |
| 403 | release_slot(info, blk); | 406 | release_slot(info, blk); |
