Skip to content

Commit 4f3f2e3

Browse files
Dan Carpenterdavem330
authored andcommitted
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 <[email protected]> Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: M Chetan Kumar <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 517c54d commit 4f3f2e3

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ static struct ipc_chnl_cfg modem_cfg[] = {
6464

6565
int ipc_chnl_cfg_get(struct ipc_chnl_cfg *chnl_cfg, int index)
6666
{
67-
int array_size = ARRAY_SIZE(modem_cfg);
68-
69-
if (index >= array_size) {
70-
pr_err("index: %d and array_size %d", index, array_size);
67+
if (index >= ARRAY_SIZE(modem_cfg)) {
68+
pr_err("index: %d and array size %zu", index,
69+
ARRAY_SIZE(modem_cfg));
7170
return -ECHRNG;
7271
}
7372

0 commit comments

Comments
 (0)