Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753981AbZAMPes (ORCPT ); Tue, 13 Jan 2009 10:34:48 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752124AbZAMPei (ORCPT ); Tue, 13 Jan 2009 10:34:38 -0500 Received: from miranda.se.axis.com ([193.13.178.8]:35413 "EHLO miranda.se.axis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752047AbZAMPeh (ORCPT ); Tue, 13 Jan 2009 10:34:37 -0500 X-Greylist: delayed 1182 seconds by postgrey-1.27 at vger.kernel.org; Tue, 13 Jan 2009 10:34:36 EST Date: Tue, 13 Jan 2009 16:14:06 +0100 From: Jesper Nilsson To: Tejun Heo , Greg Kroah-Hartman , Alan Stern , jens.axboe@oracle.com, Hinko Kocevar Cc: linux-kernel@vger.kernel.org Subject: lib/klist.c: bit 0 in pointer can't be used as flag Message-ID: <20090113151406.GC19262@axis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3306 Lines: 92 The commit a1ed5b0cffe4b16a93a6a3390e8cee0fbef94f86 (klist: don't iterate over deleted entries) introduces use of the low bit in a pointer to indicate if the knode is dead or not, assuming that this bit is always free. This is not true for all architectures, CRIS for example may align data on byte borders. The result is a bunch of warnings on bootup, devices not being added correctly etc, reported by Hinko Kocevar : ------------[ cut here ]------------ WARNING: at lib/klist.c:62 () Modules linked in: Stack from c1fe1cf0: c01cc7f4 c1fe1d11 c000eb4e c000e4de 00000000 00000000 c1f4f78f c1f50c2d c01d008c c1fdd1a0 c1fdd1a0 c1fe1d38 c0192954 c1fe0000 00000000 c1fe1dc0 00000002 7fffffff c1fe1da8 c0192d50 c1fe1dc0 00000002 7fffffff c1ff9fcc Call Trace: [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] <4>---[ end trace 4eaa2a86a8e2da22 ]--- ------------[ cut here ]------------ Repeat ad nauseam. The following naive patch fixes the problem by moving the flag to a separate field in struct klist_node, but perhaps there is a better solution? Signed-off-by: Jesper Nilsson --- include/linux/klist.h | 1 + lib/klist.c | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/linux/klist.h b/include/linux/klist.h index d5a27af..e542629 100644 --- a/include/linux/klist.h +++ b/include/linux/klist.h @@ -40,6 +40,7 @@ struct klist_node { void *n_klist; /* never access directly */ struct list_head n_node; struct kref n_ref; + unsigned int flags; }; extern void klist_add_tail(struct klist_node *n, struct klist *k); diff --git a/lib/klist.c b/lib/klist.c index 573d606..72ec552 100644 --- a/lib/klist.c +++ b/lib/klist.c @@ -43,17 +43,15 @@ * dead ones from iteration. */ #define KNODE_DEAD 1LU -#define KNODE_KLIST_MASK ~KNODE_DEAD static struct klist *knode_klist(struct klist_node *knode) { - return (struct klist *) - ((unsigned long)knode->n_klist & KNODE_KLIST_MASK); + return (struct klist *)knode->n_klist; } static bool knode_dead(struct klist_node *knode) { - return (unsigned long)knode->n_klist & KNODE_DEAD; + return knode->flags & KNODE_DEAD; } static void knode_set_klist(struct klist_node *knode, struct klist *klist) @@ -67,7 +65,7 @@ static void knode_kill(struct klist_node *knode) { /* and no knode should die twice ever either, see we're very humane */ WARN_ON(knode_dead(knode)); - *(unsigned long *)&knode->n_klist |= KNODE_DEAD; + knode->flags |= KNODE_DEAD; } /** /^JN - Jesper Nilsson -- Jesper Nilsson -- jesper.nilsson@axis.com -- 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/