mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jim Houston <jim.houston@ccur.com>
To: tridge@samba.org, Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] Re: idr in Samba4
Date: 21 Oct 2004 14:32:18 -0400	[thread overview]
Message-ID: <1098383538.987.359.camel@new.localdomain> (raw)
In-Reply-To: <16759.16648.459393.752417@samba.org>

On Thu, 2004-10-21 at 00:54, tridge@samba.org wrote:

> Apart from converting idr to use our pool allocator, and some other
> minor user-space tweaks, the only significant change I've made is to
> add a idr_find() call at the top of idr_remove() to catch possible
> errors where idr_remove() is called multiple times. Obviously this is
> programmer error if it happens, but I didn't like the default
> behaviour (I saw corruption in the tree without this check).


Hi Tridge, Andrew,

Tridge, thanks for your note.  I'm glad to hear you are using idr.c.

I agree with your concerns about idr_remove().  It really should
fail gracefully and warn if the id being removed is not valid.

The attached patch against linux-2.6.9 should do the job without
additional overhead.  Andrew, I hope you will add this patch to
your tree.

With the existing code, removing an id which was not allocated
could remove a valid id which shares the same lowest layer of the 
radix tree.

I ran a kernel with this patch but have not done any tests to force
a failure.

Jim Houston - Concurrent Computer Corp.


--- linux-2.6.9/lib/idr.c.orig	2004-10-21 12:57:24.547106092 -0400
+++ linux-2.6.9/lib/idr.c	2004-10-21 13:09:28.984974796 -0400
@@ -277,24 +277,31 @@
 }
 EXPORT_SYMBOL(idr_get_new);
 
+static void idr_remove_warning(int id)
+{
+	printk("idr_remove called for id=%d which is not allocated.\n", id);
+	dump_stack();
+}
+
 static void sub_remove(struct idr *idp, int shift, int id)
 {
 	struct idr_layer *p = idp->top;
 	struct idr_layer **pa[MAX_LEVEL];
 	struct idr_layer ***paa = &pa[0];
+	int n;
 
 	*paa = NULL;
 	*++paa = &idp->top;
 
 	while ((shift > 0) && p) {
-		int n = (id >> shift) & IDR_MASK;
+		n = (id >> shift) & IDR_MASK;
 		__clear_bit(n, &p->bitmap);
 		*++paa = &p->ary[n];
 		p = p->ary[n];
 		shift -= IDR_BITS;
 	}
-	if (likely(p != NULL)){
-		int n = id & IDR_MASK;
+	n = id & IDR_MASK;
+	if (likely(p != NULL && test_bit(n, &p->bitmap))){
 		__clear_bit(n, &p->bitmap);
 		p->ary[n] = NULL;
 		while(*paa && ! --((**paa)->count)){
@@ -303,6 +310,8 @@
 		}
 		if ( ! *paa )
 			idp->layers = 0;
+	} else {
+		idr_remove_warning(id);
 	}
 }
 





       reply	other threads:[~2004-10-21 18:42 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <16759.16648.459393.752417@samba.org>
2004-10-21 18:32 ` Jim Houston [this message]
2004-10-22  6:17   ` tridge
2004-11-19  7:38   ` performance of filesystem xattrs with Samba4 tridge
2004-11-19  8:08     ` James Morris
2004-11-19 10:16     ` Andreas Dilger
2004-11-19 11:43       ` tridge
2004-11-19 22:28         ` Andreas Dilger
2004-11-22 13:02       ` tridge
2004-11-22 21:40         ` Andreas Dilger
2004-11-19 12:03     ` Anton Altaparmakov
2004-11-19 12:43       ` tridge
2004-11-19 14:11         ` Anton Altaparmakov
2004-11-20 10:44           ` tridge
2004-11-20 16:20             ` Hans Reiser
2004-11-20 23:29               ` tridge
2004-11-19 15:34     ` Hans Reiser
2004-11-19 15:58       ` Jan Engelhardt
2004-11-19 22:03       ` tridge
2004-11-20  4:51         ` Hans Reiser
2004-11-19 23:01       ` tridge
2004-11-20  0:26         ` Andrew Morton
2004-11-21  1:14           ` tridge
2004-11-21  2:12           ` tridge
2004-11-21 23:53           ` tridge
2004-11-23  9:37           ` tridge
2004-11-23 17:55             ` Andreas Dilger
2004-11-24  7:53           ` tridge
2004-11-20  4:40         ` Hans Reiser
2004-11-20  6:47           ` tridge
2004-11-20 16:13             ` Hans Reiser
2004-11-20 23:16               ` tridge
2004-11-21  2:36                 ` Hans Reiser
2004-11-21  0:21               ` tridge
2004-11-21  2:41                 ` Hans Reiser
2004-11-21  1:53               ` tridge
2004-11-21  2:48                 ` Hans Reiser
2004-11-21  3:19                   ` tridge
2004-11-21  6:11                     ` Hans Reiser
2004-11-21 22:21     ` Nathan Scott
2004-11-21 23:43       ` tridge

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=1098383538.987.359.camel@new.localdomain \
    --to=jim.houston@ccur.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tridge@samba.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®