lkml.org 
[lkml]   [2015]   [Nov]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 2/3] drivers/base/class: __class_register(): make error behaviour consistent
Date
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


\
 
 \ /
  Last update: 2015-11-18 18:01    [W:0.074 / U:0.288 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site