]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
thunderbolt: xdomain: Fix to check return value of kmemdup
authorAditya Pakki <pakki001@umn.edu>
Wed, 20 Mar 2019 16:47:20 +0000 (11:47 -0500)
committerMika Westerberg <mika.westerberg@linux.intel.com>
Fri, 22 Mar 2019 10:27:44 +0000 (13:27 +0300)
kmemdup can fail and return a NULL pointer. The patch modifies the
signature of tb_xdp_schedule_request and passes the failure error upstream.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
drivers/thunderbolt/xdomain.c

index e0642dcb8b9bda3a3e5e8d3f2d8bcf8bc97f432f..e2fc4543142d5c9037184db959545a088b3af3b3 100644 (file)
@@ -526,7 +526,7 @@ static void tb_xdp_handle_request(struct work_struct *work)
        kfree(xw);
 }
 
-static void
+static bool
 tb_xdp_schedule_request(struct tb *tb, const struct tb_xdp_header *hdr,
                        size_t size)
 {
@@ -534,13 +534,18 @@ tb_xdp_schedule_request(struct tb *tb, const struct tb_xdp_header *hdr,
 
        xw = kmalloc(sizeof(*xw), GFP_KERNEL);
        if (!xw)
-               return;
+               return false;
 
        INIT_WORK(&xw->work, tb_xdp_handle_request);
        xw->pkg = kmemdup(hdr, size, GFP_KERNEL);
+       if (!xw->pkg) {
+               kfree(xw);
+               return false;
+       }
        xw->tb = tb;
 
        queue_work(tb->wq, &xw->work);
+       return true;
 }
 
 /**
@@ -1422,10 +1427,8 @@ bool tb_xdomain_handle_request(struct tb *tb, enum tb_cfg_pkg_type type,
         * handlers in turn.
         */
        if (uuid_equal(&hdr->uuid, &tb_xdp_uuid)) {
-               if (type == TB_CFG_PKG_XDOMAIN_REQ) {
-                       tb_xdp_schedule_request(tb, hdr, size);
-                       return true;
-               }
+               if (type == TB_CFG_PKG_XDOMAIN_REQ)
+                       return tb_xdp_schedule_request(tb, hdr, size);
                return false;
        }