public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nicolai Stange <nicstange@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Nicolai Stange <nicstange@gmail.com>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	Mark Fasheh <mfasheh@suse.com>, Joel Becker <jlbec@evilplan.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Joe Perches <joe@perches.com>,
	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
Date: Wed, 18 Nov 2015 17:48:31 +0100	[thread overview]
Message-ID: <878u5vckyo.fsf_-_@gmail.com> (raw)
In-Reply-To: <87k2pfcl73.fsf_-_@gmail.com> (Nicolai Stange's message of "Wed, 18 Nov 2015 17:43:28 +0100")

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 <nicstange@gmail.com>
---
 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


  parent reply	other threads:[~2015-11-18 16:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-17  0:04 [PATCH] lib/kobject: fix memory leak in error path of kset_create_and_add() Nicolai Stange
2015-11-17  4:12 ` Greg Kroah-Hartman
2015-11-17  8:09   ` Nicolai Stange
2015-11-17 11:29     ` Nicolai Stange
2015-11-18 16:43   ` [PATCH v2] kset- and class-registration cleanups Nicolai Stange
2015-11-18 16:46     ` [PATCH v2 1/3] lib/kobject: fix memory leak in error path of kset_create_and_add() Nicolai Stange
2015-11-18 16:48     ` Nicolai Stange [this message]
2015-11-18 16:50     ` [PATCH v2 3/3] drivers/base/class: __class_register(): invoke class' releaser on failure Nicolai Stange
2016-02-23 14:58     ` [PATCH v2] kset- and class-registration cleanups Nicolai Stange

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=878u5vckyo.fsf_-_@gmail.com \
    --to=nicstange@gmail.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jlbec@evilplan.org \
    --cc=joe@perches.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mfasheh@suse.com \
    --cc=ocfs2-devel@oss.oracle.com \
    --cc=tytso@mit.edu \
    /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