All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] trace: cleanup: make some types unsigned
@ 2011-10-07 13:27 ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2011-10-07 13:27 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Frederic Weisbecker, Ingo Molnar, linux-kernel, kernel-janitors

The problem here is that I'm trying to silence a static checker
warning.  In replace_preds() we cap n_preds at MAX_FILTER_PRED but
we don't check for negative values.  It can't actually be negative
values, but the static checkers get confused.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 256764e..7f4daff 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -790,7 +790,7 @@ static struct event_filter *__alloc_filter(void)
 	return filter;
 }
 
-static int __alloc_preds(struct event_filter *filter, int n_preds)
+static int __alloc_preds(struct event_filter *filter, unsigned int n_preds)
 {
 	struct filter_pred *pred;
 	int i;
@@ -1361,10 +1361,10 @@ static int check_preds(struct filter_parse_state *ps)
 	return 0;
 }
 
-static int count_preds(struct filter_parse_state *ps)
+static unsigned int count_preds(struct filter_parse_state *ps)
 {
 	struct postfix_elt *elt;
-	int n_preds = 0;
+	unsigned int n_preds = 0;
 
 	list_for_each_entry(elt, &ps->postfix, list) {
 		if (elt->op == OP_NONE)
@@ -1601,7 +1601,7 @@ static int replace_preds(struct ftrace_event_call *call,
 	struct postfix_elt *elt;
 	struct pred_stack stack = { }; /* init to NULL */
 	int err;
-	int n_preds = 0;
+	unsigned int n_preds = 0;
 
 	n_preds = count_preds(ps);
 	if (n_preds >= MAX_FILTER_PRED) {

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

* [patch] trace: cleanup: make some types unsigned
@ 2011-10-07 13:27 ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2011-10-07 13:27 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Frederic Weisbecker, Ingo Molnar, linux-kernel, kernel-janitors

The problem here is that I'm trying to silence a static checker
warning.  In replace_preds() we cap n_preds at MAX_FILTER_PRED but
we don't check for negative values.  It can't actually be negative
values, but the static checkers get confused.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 256764e..7f4daff 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -790,7 +790,7 @@ static struct event_filter *__alloc_filter(void)
 	return filter;
 }
 
-static int __alloc_preds(struct event_filter *filter, int n_preds)
+static int __alloc_preds(struct event_filter *filter, unsigned int n_preds)
 {
 	struct filter_pred *pred;
 	int i;
@@ -1361,10 +1361,10 @@ static int check_preds(struct filter_parse_state *ps)
 	return 0;
 }
 
-static int count_preds(struct filter_parse_state *ps)
+static unsigned int count_preds(struct filter_parse_state *ps)
 {
 	struct postfix_elt *elt;
-	int n_preds = 0;
+	unsigned int n_preds = 0;
 
 	list_for_each_entry(elt, &ps->postfix, list) {
 		if (elt->op = OP_NONE)
@@ -1601,7 +1601,7 @@ static int replace_preds(struct ftrace_event_call *call,
 	struct postfix_elt *elt;
 	struct pred_stack stack = { }; /* init to NULL */
 	int err;
-	int n_preds = 0;
+	unsigned int n_preds = 0;
 
 	n_preds = count_preds(ps);
 	if (n_preds >= MAX_FILTER_PRED) {

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

* Re: [patch] trace: cleanup: make some types unsigned
  2011-10-07 13:27 ` Dan Carpenter
@ 2011-10-07 13:38   ` Steven Rostedt
  -1 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2011-10-07 13:38 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Frederic Weisbecker, Ingo Molnar, linux-kernel, kernel-janitors

On Fri, 2011-10-07 at 16:27 +0300, Dan Carpenter wrote:
> The problem here is that I'm trying to silence a static checker
> warning.  In replace_preds() we cap n_preds at MAX_FILTER_PRED but
> we don't check for negative values.  It can't actually be negative
> values, but the static checkers get confused.

I really hate to uglify code for the sake of static checkers.

This code may change in the near future, and the possibility that
n_preds may become a possibility. Perhaps we should add a:

WARN_ON(n_preds < 0);

If in the future the count_preds() changes and incorrectly produces a
negative number, or perhaps even overflows int, we wont catch it with
unsigned.

-- Steve



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

* Re: [patch] trace: cleanup: make some types unsigned
@ 2011-10-07 13:38   ` Steven Rostedt
  0 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2011-10-07 13:38 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Frederic Weisbecker, Ingo Molnar, linux-kernel, kernel-janitors

On Fri, 2011-10-07 at 16:27 +0300, Dan Carpenter wrote:
> The problem here is that I'm trying to silence a static checker
> warning.  In replace_preds() we cap n_preds at MAX_FILTER_PRED but
> we don't check for negative values.  It can't actually be negative
> values, but the static checkers get confused.

I really hate to uglify code for the sake of static checkers.

This code may change in the near future, and the possibility that
n_preds may become a possibility. Perhaps we should add a:

WARN_ON(n_preds < 0);

If in the future the count_preds() changes and incorrectly produces a
negative number, or perhaps even overflows int, we wont catch it with
unsigned.

-- Steve



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

* Re: [patch] trace: cleanup: make some types unsigned
  2011-10-07 13:38   ` Steven Rostedt
@ 2011-10-07 20:20     ` Dan Carpenter
  -1 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2011-10-07 20:20 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Frederic Weisbecker, Ingo Molnar, linux-kernel, kernel-janitors

On Fri, Oct 07, 2011 at 09:38:51AM -0400, Steven Rostedt wrote:
> On Fri, 2011-10-07 at 16:27 +0300, Dan Carpenter wrote:
> > The problem here is that I'm trying to silence a static checker
> > warning.  In replace_preds() we cap n_preds at MAX_FILTER_PRED but
> > we don't check for negative values.  It can't actually be negative
> > values, but the static checkers get confused.
> 
> I really hate to uglify code for the sake of static checkers.
> 
> This code may change in the near future, and the possibility that
> n_preds may become a possibility. Perhaps we should add a:
> 
> WARN_ON(n_preds < 0);
> 
> If in the future the count_preds() changes and incorrectly produces a
> negative number, or perhaps even overflows int, we wont catch it with
> unsigned.

I've sent a couple type changes to silence static checker warnings,
but I haven't been pushing it, because I'm interested to see what
people think about them first.  I didn't think unsigned int was
particularly ugly, but now that you point it out I guess it is
needlessly pedantic and longer to type.  So it's fine if you ignore
the patch.

Please don't add the WARN_ON().  WARN_ON()s are uglier than unsigned
ints.  WARN_ON() don't solve any problems, they just make debugging
the crash easier.  Are we going to crash here, and if so, do we
expect that debugging it will be difficult?  Probably not.

In theory, static checkers should be able to look at this code and
know that n_preds can't overflow.  So yeah.  Let's call this a
static checker bug and move on.

regards,
dan carpenter

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

* Re: [patch] trace: cleanup: make some types unsigned
@ 2011-10-07 20:20     ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2011-10-07 20:20 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Frederic Weisbecker, Ingo Molnar, linux-kernel, kernel-janitors

On Fri, Oct 07, 2011 at 09:38:51AM -0400, Steven Rostedt wrote:
> On Fri, 2011-10-07 at 16:27 +0300, Dan Carpenter wrote:
> > The problem here is that I'm trying to silence a static checker
> > warning.  In replace_preds() we cap n_preds at MAX_FILTER_PRED but
> > we don't check for negative values.  It can't actually be negative
> > values, but the static checkers get confused.
> 
> I really hate to uglify code for the sake of static checkers.
> 
> This code may change in the near future, and the possibility that
> n_preds may become a possibility. Perhaps we should add a:
> 
> WARN_ON(n_preds < 0);
> 
> If in the future the count_preds() changes and incorrectly produces a
> negative number, or perhaps even overflows int, we wont catch it with
> unsigned.

I've sent a couple type changes to silence static checker warnings,
but I haven't been pushing it, because I'm interested to see what
people think about them first.  I didn't think unsigned int was
particularly ugly, but now that you point it out I guess it is
needlessly pedantic and longer to type.  So it's fine if you ignore
the patch.

Please don't add the WARN_ON().  WARN_ON()s are uglier than unsigned
ints.  WARN_ON() don't solve any problems, they just make debugging
the crash easier.  Are we going to crash here, and if so, do we
expect that debugging it will be difficult?  Probably not.

In theory, static checkers should be able to look at this code and
know that n_preds can't overflow.  So yeah.  Let's call this a
static checker bug and move on.

regards,
dan carpenter

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

end of thread, other threads:[~2011-10-07 20:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-07 13:27 [patch] trace: cleanup: make some types unsigned Dan Carpenter
2011-10-07 13:27 ` Dan Carpenter
2011-10-07 13:38 ` Steven Rostedt
2011-10-07 13:38   ` Steven Rostedt
2011-10-07 20:20   ` Dan Carpenter
2011-10-07 20:20     ` Dan Carpenter

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.