All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/kobject: Simplify checking of parameters in kobj_ns_type_register.
@ 2022-06-17  8:38 wuchi
  2022-06-17  8:49 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: wuchi @ 2022-06-17  8:38 UTC (permalink / raw)
  To: gregkh, rafael; +Cc: linux-kernel

1. Merge checking of following code:
    if (type >= KOBJ_NS_TYPES)
    ...
    if (type <= KOBJ_NS_TYPE_NONE)

2. Move the checking of parameters out of critical section, there is
no need to check that with spinlock.

Signed-off-by: wuchi <wuchi.zero@gmail.com>
---
 lib/kobject.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 5f0e71ab292c..6a8b009682b8 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -996,19 +996,13 @@ static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
 {
 	enum kobj_ns_type type = ops->type;
-	int error;
-
-	spin_lock(&kobj_ns_type_lock);
+	int error = -EBUSY;
 
-	error = -EINVAL;
-	if (type >= KOBJ_NS_TYPES)
-		goto out;
+	if (unlikely(type >= KOBJ_NS_TYPES || type <= KOBJ_NS_TYPE_NONE))
+		return -EINVAL;
 
-	error = -EINVAL;
-	if (type <= KOBJ_NS_TYPE_NONE)
-		goto out;
+	spin_lock(&kobj_ns_type_lock);
 
-	error = -EBUSY;
 	if (kobj_ns_ops_tbl[type])
 		goto out;
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-17  9:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-17  8:38 [PATCH] lib/kobject: Simplify checking of parameters in kobj_ns_type_register wuchi
2022-06-17  8:49 ` Greg KH
2022-06-17  9:55   ` chi wu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.