Jeff Mahoney <[email protected]> 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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]