mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Jeff Mahoney <jeffm@suse.com>
Cc: linux-kernel@vger.kernel.org, torvalds@osdl.org
Subject: Re: [PATCH 01/08] idr: add idr_replace method for replacing pointers
Date: Thu, 13 Apr 2006 15:05:27 -0700	[thread overview]
Message-ID: <20060413150527.0028bc88.akpm@osdl.org> (raw)
In-Reply-To: <20060413203546.GA3170@locomotive.unixthugs.org>

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).


  reply	other threads:[~2006-04-13 22:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-13 20:35 Jeff Mahoney
2006-04-13 22:05 ` Andrew Morton [this message]
2006-04-14  0:08   ` Jeff Mahoney
2006-04-13 20:35 Jeff Mahoney
2006-04-13 20:44 ` Jeff Mahoney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060413150527.0028bc88.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=jeffm@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®