diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2021-08-16 14:13:33 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2021-08-16 15:40:18 +0300 |
commit | 4f3f2e3fa0431b93745b110da1c365806c5acce3 (patch) | |
tree | f84c05994cc19d332c972a1779841cc4036742ff /drivers | |
parent | 517c54d282392a2c7dedc80783886d2cd1836c0d (diff) | |
download | linux-4f3f2e3fa0431b93745b110da1c365806c5acce3.tar.xz |
net: iosm: Prevent underflow in ipc_chnl_cfg_get()
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c b/drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c index 804e6c4f2c78..519361ec40df 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c +++ b/drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c @@ -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; } |