Luis R. Rodriguez e2d9442dfe lib/test_kmod.c: fix limit check on number of test devices created
[ Upstream commit ac68b1b3b9c73e652dc7ce0585672e23c5a2dca4 ]

As reported by Dan the parentheses is in the wrong place, and since
unlikely() call returns either 0 or 1 it's never less than zero.  The
second issue is that signed integer overflows like "INT_MAX + 1" are
undefined behavior.

Since num_test_devs represents the number of devices, we want to stop
prior to hitting the max, and not rely on the wrap arround at all.  So
just cap at num_test_devs + 1, prior to assigning a new device.

Link: http://lkml.kernel.org/r/20180224030046.24238-1-mcgrof@kernel.org
Fixes: d9c6a72d6fa2 ("kmod: add test driver to stress test the module loader")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-05-30 07:52:14 +02:00
..
2018-03-03 10:24:29 +01:00
2017-08-15 09:02:08 -07:00
2015-11-23 09:44:58 +01:00
2017-06-09 11:52:07 +02:00
2017-02-24 17:46:57 -08:00
2017-05-09 15:40:28 -07:00
2017-02-24 17:46:57 -08:00
2017-10-03 17:54:25 -07:00
2018-02-22 15:42:24 +01:00
2018-02-16 20:23:04 +01:00
2016-12-06 10:17:03 +02:00
2017-07-07 10:37:54 -07:00
2017-08-15 09:02:07 -07:00