Skip to contentSkip to conversation

rpmsg: char: fix resource leak on kbuf on copy_from_iter_full failure

PATCH New Colin King 1 participant 1 message Oct 8, 2019

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 rpmsg: char: fix resource leak on kbuf on copy_from_iter_full failure

From: Colin Ian King <[email protected]>

Currently when copy_from_iter_full fails the kbuf is not free'd on the error return path. Fix this by setting the error return code and exiting via the free_kbuf path.

Addresses-Coverity: ("Resource leak")

Fixes ccf45b18ce89 ("rpmsg: char: Migrate to iter versions of read and write")
---
 drivers/rpmsg/rpmsg_char.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/rpmsg/rpmsg_char.c +4 -2
index 507bfe163883..7db28643db43 100644
@@ -227,8 +227,10 @@ static ssize_t rpmsg_eptdev_write_iter(struct kiocb *iocb,
 	if (!kbuf)
 		return -ENOMEM;
 
-	if (!copy_from_iter_full(kbuf, len, from))
-		return -EFAULT;
+	if (!copy_from_iter_full(kbuf, len, from)) {
+		ret = -EFAULT;
+		goto free_kbuf;
+	}
 
 	if (mutex_lock_interruptible(&eptdev->ept_lock)) {
 		ret = -ERESTARTSYS;
Signature · 1 line
2.20.1