Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Xiaoke Wang and committed by
Mika Westerberg
3cc1c6de fea783e6

+6 -1
+6 -1
drivers/thunderbolt/icm.c
··· 1741 1741 if (!n) 1742 1742 return; 1743 1743 1744 - INIT_WORK(&n->work, icm_handle_notification); 1745 1744 n->pkg = kmemdup(buf, size, GFP_KERNEL); 1745 + if (!n->pkg) { 1746 + kfree(n); 1747 + return; 1748 + } 1749 + 1750 + INIT_WORK(&n->work, icm_handle_notification); 1746 1751 n->tb = tb; 1747 1752 1748 1753 queue_work(tb->wq, &n->work);