Message ID | 162592897337.1158485.13933847832718343850.stgit@devnote2 (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | kprobes: treewide: Clean up kprobe code | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Not a local patch |
On Sat, 2021-07-10 at 23:56 +0900, Masami Hiramatsu wrote: > Use the 'bool' type instead of 'int' for the functions which > returns a boolean value, because this makes clear that those > functions don't return any error code. [] > diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h [] > @@ -104,25 +104,25 @@ struct kprobe { > #define KPROBE_FLAG_FTRACE 8 /* probe is using ftrace */ > > > /* Has this kprobe gone ? */ > -static inline int kprobe_gone(struct kprobe *p) > +static inline bool kprobe_gone(struct kprobe *p) > { > return p->flags & KPROBE_FLAG_GONE; > } This change would also allow the removal of the !! from: kernel/trace/trace_kprobe.c:104: return !!(kprobe_gone(&tk->rp.kp)); --- kernel/trace/trace_kprobe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index ea6178cb5e334..c6e0345a44e94 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -101,7 +101,7 @@ static nokprobe_inline unsigned long trace_kprobe_offset(struct trace_kprobe *tk static nokprobe_inline bool trace_kprobe_has_gone(struct trace_kprobe *tk) { - return !!(kprobe_gone(&tk->rp.kp)); + return kprobe_gone(&tk->rp.kp); } static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk,
On Sat, 10 Jul 2021 09:27:22 -0700 Joe Perches <joe@perches.com> wrote: > On Sat, 2021-07-10 at 23:56 +0900, Masami Hiramatsu wrote: > > Use the 'bool' type instead of 'int' for the functions which > > returns a boolean value, because this makes clear that those > > functions don't return any error code. > [] > > diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h > [] > > @@ -104,25 +104,25 @@ struct kprobe { > > #define KPROBE_FLAG_FTRACE 8 /* probe is using ftrace */ > > > > > > /* Has this kprobe gone ? */ > > -static inline int kprobe_gone(struct kprobe *p) > > +static inline bool kprobe_gone(struct kprobe *p) > > { > > return p->flags & KPROBE_FLAG_GONE; > > } > > This change would also allow the removal of the !! from: > > kernel/trace/trace_kprobe.c:104: return !!(kprobe_gone(&tk->rp.kp)); Good catch! OK, I'll update Thank you, > --- > kernel/trace/trace_kprobe.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c > index ea6178cb5e334..c6e0345a44e94 100644 > --- a/kernel/trace/trace_kprobe.c > +++ b/kernel/trace/trace_kprobe.c > @@ -101,7 +101,7 @@ static nokprobe_inline unsigned long trace_kprobe_offset(struct trace_kprobe *tk > > static nokprobe_inline bool trace_kprobe_has_gone(struct trace_kprobe *tk) > { > - return !!(kprobe_gone(&tk->rp.kp)); > + return kprobe_gone(&tk->rp.kp); > } > > static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk, > >
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h index bb6d1e72a943..7d0d21f2315a 100644 --- a/include/linux/kprobes.h +++ b/include/linux/kprobes.h @@ -104,25 +104,25 @@ struct kprobe { #define KPROBE_FLAG_FTRACE 8 /* probe is using ftrace */ /* Has this kprobe gone ? */ -static inline int kprobe_gone(struct kprobe *p) +static inline bool kprobe_gone(struct kprobe *p) { return p->flags & KPROBE_FLAG_GONE; } /* Is this kprobe disabled ? */ -static inline int kprobe_disabled(struct kprobe *p) +static inline bool kprobe_disabled(struct kprobe *p) { return p->flags & (KPROBE_FLAG_DISABLED | KPROBE_FLAG_GONE); } /* Is this kprobe really running optimized path ? */ -static inline int kprobe_optimized(struct kprobe *p) +static inline bool kprobe_optimized(struct kprobe *p) { return p->flags & KPROBE_FLAG_OPTIMIZED; } /* Is this kprobe uses ftrace ? */ -static inline int kprobe_ftrace(struct kprobe *p) +static inline bool kprobe_ftrace(struct kprobe *p) { return p->flags & KPROBE_FLAG_FTRACE; } diff --git a/kernel/kprobes.c b/kernel/kprobes.c index e30c639fe2cc..2029d7ceaa11 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -198,8 +198,8 @@ kprobe_opcode_t *__get_insn_slot(struct kprobe_insn_cache *c) return slot; } -/* Return 1 if all garbages are collected, otherwise 0. */ -static int collect_one_slot(struct kprobe_insn_page *kip, int idx) +/* Return true if all garbages are collected, otherwise false. */ +static bool collect_one_slot(struct kprobe_insn_page *kip, int idx) { kip->slot_used[idx] = SLOT_CLEAN; kip->nused--; @@ -223,9 +223,9 @@ static int collect_one_slot(struct kprobe_insn_page *kip, int idx) kip->cache->free(kip->insns); kfree(kip); } - return 1; + return true; } - return 0; + return false; } static int collect_garbage_slots(struct kprobe_insn_cache *c) @@ -389,13 +389,13 @@ NOKPROBE_SYMBOL(get_kprobe); static int aggr_pre_handler(struct kprobe *p, struct pt_regs *regs); /* Return true if 'p' is an aggregator */ -static inline int kprobe_aggrprobe(struct kprobe *p) +static inline bool kprobe_aggrprobe(struct kprobe *p) { return p->pre_handler == aggr_pre_handler; } /* Return true if 'p' is unused */ -static inline int kprobe_unused(struct kprobe *p) +static inline bool kprobe_unused(struct kprobe *p) { return kprobe_aggrprobe(p) && kprobe_disabled(p) && list_empty(&p->list); @@ -455,7 +455,7 @@ static inline int kprobe_optready(struct kprobe *p) } /* Return true if the kprobe is disarmed. Note: p must be on hash list */ -static inline int kprobe_disarmed(struct kprobe *p) +static inline bool kprobe_disarmed(struct kprobe *p) { struct optimized_kprobe *op; @@ -469,16 +469,16 @@ static inline int kprobe_disarmed(struct kprobe *p) } /* Return true if the probe is queued on (un)optimizing lists */ -static int kprobe_queued(struct kprobe *p) +static bool kprobe_queued(struct kprobe *p) { struct optimized_kprobe *op; if (kprobe_aggrprobe(p)) { op = container_of(p, struct optimized_kprobe, kp); if (!list_empty(&op->list)) - return 1; + return true; } - return 0; + return false; } /* @@ -1683,7 +1683,7 @@ int register_kprobe(struct kprobe *p) EXPORT_SYMBOL_GPL(register_kprobe); /* Check if all probes on the 'ap' are disabled. */ -static int aggr_kprobe_disabled(struct kprobe *ap) +static bool aggr_kprobe_disabled(struct kprobe *ap) { struct kprobe *kp; @@ -1695,9 +1695,9 @@ static int aggr_kprobe_disabled(struct kprobe *ap) * Since there is an active probe on the list, * we can't disable this 'ap'. */ - return 0; + return false; - return 1; + return true; } static struct kprobe *__disable_kprobe(struct kprobe *p)
Use the 'bool' type instead of 'int' for the functions which returns a boolean value, because this makes clear that those functions don't return any error code. Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> --- include/linux/kprobes.h | 8 ++++---- kernel/kprobes.c | 26 +++++++++++++------------- 2 files changed, 17 insertions(+), 17 deletions(-)