lkml.org 
[lkml]   [2006]   [Apr]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 01/08] idr: add idr_replace method for replacing pointers
Jeff Mahoney <jeffm@suse.com> wrote:
>
> +/**
> + * idr_replace - replace pointer for given id
> + * @idp: idr handle
> + * @ptr: pointer you want associated with the ide
> + * @id: lookup key
> + *
> + * Replace the pointer registered with the id. A -ENOENT
> + * return indicates that @id was not found.
> + *
> + * The caller must serialize vs idr_find(), idr_get_new(), and idr_remove().
> + */
> +int idr_replace(struct idr *idp, void *ptr, int id)
> +{
> + int n;
> + struct idr_layer *p;
> + int shift = (idp->layers - 1) * IDR_BITS;
> +
> + n = idp->layers * IDR_BITS;
> + p = idp->top;
> +
> + id &= MAX_ID_MASK;
> +
> + while ((shift > 0) && p) {
> + n = (id >> shift) & IDR_MASK;
> + p = p->ary[n];
> + shift -= IDR_BITS;
> + }
> +
> + n = id & IDR_MASK;
> + if (unlikely(p == NULL || !test_bit(n, &p->bitmap)))
> + return -ENOENT;
> +
> + p->ary[n] = ptr;
> + return 0;
> +}

I'd have thought it would be more flexible were this to return the old
pointer.

If there was no old item, we could return NULL and "succeed". But that gets
a bit ill-defined, because lack of an old pointer can occur if either a)
there was a layer, but the slot was empty or b) there wasn't a layer for
this new item. So perhaps it's best to continue considering lack of an old
pointer as an error, with ERR_PTR(-ENOENT).

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-04-14 00:05    [W:0.035 / U:0.100 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site