Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934762AbXK3Ovm (ORCPT ); Fri, 30 Nov 2007 09:51:42 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753943AbXK3Ov3 (ORCPT ); Fri, 30 Nov 2007 09:51:29 -0500 Received: from iolanthe.rowland.org ([192.131.102.54]:36980 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751325AbXK3Ov2 (ORCPT ); Fri, 30 Nov 2007 09:51:28 -0500 Date: Fri, 30 Nov 2007 09:51:27 -0500 (EST) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Dave Young cc: Greg KH , Cornelia Huck , , Kay Sievers , Jonathan Corbet , Randy Dunlap Subject: Re: [RFC] Sample kset/ktype/kobject implementation In-Reply-To: Message-ID: 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: 1235 Lines: 33 On Fri, 30 Nov 2007, Dave Young wrote: > > The rule is simple enough. After calling kobject_register() you should > > always use kobject_put() -- even if kobject_register() failed. > > > > In fact, after calling kobject_init() you should use kobject_put(). > > The first rule follows from this one, since kobject_register() calls > > kobject_init() internally. > > > Hi, > The behavior is not very clear here, the root problem is that : > > 1. Should we call kobject_put so cleanup work can be done by refcount > touch zero or call kfree every time after kobject_register failed? Call kobject_put so that the cleanup work will be done when the refcount goes to 0. Don't call kfree. > 2. If kobject_put calling is true, should this be done in > kobject_register error handling codes or by hand after > kobject_register failed? It should be done by hand after kobject_register fails. Otherwise kobject_register would end up dropping a reference that it never acquired. Alan Stern - 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/