Skip to content

Commit 5f841fe

Browse files
jerome-pouillergregkh
authored andcommitted
staging: wfx: increase robustness of hif_generic_confirm()
Smatch complains: drivers/staging/wfx/hif_rx.c:26 hif_generic_confirm() warn: negative user subtract: 0-u16max - 4 20 static int hif_generic_confirm(struct wfx_dev *wdev, 21 const struct hif_msg *hif, const void *buf) 22 { 23 // All confirm messages start with status 24 int status = le32_to_cpup((__le32 *)buf); 25 int cmd = hif->id; 26 int len = le16_to_cpu(hif->len) - 4; // drop header ^^^^^ 27 28 WARN(!mutex_is_locked(&wdev->hif_cmd.lock), "data locking error"); In fact, rx_helper() already make the necessary checks on the value of hif->len. Never mind, add an explicit check to make Smatch happy. Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Jérôme Pouiller <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b3c669b commit 5f841fe

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/staging/wfx/hif_rx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ static int hif_generic_confirm(struct wfx_dev *wdev,
4040
}
4141

4242
if (wdev->hif_cmd.buf_recv) {
43-
if (wdev->hif_cmd.len_recv >= len)
43+
if (wdev->hif_cmd.len_recv >= len && len > 0)
4444
memcpy(wdev->hif_cmd.buf_recv, buf, len);
4545
else
46-
status = -ENOMEM;
46+
status = -EIO;
4747
}
4848
wdev->hif_cmd.ret = status;
4949

0 commit comments

Comments
 (0)