提交 8fbaa51d 编写于 作者: A Andrew Donnellan 提交者: Michael Ellerman

cxl: fix potential NULL dereference in free_adapter()

If kzalloc() fails when allocating adapter->guest in
cxl_guest_init_adapter(), we call free_adapter() before erroring out.
free_adapter() in turn attempts to dereference adapter->guest, which in
this case is NULL.

In free_adapter(), skip the adapter->guest cleanup if adapter->guest is
NULL.

Fixes: 14baf4d9 ("cxl: Add guest-specific code")
Reported-by: NDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: NAndrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: NMichael Ellerman <mpe@ellerman.id.au>
上级 1e44727a
...@@ -1055,6 +1055,7 @@ static void free_adapter(struct cxl *adapter) ...@@ -1055,6 +1055,7 @@ static void free_adapter(struct cxl *adapter)
struct irq_avail *cur; struct irq_avail *cur;
int i; int i;
if (adapter->guest) {
if (adapter->guest->irq_avail) { if (adapter->guest->irq_avail) {
for (i = 0; i < adapter->guest->irq_nranges; i++) { for (i = 0; i < adapter->guest->irq_nranges; i++) {
cur = &adapter->guest->irq_avail[i]; cur = &adapter->guest->irq_avail[i];
...@@ -1063,8 +1064,9 @@ static void free_adapter(struct cxl *adapter) ...@@ -1063,8 +1064,9 @@ static void free_adapter(struct cxl *adapter)
kfree(adapter->guest->irq_avail); kfree(adapter->guest->irq_avail);
} }
kfree(adapter->guest->status); kfree(adapter->guest->status);
cxl_remove_adapter_nr(adapter);
kfree(adapter->guest); kfree(adapter->guest);
}
cxl_remove_adapter_nr(adapter);
kfree(adapter); kfree(adapter);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册