All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] misc: kgdbts: silence array underflow warning
@ 2018-05-17 12:22 ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2018-05-17 12:22 UTC (permalink / raw)
  To: Jason Wessel
  Cc: Daniel Thompson, Arnd Bergmann, Greg Kroah-Hartman,
	kgdb-bugreport, linux-kernel, kernel-janitors

Smatch distrusts simple_strtol().  I don't know the code well enough
to say if the distrust is justified here, but it seems harmless to
silence the warning.

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

diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
index 6193270e7b3d..e0508acaedaa 100644
--- a/drivers/misc/kgdbts.c
+++ b/drivers/misc/kgdbts.c
@@ -400,13 +400,15 @@ static void skip_back_repeat_test(char *arg)
 	int go_back = simple_strtol(arg, NULL, 10);
 
 	repeat_test--;
-	if (repeat_test <= 0) {
+	if (repeat_test <= 0 || go_back < 0) {
 		ts.idx++;
 	} else {
 		if (repeat_test % 100 == 0)
 			v1printk("kgdbts:RUN ... %d remaining\n", repeat_test);
 
 		ts.idx -= go_back;
+		if (ts.idx < 0)
+			ts.idx = 0;
 	}
 	fill_get_buf(ts.tst[ts.idx].get);
 }

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

* [PATCH] misc: kgdbts: silence array underflow warning
@ 2018-05-17 12:22 ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2018-05-17 12:22 UTC (permalink / raw)
  To: Jason Wessel
  Cc: Daniel Thompson, Arnd Bergmann, Greg Kroah-Hartman,
	kgdb-bugreport, linux-kernel, kernel-janitors

Smatch distrusts simple_strtol().  I don't know the code well enough
to say if the distrust is justified here, but it seems harmless to
silence the warning.

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

diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
index 6193270e7b3d..e0508acaedaa 100644
--- a/drivers/misc/kgdbts.c
+++ b/drivers/misc/kgdbts.c
@@ -400,13 +400,15 @@ static void skip_back_repeat_test(char *arg)
 	int go_back = simple_strtol(arg, NULL, 10);
 
 	repeat_test--;
-	if (repeat_test <= 0) {
+	if (repeat_test <= 0 || go_back < 0) {
 		ts.idx++;
 	} else {
 		if (repeat_test % 100 = 0)
 			v1printk("kgdbts:RUN ... %d remaining\n", repeat_test);
 
 		ts.idx -= go_back;
+		if (ts.idx < 0)
+			ts.idx = 0;
 	}
 	fill_get_buf(ts.tst[ts.idx].get);
 }

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

* Re: [PATCH] misc: kgdbts: silence array underflow warning
  2018-05-17 12:22 ` Dan Carpenter
@ 2018-05-17 13:31   ` Daniel Thompson
  -1 siblings, 0 replies; 4+ messages in thread
From: Daniel Thompson @ 2018-05-17 13:31 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jason Wessel, Arnd Bergmann, Greg Kroah-Hartman, kgdb-bugreport,
	linux-kernel, kernel-janitors

On Thu, May 17, 2018 at 03:22:29PM +0300, Dan Carpenter wrote:
> Smatch distrusts simple_strtol().  I don't know the code well enough
> to say if the distrust is justified here, but it seems harmless to
> silence the warning.

What warning does this fix? I'd prefer to have it in the description.


> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
> index 6193270e7b3d..e0508acaedaa 100644
> --- a/drivers/misc/kgdbts.c
> +++ b/drivers/misc/kgdbts.c
> @@ -400,13 +400,15 @@ static void skip_back_repeat_test(char *arg)
>  	int go_back = simple_strtol(arg, NULL, 10);

If go_back is out of range then this is a serious error in the test
plans found in the module. Something simple and clear such as
BUG_ON(go_back <= 0 || go_back > ts.idx) is probably sufficient.


>  	repeat_test--;
> -	if (repeat_test <= 0) {
> +	if (repeat_test <= 0 || go_back < 0) {

The BUG_ON() will mess things up because whatever breakpoints
the test is using are still enabled.

If you really want to recover cleanly then perhaps:

+	if (repeat_test <= 0 || WARN_ON(go_back < 0 || go_back > ts.idx)) {


>  		ts.idx++;
>  	} else {
>  		if (repeat_test % 100 == 0)
>  			v1printk("kgdbts:RUN ... %d remaining\n", repeat_test);
>  
>  		ts.idx -= go_back;
> +		if (ts.idx < 0)
> +			ts.idx = 0;

Not sure about this. If we know the opcodes are bad then re-executing
them doesn't seem like a good idea (hence covering it in the WARN_ON
branch above).


Daniel.

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

* Re: [PATCH] misc: kgdbts: silence array underflow warning
@ 2018-05-17 13:31   ` Daniel Thompson
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Thompson @ 2018-05-17 13:31 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jason Wessel, Arnd Bergmann, Greg Kroah-Hartman, kgdb-bugreport,
	linux-kernel, kernel-janitors

On Thu, May 17, 2018 at 03:22:29PM +0300, Dan Carpenter wrote:
> Smatch distrusts simple_strtol().  I don't know the code well enough
> to say if the distrust is justified here, but it seems harmless to
> silence the warning.

What warning does this fix? I'd prefer to have it in the description.


> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
> index 6193270e7b3d..e0508acaedaa 100644
> --- a/drivers/misc/kgdbts.c
> +++ b/drivers/misc/kgdbts.c
> @@ -400,13 +400,15 @@ static void skip_back_repeat_test(char *arg)
>  	int go_back = simple_strtol(arg, NULL, 10);

If go_back is out of range then this is a serious error in the test
plans found in the module. Something simple and clear such as
BUG_ON(go_back <= 0 || go_back > ts.idx) is probably sufficient.


>  	repeat_test--;
> -	if (repeat_test <= 0) {
> +	if (repeat_test <= 0 || go_back < 0) {

The BUG_ON() will mess things up because whatever breakpoints
the test is using are still enabled.

If you really want to recover cleanly then perhaps:

+	if (repeat_test <= 0 || WARN_ON(go_back < 0 || go_back > ts.idx)) {


>  		ts.idx++;
>  	} else {
>  		if (repeat_test % 100 = 0)
>  			v1printk("kgdbts:RUN ... %d remaining\n", repeat_test);
>  
>  		ts.idx -= go_back;
> +		if (ts.idx < 0)
> +			ts.idx = 0;

Not sure about this. If we know the opcodes are bad then re-executing
them doesn't seem like a good idea (hence covering it in the WARN_ON
branch above).


Daniel.

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

end of thread, other threads:[~2018-05-17 13:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-17 12:22 [PATCH] misc: kgdbts: silence array underflow warning Dan Carpenter
2018-05-17 12:22 ` Dan Carpenter
2018-05-17 13:31 ` Daniel Thompson
2018-05-17 13:31   ` Daniel Thompson

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.