]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: iosm: Prevent underflow in ipc_chnl_cfg_get()
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 16 Aug 2021 11:13:33 +0000 (14:13 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 16 Aug 2021 12:40:18 +0000 (13:40 +0100)
The bounds check on "index" doesn't catch negative values.  Using
ARRAY_SIZE() directly is more readable and more robust because it prevents
negative values for "index".  Fortunately we only pass valid values to
ipc_chnl_cfg_get() so this patch does not affect runtime.

Reported-by: Solomon Ucko <solly.ucko@gmail.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: M Chetan Kumar <m.chetan.kumar@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c

index 804e6c4f2c782f3c9763e9f4089bce605001f738..519361ec40dfcb472b264b184eace3d4a48b4c33 100644 (file)
@@ -64,10 +64,9 @@ static struct ipc_chnl_cfg modem_cfg[] = {
 
 int ipc_chnl_cfg_get(struct ipc_chnl_cfg *chnl_cfg, int index)
 {
-       int array_size = ARRAY_SIZE(modem_cfg);
-
-       if (index >= array_size) {
-               pr_err("index: %d and array_size %d", index, array_size);
+       if (index >= ARRAY_SIZE(modem_cfg)) {
+               pr_err("index: %d and array size %zu", index,
+                      ARRAY_SIZE(modem_cfg));
                return -ECHRNG;
        }