mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@osdl.org>
To: Robin Holt <holt@sgi.com>
Cc: Simon Derr <Simon.Derr@bull.net>, Paul Jackson <pj@sgi.com>,
	Andrew Morton <akpm@osdl.org>,
	Dinakar Guniguntala <dino@in.ibm.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2.6.12-rc4] cpuset exit NULL dereference fix
Date: Thu, 26 May 2005 08:44:37 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.58.0505260840470.2307@ppc970.osdl.org> (raw)
In-Reply-To: <20050526120859.GD29852@lnx-holt.americas.sgi.com>



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

  reply	other threads:[~2005-05-26 15:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-26  8:25 Paul Jackson
2005-05-26  9:00 ` Simon Derr
2005-05-26 12:08   ` Robin Holt
2005-05-26 15:44     ` Linus Torvalds [this message]
2005-05-26 18:46       ` Paul Jackson
2005-05-26 20:46     ` Paul Jackson
2005-05-26 13:54   ` Dinakar Guniguntala
2005-05-26 20:07   ` Paul Jackson
2005-05-27  0:24     ` Paul Jackson
2005-05-26 23:40   ` Paul Jackson
2005-05-27  8:07     ` Simon Derr
2005-05-27  8:44       ` Paul Jackson

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=Pine.LNX.4.58.0505260840470.2307@ppc970.osdl.org \
    --to=torvalds@osdl.org \
    --cc=Simon.Derr@bull.net \
    --cc=akpm@osdl.org \
    --cc=dino@in.ibm.com \
    --cc=holt@sgi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pj@sgi.com \
    /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®