From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964853AbXCSVQG (ORCPT ); Mon, 19 Mar 2007 17:16:06 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S964852AbXCSVQG (ORCPT ); Mon, 19 Mar 2007 17:16:06 -0400 Received: from netops-testserver-3-out.sgi.com ([192.48.171.28]:51329 "EHLO netops-testserver-3.corp.sgi.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S964917AbXCSVQE (ORCPT ); Mon, 19 Mar 2007 17:16:04 -0400 Date: Mon, 19 Mar 2007 14:16:01 -0700 (PDT) From: Christoph Lameter X-X-Sender: clameter@schroedinger.engr.sgi.com To: Matt Mackall cc: Pekka J Enberg , akpm@linux-foundation.org, ast@domdv.de, linux-kernel@vger.kernel.org Subject: Re: [PATCH] slab: deal with NULL pointers passed to kmem_cache_free In-Reply-To: <20070319204945.GJ10459@waste.org> Message-ID: References: <20070319204945.GJ10459@waste.org> 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 On Mon, 19 Mar 2007, Matt Mackall wrote: > I think this sort of thing should work: > > a = kmalloc(...) > b = kmem_cache_alloc(..) > c = allocate_some_id(...) > if (!a || !b || !c) { > free_some_id(c) > kmem_cache_free(c) ^^^^ this requires the specification of a kmem_cache structure and the object must be allocated by that cache. > kfree(a); Here we dynamically determine the slab cache and do not verify even which slab it came from. So you can always use kfree if you do not care. kmem_cache_free verifies correctness.