swiotlb: fix use after free on error handling path
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 15 Jul 2022 08:19:50 +0000 (11:19 +0300)
committerChristoph Hellwig <hch@lst.de>
Mon, 18 Jul 2022 04:48:46 +0000 (06:48 +0200)
Don't dereference "mem" after it has been freed.  Flip the
two kfree()s around to address this bug.

Fixes: 26ffb91fa5e0 ("swiotlb: split up the global swiotlb lock")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
kernel/dma/swiotlb.c

index dcf1459..c50e6fe 100644 (file)
@@ -979,8 +979,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
                mem->areas = kcalloc(nareas, sizeof(*mem->areas),
                                GFP_KERNEL);
                if (!mem->areas) {
-                       kfree(mem);
                        kfree(mem->slots);
+                       kfree(mem);
                        return -ENOMEM;
                }