Skip to content

Commit

Permalink
staging: wfx: increase robustness of hif_generic_confirm()
Browse files Browse the repository at this point in the history
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 <dan.carpenter@oracle.com>
Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Link: https://lore.kernel.org/r/20201009171307.864608-6-Jerome.Pouiller@silabs.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jérôme Pouiller authored and Greg Kroah-Hartman committed Oct 10, 2020
1 parent b3c669b commit 5f841fe
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/staging/wfx/hif_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ static int hif_generic_confirm(struct wfx_dev *wdev,
}

if (wdev->hif_cmd.buf_recv) {
if (wdev->hif_cmd.len_recv >= len)
if (wdev->hif_cmd.len_recv >= len && len > 0)
memcpy(wdev->hif_cmd.buf_recv, buf, len);
else
status = -ENOMEM;
status = -EIO;
}
wdev->hif_cmd.ret = status;

Expand Down

0 comments on commit 5f841fe

Please sign in to comment.