[PATCH v5 2/7] char: xillybus: Remove duplicate error path code
From: Eli Billauer
Date: Wed Aug 05 2026 - 07:15:46 EST
Remove dedicated code for the error path, which is both redundant and
incorrect: It calls kref_put() before mutex_unlock(&chan->lock). As
kref_put() may result in releasing the memory containing the mutex, this
could lead to UAF.
Assisted-by: Deepseek:v4-pro Kimi:K2.6 ChatGPT:GPT-5.5 Claude:Sonnet-4.6
Assisted-by: Sashiko-0.2.5:gemini-3.1-pro-preview
Signed-off-by: Eli Billauer <eli.billauer@xxxxxxxxx>
---
Notes:
Changelog:
=========
No change on v4->v5.
Changes v3->v4:
-- Correct the commit description to indicate that the removed duplicate
code wasn't only redundant, but could also lead to a UAF, as pointed
out by Sashiko, and an attribution is hence added too.
Changes v2->v3:
-- Add Assisted-by tag to description
No change on v1->v2.
drivers/char/xillybus/xillyusb.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xillyusb.c
index 560c3568fc96..ee819e2e3f82 100644
--- a/drivers/char/xillybus/xillyusb.c
+++ b/drivers/char/xillybus/xillyusb.c
@@ -1424,16 +1424,12 @@ static int xillyusb_open(struct inode *inode, struct file *filp)
if (filp->f_mode & FMODE_WRITE)
chan->open_for_write = 0;
+unmutex_fail:
mutex_unlock(&chan->lock);
kref_put(&xdev->kref, cleanup_dev);
return rc;
-
-unmutex_fail:
- kref_put(&xdev->kref, cleanup_dev);
- mutex_unlock(&chan->lock);
- return rc;
}
static ssize_t xillyusb_read(struct file *filp, char __user *userbuf,
--
2.34.1