| From 2e39cf7b8f86c3be306985b9b0185f46f1b10b28 Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Thu, 9 Feb 2023 10:00:02 +0100 |
| Subject: um: virtio_uml: free command if adding to virtqueue failed |
| |
| From: Benjamin Berg <benjamin.berg@intel.com> |
| |
| [ Upstream commit 8a6ca543646f2940832665dbf4e04105262505e2 ] |
| |
| If adding the command fails (i.e. the virtqueue is broken) then free it |
| again if the function allocated a new buffer for it. |
| |
| Fixes: 68f5d3f3b654 ("um: add PCI over virtio emulation driver") |
| Signed-off-by: Benjamin Berg <benjamin.berg@intel.com> |
| Signed-off-by: Richard Weinberger <richard@nod.at> |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| arch/um/drivers/virt-pci.c | 5 ++++- |
| 1 file changed, 4 insertions(+), 1 deletion(-) |
| |
| diff --git a/arch/um/drivers/virt-pci.c b/arch/um/drivers/virt-pci.c |
| index 3ac220dafec4a..3b637ad75ec81 100644 |
| --- a/arch/um/drivers/virt-pci.c |
| +++ b/arch/um/drivers/virt-pci.c |
| @@ -132,8 +132,11 @@ static int um_pci_send_cmd(struct um_pci_device *dev, |
| out ? 1 : 0, |
| posted ? cmd : HANDLE_NO_FREE(cmd), |
| GFP_ATOMIC); |
| - if (ret) |
| + if (ret) { |
| + if (posted) |
| + kfree(cmd); |
| goto out; |
| + } |
| |
| if (posted) { |
| virtqueue_kick(dev->cmd_vq); |
| -- |
| 2.39.2 |
| |