Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756418AbbKRQsf (ORCPT ); Wed, 18 Nov 2015 11:48:35 -0500 Received: from mail-wm0-f52.google.com ([74.125.82.52]:38345 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751832AbbKRQse (ORCPT ); Wed, 18 Nov 2015 11:48:34 -0500 From: Nicolai Stange To: Greg Kroah-Hartman Cc: Nicolai Stange , "Theodore Ts'o" , Andreas Dilger , Mark Fasheh , Joel Becker , Andrew Morton , Joe Perches , linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, ocfs2-devel@oss.oracle.com Subject: [PATCH v2 2/3] drivers/base/class: __class_register(): make error behaviour consistent References: <871tbpebjw.fsf@gmail.com> <20151117041213.GA10860@kroah.com> <87k2pfcl73.fsf_-_@gmail.com> Date: Wed, 18 Nov 2015 17:48:31 +0100 In-Reply-To: <87k2pfcl73.fsf_-_@gmail.com> (Nicolai Stange's message of "Wed, 18 Nov 2015 17:43:28 +0100") Message-ID: <878u5vckyo.fsf_-_@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1446 Lines: 45 If a class attribute's sysfs creation fails at the very end of __class_register(), the kset object already registered for the class itself is not unregistered again. This is not consistent with the other possible failures of __class_register() for which nothing is left over to be manually released by the caller. Since class attribute creation does not fail in the real world, the impact is minimal -- this patch is a cosmetic one. Make __class_register() follow all-or-nothing semantics, i.e. unregister the already registered cp->subsys kset object on attribute creation failure. Signed-off-by: Nicolai Stange --- drivers/base/class.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/base/class.c b/drivers/base/class.c index c9683cf..fc663d0 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -225,6 +225,12 @@ int __class_register(struct class *cls, struct lock_class_key *key) } error = add_class_attrs(class_get(cls)); class_put(cls); + if (error) { + /* as above, clear cp->class on error */ + cp->class = NULL; + cls->p = NULL; + kset_put(&cp->subsys); + } return error; } EXPORT_SYMBOL_GPL(__class_register); -- 2.6.3 -- 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/