diff options
author | Xiaoke Wang <xkernel.wang@foxmail.com> | 2021-12-13 09:27:15 +0100 |
---|---|---|
committer | Mika Westerberg <mika.westerberg@linux.intel.com> | 2021-12-15 11:39:08 +0100 |
commit | 3cc1c6de458e0e58c413c3c35802ca96e55bbdbe (patch) | |
tree | f5911457823a0343411ea07e9a804406ccb33bc2 | |
parent | thunderbolt: Do not dereference fwnode in struct device (diff) | |
download | linux-3cc1c6de458e0e58c413c3c35802ca96e55bbdbe.tar.xz linux-3cc1c6de458e0e58c413c3c35802ca96e55bbdbe.zip |
thunderbolt: Check return value of kmemdup() in icm_handle_event()
kmemdup() may return NULL if there is not enough memory available. Check
this and bail out early in this case. While there move INIT_WORK() to
happen after we have allocated all the memory needed for the event
handling to avoid doing unnecessary work.
Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
-rw-r--r-- | drivers/thunderbolt/icm.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c index 6255f1ef9599..fff0c740c8f3 100644 --- a/drivers/thunderbolt/icm.c +++ b/drivers/thunderbolt/icm.c @@ -1741,8 +1741,13 @@ static void icm_handle_event(struct tb *tb, enum tb_cfg_pkg_type type, if (!n) return; - INIT_WORK(&n->work, icm_handle_notification); n->pkg = kmemdup(buf, size, GFP_KERNEL); + if (!n->pkg) { + kfree(n); + return; + } + + INIT_WORK(&n->work, icm_handle_notification); n->tb = tb; queue_work(tb->wq, &n->work); |