[PATCH RFC POC 48/50] misc: fastrpc: install the dma-buf descriptor when the ioctl returns
From: Christian Brauner <brauner@kernel.org>
Date: 2026-09-15 11:37:33
Also in:
bpf, dri-devel, io-uring, kexec, kvm, linux-alpha, linux-arm-kernel, linux-arm-msm, linux-fsdevel, linux-gpio, linux-hyperv, linux-m68k, linux-mips, linux-mm, linux-sh, linux-um, lkml, netdev, sparclinux, virtualization
Subsystem:
char and misc drivers, qualcomm fastrpc driver, the rest · Maintainers:
Arnd Bergmann, Greg Kroah-Hartman, Srinivas Kandagatla, Linus Torvalds
Rely on the fd exit path machinery.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
drivers/misc/fastrpc.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 90fd669636ec..24b84019bbd7 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -7,6 +7,7 @@
#include <linux/dma-buf.h>
#include <linux/dma-mapping.h>
#include <linux/dma-resv.h>
+#include <linux/file.h>
#include <linux/idr.h>
#include <linux/list.h>
#include <linux/miscdevice.h>
@@ -1804,6 +1805,7 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp)
DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
struct fastrpc_buf *buf = NULL;
int err;
+ const struct fd_slot *fd;
if (copy_from_user(&bp, argp, sizeof(bp)))
return -EFAULT;
@@ -1822,23 +1824,16 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp)
return err;
}
- bp.fd = dma_buf_fd(buf->dmabuf, O_ACCMODE);
- if (bp.fd < 0) {
+ fd = fd_prepare(O_ACCMODE);
+ if (IS_ERR(fd)) {
dma_buf_put(buf->dmabuf);
return -EINVAL;
}
+ bp.fd = fd_stage(fd, buf->dmabuf->file);
- if (copy_to_user(argp, &bp, sizeof(bp))) {
- /*
- * The usercopy failed, but we can't do much about it, as
- * dma_buf_fd() already called fd_install() and made the
- * file descriptor accessible for the current process. It
- * might already be closed and dmabuf no longer valid when
- * we reach this point. Therefore "leak" the fd and rely on
- * the process exit path to do any required cleanup.
- */
+ /* The staged file is dropped with its descriptor if this faults. */
+ if (copy_to_user(argp, &bp, sizeof(bp)))
return -EFAULT;
- }
return 0;
}
--
2.53.0