Skip to contentSkip to conversation

lib/kobject: simplify the kobject_init function

PATCH In review Dong Hao 3 participants 9 messages Mar 19, 2013

Subsystems (2)
lore
Share & tools
lore

Dong Hao

author
#0 lore raw

PATCH 1/3 lib/kobject: simplify the kobject_init function

From: Dong Hao <[email protected]>

The printk() function at the end of function kobject_init() already had '\n', so remove the duplicated one.

---
 lib/kobject.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kobject.c +1 -1
index e07ee1f..279a172 100644
@@ -274,7 +274,7 @@ void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
 		goto error;
 	}
 	if (!ktype) {
-		err_str = "must have a ktype to be initialized properly!\n";
+		err_str = "must have a ktype to be initialized properly!";
 		goto error;
 	}
 	if (kobj->state_initialized) {
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 2/3 lib/kobject: Panic when kobj or ktype is not properly assigned

From: Dong Hao <[email protected]>

kobj and ktype are two important attributes which will be used after kobject_init(), and (!kobj)|(!ktype) may cause FS corruption which could not be recovered. Panic instead of dump_stack() when neither kobj nor ktype is properly assigned to detect the bug early.

---
 lib/kobject.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kobject.c +1 -1
index 279a172..ff9b3c3 100644
@@ -290,7 +290,7 @@ void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
 
 error:
 	printk(KERN_ERR "kobject (%p): %s\n", kobj, err_str);
-	dump_stack();
+	BUG_ON(1);
 }
 EXPORT_SYMBOL(kobject_init);
 
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH 2/3] lib/kobject: Panic when kobj or ktype is not properly assigned

Quoted 5 lines · Dong Hao

From: Dong Hao <[email protected]>

kobj and ktype are two important attributes which will be used after kobject_init(),

and (!kobj)|(!ktype) may cause FS corruption which could not be recovered.

delete this line, i am not very convinced about corruption ...

Quoted 21 lines

Panic instead of dump_stack() when neither kobj nor ktype is properly assigned to detect the bug early.

---
 lib/kobject.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kobject.c +1 -1
index 279a172..ff9b3c3 100644
@@ -290,7 +290,7 @@ void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
 
 error:
 	printk(KERN_ERR "kobject (%p): %s\n", kobj, err_str);
-	dump_stack();
+	BUG_ON(1);
 }
 EXPORT_SYMBOL(kobject_init);
 
maintainer
#3 lore raw

Re: [PATCH 2/3] lib/kobject: Panic when kobj or ktype is not properly assigned

In reply to Dong Hao
Quoted 17 lines · Dong Hao

From: Dong Hao <[email protected]>

kobj and ktype are two important attributes which will be used after kobject_init(), and (!kobj)|(!ktype) may cause FS corruption which could not be recovered. Panic instead of dump_stack() when neither kobj nor ktype is properly assigned to detect the bug early.

---
 lib/kobject.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kobject.c +0 -0
index 279a172..ff9b3c3 100644

lib/kobject.c void kobject_init(struct kobject *kobj, struct kobj_type *ktype) · line 293

Quoted 5 lines
lib/kobject.c +1 -1
@@ -290,7 +290,7 @@ void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
 
 error:
 	printk(KERN_ERR "kobject (%p): %s\n", kobj, err_str);
-	dump_stack();
+	BUG_ON(1);

You just crashed the machine. That's horrible, and unacceptable.

*plonk*

author
#4 lore raw

PATCH 3/3 lib/kobject: WARN_ON corresponds to BUG_ON

In reply to Dong Hao

From: Dong Hao <[email protected]>

WARN_ON corresponds to BUG_ON and also gets more info.

---
 lib/kobject.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kobject.c +1 -1
index ff9b3c3..f7d9f31 100644
@@ -281,7 +281,7 @@ void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
 		/* do not error out as sometimes we can recover */
 		printk(KERN_ERR "kobject (%p): tried to init an initialized "
 		       "object, something is seriously wrong.\n", kobj);
-		dump_stack();
+		WARN_ON(1);
 	}
 
 	kobject_init_internal(kobj);
Signature · 1 line
1.7.9.5
#5 lore raw

Re: [PATCH 3/3] lib/kobject: WARN_ON corresponds to BUG_ON

Quoted 3 lines · Dong Hao

From: Dong Hao <[email protected]>

WARN_ON corresponds to BUG_ON and also gets more info.

Change the log like this:
like the comments said, double initialize a kobj is wrong but can be recoverd, using WARN_ON to warn the developer also it can get more info.

(Or you refine the code by yourself.)

Quoted 20 lines
---
 lib/kobject.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kobject.c +1 -1
index ff9b3c3..f7d9f31 100644
@@ -281,7 +281,7 @@ void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
 		/* do not error out as sometimes we can recover */
 		printk(KERN_ERR "kobject (%p): tried to init an initialized "
 		       "object, something is seriously wrong.\n", kobj);
-		dump_stack();
+		WARN_ON(1);
 	}
 
 	kobject_init_internal(kobj);
#6 lore raw

Re: [PATCH 3/3] lib/kobject: WARN_ON corresponds to BUG_ON

Quoted 11 lines · Xiao Guangrong
Quoted 3 lines · Dong Hao

From: Dong Hao <[email protected]>

WARN_ON corresponds to BUG_ON and also gets more info.

Change the log like this:
like the comments said, double initialize a kobj is wrong but can be recoverd, using WARN_ON to warn the developer also it can get more info.

(Or you refine the code by yourself.)

s/code/comment

Quoted 22 lines
Quoted 21 lines
---
 lib/kobject.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kobject.c +1 -1
index ff9b3c3..f7d9f31 100644
@@ -281,7 +281,7 @@ void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
 		/* do not error out as sometimes we can recover */
 		printk(KERN_ERR "kobject (%p): tried to init an initialized "
 		       "object, something is seriously wrong.\n", kobj);
-		dump_stack();
+		WARN_ON(1);
 	}
 
 	kobject_init_internal(kobj);
maintainer
#7 lore raw

Re: [PATCH 3/3] lib/kobject: WARN_ON corresponds to BUG_ON

In reply to Dong Hao
Quoted 3 lines · Dong Hao

From: Dong Hao <[email protected]>

WARN_ON corresponds to BUG_ON and also gets more info.

Huh? No.

Please stop, don't resend these.

greg k-h

maintainer
#8 lore raw
In reply to Dong Hao
Quoted 4 lines · Dong Hao

From: Dong Hao <[email protected]>

The printk() function at the end of function kobject_init() already had '\n', so remove the duplicated one.

Your subject doesn't match this description.