Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1384769 > unrolled thread
| Started by | changbin.du@intel.com |
|---|---|
| First post | 2016-04-22 10:20 +0200 |
| Last post | 2016-04-22 11:20 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 1/7] debugobjects: make fixup functions return bool instead of int changbin.du@intel.com - 2016-04-22 10:20 +0200
Re: [PATCH 1/7] debugobjects: make fixup functions return bool instead of int Thomas Gleixner <tglx@linutronix.de> - 2016-04-22 10:40 +0200
RE: [PATCH 1/7] debugobjects: make fixup functions return bool instead of int "Du, Changbin" <changbin.du@intel.com> - 2016-04-22 11:00 +0200
RE: [PATCH 1/7] debugobjects: make fixup functions return bool instead of int Thomas Gleixner <tglx@linutronix.de> - 2016-04-22 11:20 +0200
| From | changbin.du@intel.com |
|---|---|
| Date | 2016-04-22 10:20 +0200 |
| Subject | [PATCH 1/7] debugobjects: make fixup functions return bool instead of int |
| Message-ID | <rqEtI-7kx-3@gated-at.bofh.it> |
From: "Du, Changbin" <changbin.du@intel.com>
The object debugging infrastructure core provides some fixup callbacks
for the subsystem who use it. These callbacks are called from the debug
code whenever a problem in debug_object_init is detected. And
debugobjects core suppose them returns 1 when the fixup was successful,
otherwise 0. So the return type is boolean.
A bad thing is that debug_object_fixup use the return value for
arithmetic operation. It confused me that what is the reall return
type.
Reading over the whole code, I found some place do use the return value
incorrectly(see next patch). So why use bool type instead?
Signed-off-by: Du, Changbin <changbin.du@intel.com>
---
include/linux/debugobjects.h | 15 ++++++++-------
lib/debugobjects.c | 43 +++++++++++++++++++++----------------------
2 files changed, 29 insertions(+), 29 deletions(-)
diff --git a/include/linux/debugobjects.h b/include/linux/debugobjects.h
index 98ffcbd..a899f10 100644
--- a/include/linux/debugobjects.h
+++ b/include/linux/debugobjects.h
@@ -39,7 +39,8 @@ struct debug_obj {
* @debug_hint: function returning address, which have associated
* kernel symbol, to allow identify the object
* @fixup_init: fixup function, which is called when the init check
- * fails
+ * fails. All fixup functions must return true if fixup
+ * was successful, otherwise return false
* @fixup_activate: fixup function, which is called when the activate check
* fails
* @fixup_destroy: fixup function, which is called when the destroy check
@@ -51,12 +52,12 @@ struct debug_obj {
*/
struct debug_obj_descr {
const char *name;
- void *(*debug_hint) (void *addr);
- int (*fixup_init) (void *addr, enum debug_obj_state state);
- int (*fixup_activate) (void *addr, enum debug_obj_state state);
- int (*fixup_destroy) (void *addr, enum debug_obj_state state);
- int (*fixup_free) (void *addr, enum debug_obj_state state);
- int (*fixup_assert_init)(void *addr, enum debug_obj_state state);
+ void *(*debug_hint)(void *addr);
+ bool (*fixup_init)(void *addr, enum debug_obj_state state);
+ bool (*fixup_activate)(void *addr, enum debug_obj_state state);
+ bool (*fixup_destroy)(void *addr, enum debug_obj_state state);
+ bool (*fixup_free)(void *addr, enum debug_obj_state state);
+ bool (*fixup_assert_init)(void *addr, enum debug_obj_state state);
};
#ifdef CONFIG_DEBUG_OBJECTS
diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index 519b5a1..a9cee16 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -269,16 +269,15 @@ static void debug_print_object(struct debug_obj *obj, char *msg)
* Try to repair the damage, so we have a better chance to get useful
* debug output.
*/
-static int
-debug_object_fixup(int (*fixup)(void *addr, enum debug_obj_state state),
+static bool
+debug_object_fixup(bool (*fixup)(void *addr, enum debug_obj_state state),
void * addr, enum debug_obj_state state)
{
- int fixed = 0;
-
- if (fixup)
- fixed = fixup(addr, state);
- debug_objects_fixups += fixed;
- return fixed;
+ if (fixup && fixup(addr, state)) {
+ debug_objects_fixups++;
+ return true;
+ }
+ return false;
}
static void debug_object_is_on_stack(void *addr, int onstack)
@@ -797,7 +796,7 @@ static __initdata struct debug_obj_descr descr_type_test;
* fixup_init is called when:
* - an active object is initialized
*/
-static int __init fixup_init(void *addr, enum debug_obj_state state)
+static bool __init fixup_init(void *addr, enum debug_obj_state state)
{
struct self_test *obj = addr;
@@ -805,9 +804,9 @@ static int __init fixup_init(void *addr, enum debug_obj_state state)
case ODEBUG_STATE_ACTIVE:
debug_object_deactivate(obj, &descr_type_test);
debug_object_init(obj, &descr_type_test);
- return 1;
+ return true;
default:
- return 0;
+ return false;
}
}
@@ -816,7 +815,7 @@ static int __init fixup_init(void *addr, enum debug_obj_state state)
* - an active object is activated
* - an unknown object is activated (might be a statically initialized object)
*/
-static int __init fixup_activate(void *addr, enum debug_obj_state state)
+static bool __init fixup_activate(void *addr, enum debug_obj_state state)
{
struct self_test *obj = addr;
@@ -825,17 +824,17 @@ static int __init fixup_activate(void *addr, enum debug_obj_state state)
if (obj->static_init == 1) {
debug_object_init(obj, &descr_type_test);
debug_object_activate(obj, &descr_type_test);
- return 0;
+ return false;
}
- return 1;
+ return true;
case ODEBUG_STATE_ACTIVE:
debug_object_deactivate(obj, &descr_type_test);
debug_object_activate(obj, &descr_type_test);
- return 1;
+ return true;
default:
- return 0;
+ return false;
}
}
@@ -843,7 +842,7 @@ static int __init fixup_activate(void *addr, enum debug_obj_state state)
* fixup_destroy is called when:
* - an active object is destroyed
*/
-static int __init fixup_destroy(void *addr, enum debug_obj_state state)
+static bool __init fixup_destroy(void *addr, enum debug_obj_state state)
{
struct self_test *obj = addr;
@@ -851,9 +850,9 @@ static int __init fixup_destroy(void *addr, enum debug_obj_state state)
case ODEBUG_STATE_ACTIVE:
debug_object_deactivate(obj, &descr_type_test);
debug_object_destroy(obj, &descr_type_test);
- return 1;
+ return true;
default:
- return 0;
+ return false;
}
}
@@ -861,7 +860,7 @@ static int __init fixup_destroy(void *addr, enum debug_obj_state state)
* fixup_free is called when:
* - an active object is freed
*/
-static int __init fixup_free(void *addr, enum debug_obj_state state)
+static bool __init fixup_free(void *addr, enum debug_obj_state state)
{
struct self_test *obj = addr;
@@ -869,9 +868,9 @@ static int __init fixup_free(void *addr, enum debug_obj_state state)
case ODEBUG_STATE_ACTIVE:
debug_object_deactivate(obj, &descr_type_test);
debug_object_free(obj, &descr_type_test);
- return 1;
+ return true;
default:
- return 0;
+ return false;
}
}
--
2.7.4
[toc] | [next] | [standalone]
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2016-04-22 10:40 +0200 |
| Subject | Re: [PATCH 1/7] debugobjects: make fixup functions return bool instead of int |
| Message-ID | <rqEN4-7vo-19@gated-at.bofh.it> |
| In reply to | #1384769 |
On Fri, 22 Apr 2016, changbin.du@intel.com wrote: > From: "Du, Changbin" <changbin.du@intel.com> > > The object debugging infrastructure core provides some fixup callbacks > for the subsystem who use it. These callbacks are called from the debug > code whenever a problem in debug_object_init is detected. And > debugobjects core suppose them returns 1 when the fixup was successful, > otherwise 0. So the return type is boolean. > > A bad thing is that debug_object_fixup use the return value for > arithmetic operation. It confused me that what is the reall return What's bad about that? The fact that it's used for arithmethic operation or that it confused you? > Reading over the whole code, I found some place do use the return value > incorrectly(see next patch). So why use bool type instead? Patches which fix a problem need to come first not in the middle of a revamp series. > + bool (*fixup_init)(void *addr, enum debug_obj_state state); > + bool (*fixup_activate)(void *addr, enum debug_obj_state state); > + bool (*fixup_destroy)(void *addr, enum debug_obj_state state); > + bool (*fixup_free)(void *addr, enum debug_obj_state state); > + bool (*fixup_assert_init)(void *addr, enum debug_obj_state state); So this change will introduce a gazillion of compile warnings because the callbacks in the various usage sites are still having 'int' return type. Thanks, tglx
[toc] | [prev] | [next] | [standalone]
| From | "Du, Changbin" <changbin.du@intel.com> |
|---|---|
| Date | 2016-04-22 11:00 +0200 |
| Subject | RE: [PATCH 1/7] debugobjects: make fixup functions return bool instead of int |
| Message-ID | <rqF6p-7D6-7@gated-at.bofh.it> |
| In reply to | #1384790 |
Hi, > On Fri, 22 Apr 2016, changbin.du@intel.com wrote: > > From: "Du, Changbin" <changbin.du@intel.com> > > > > The object debugging infrastructure core provides some fixup callbacks > > for the subsystem who use it. These callbacks are called from the debug > > code whenever a problem in debug_object_init is detected. And > > debugobjects core suppose them returns 1 when the fixup was successful, > > otherwise 0. So the return type is boolean. > > > > A bad thing is that debug_object_fixup use the return value for > > arithmetic operation. It confused me that what is the reall return > > What's bad about that? The fact that it's used for arithmethic operation or > that it confused you? > It confused me because this is not a common usage. I was confused that what does he fixup function return? A countable value? But doc says return fixed or not! if (fixup) fixed = fixup(addr, state); debug_objects_fixups += fixed; In common,for int return 0 indicates success, negative for fail, positive for something countable. So I think it is better follow this rule. Here is not of countable, it is Boolean. So why not this? if (fixup && fixup(addr, state)) debug_objects_fixups++; > > Reading over the whole code, I found some place do use the return value > > incorrectly(see next patch). So why use bool type instead? > > Patches which fix a problem need to come first not in the middle of a revamp > series. > Thanks, I am first know of this. > > + bool (*fixup_init)(void *addr, enum debug_obj_state state); > > + bool (*fixup_activate)(void *addr, enum debug_obj_state state); > > + bool (*fixup_destroy)(void *addr, enum debug_obj_state state); > > + bool (*fixup_free)(void *addr, enum debug_obj_state state); > > + bool (*fixup_assert_init)(void *addr, enum debug_obj_state state); > > So this change will introduce a gazillion of compile warnings because the > callbacks in the various usage sites are still having 'int' return type. > No, I modified all the code who use debugojects API. > Thanks, > > tglx Thanks, Du, Changbin
[toc] | [prev] | [next] | [standalone]
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2016-04-22 11:20 +0200 |
| Subject | RE: [PATCH 1/7] debugobjects: make fixup functions return bool instead of int |
| Message-ID | <rqFpL-846-9@gated-at.bofh.it> |
| In reply to | #1384802 |
On Fri, 22 Apr 2016, Du, Changbin wrote: > > On Fri, 22 Apr 2016, changbin.du@intel.com wrote: > > > A bad thing is that debug_object_fixup use the return value for > > > arithmetic operation. It confused me that what is the reall return > > > > What's bad about that? The fact that it's used for arithmethic operation or > > that it confused you? > > > It confused me because this is not a common usage. I was confused that what > does he fixup function return? A countable value? But doc says return fixed > or not! It says return 0 for not fixed up and 1 for fixed up. The activate fixup is special and it has been written this way to handle the static initialization case. > if (fixup) > fixed = fixup(addr, state); > debug_objects_fixups += fixed; > In common,for int return 0 indicates success, negative for fail, positive > for something countable. So I think it is better follow this rule. Here is > not of countable, it is Boolean. Yes, it's common for most of the code. This code has been deliberately been written differently. I'm not opposed to change that and improve it, but just slapping bool on it does not really make any difference. > So why not this? > if (fixup && fixup(addr, state)) > debug_objects_fixups++; There is no problem with that per se. > > > + bool (*fixup_init)(void *addr, enum debug_obj_state state); > > > + bool (*fixup_activate)(void *addr, enum debug_obj_state state); > > > + bool (*fixup_destroy)(void *addr, enum debug_obj_state state); > > > + bool (*fixup_free)(void *addr, enum debug_obj_state state); > > > + bool (*fixup_assert_init)(void *addr, enum debug_obj_state state); > > > > So this change will introduce a gazillion of compile warnings because the > > callbacks in the various usage sites are still having 'int' return type. > > > No, I modified all the code who use debugojects API. You do that in the later patches. But patches must be compilable and functional on their own. Compiling this one will emit a gazillion of "initialization from incompatible pointer type" warnings. Thanks, tglx
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web