Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S261570AbVEZPnS (ORCPT ); Thu, 26 May 2005 11:43:18 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S261571AbVEZPnS (ORCPT ); Thu, 26 May 2005 11:43:18 -0400 Received: from fire.osdl.org ([65.172.181.4]:41156 "EHLO smtp.osdl.org") by vger.kernel.org with ESMTP id S261570AbVEZPnO (ORCPT ); Thu, 26 May 2005 11:43:14 -0400 Date: Thu, 26 May 2005 08:44:37 -0700 (PDT) From: Linus Torvalds To: Robin Holt cc: Simon Derr , Paul Jackson , Andrew Morton , Dinakar Guniguntala , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2.6.12-rc4] cpuset exit NULL dereference fix In-Reply-To: <20050526120859.GD29852@lnx-holt.americas.sgi.com> Message-ID: References: <20050526082508.927.67614.sendpatchset@tomahawk.engr.sgi.com> <20050526120859.GD29852@lnx-holt.americas.sgi.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1032 Lines: 30 On Thu, 26 May 2005, Robin Holt wrote: > > Why not change the atomic into a lock and a refcount. Grab the lock before > each increment/decrement of the refcount and only continue with the removal > code when the refcount reaches 0. For this, there is a nice atomic_dec_and_lock() function that is the same as "atomic_dec_and_test()", except it grabs the lock if the count decrements to zero. I'm surprised people haven't picked up on it - it's been around for a while, the VFS layer uses it for some quite fundamental data structures (inode and dcache refcounts), and it's even documented in "atomic_ops.txt" And it's _designed_ for refcountign things like this. Basic rule of kernel programming: if a globally visible object does not have a refcount, IT IS A BUG. Linus - 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/