media: convert media_request_alloc() to FD_PREPARE()

Link: https://patch.msgid.link/20251123-work-fd-prepare-v4-40-b6efa1706cfd@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Christian Brauner 2025-11-23 17:33:58 +01:00
parent c99dc44562
commit 6f504cbf10
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2
1 changed files with 12 additions and 22 deletions

View File

@ -282,8 +282,6 @@ EXPORT_SYMBOL_GPL(media_request_get_by_fd);
int media_request_alloc(struct media_device *mdev, int *alloc_fd) int media_request_alloc(struct media_device *mdev, int *alloc_fd)
{ {
struct media_request *req; struct media_request *req;
struct file *filp;
int fd;
int ret; int ret;
/* Either both are NULL or both are non-NULL */ /* Either both are NULL or both are non-NULL */
@ -297,19 +295,6 @@ int media_request_alloc(struct media_device *mdev, int *alloc_fd)
if (!req) if (!req)
return -ENOMEM; return -ENOMEM;
fd = get_unused_fd_flags(O_CLOEXEC);
if (fd < 0) {
ret = fd;
goto err_free_req;
}
filp = anon_inode_getfile("request", &request_fops, NULL, O_CLOEXEC);
if (IS_ERR(filp)) {
ret = PTR_ERR(filp);
goto err_put_fd;
}
filp->private_data = req;
req->mdev = mdev; req->mdev = mdev;
req->state = MEDIA_REQUEST_STATE_IDLE; req->state = MEDIA_REQUEST_STATE_IDLE;
req->num_incomplete_objects = 0; req->num_incomplete_objects = 0;
@ -320,19 +305,24 @@ int media_request_alloc(struct media_device *mdev, int *alloc_fd)
req->updating_count = 0; req->updating_count = 0;
req->access_count = 0; req->access_count = 0;
*alloc_fd = fd; FD_PREPARE(fdf, O_CLOEXEC,
anon_inode_getfile("request", &request_fops, NULL,
O_CLOEXEC));
if (fdf.err) {
ret = fdf.err;
goto err_free_req;
}
fd_prepare_file(fdf)->private_data = req;
*alloc_fd = fd_publish(fdf);
snprintf(req->debug_str, sizeof(req->debug_str), "%u:%d", snprintf(req->debug_str, sizeof(req->debug_str), "%u:%d",
atomic_inc_return(&mdev->request_id), fd); atomic_inc_return(&mdev->request_id), *alloc_fd);
dev_dbg(mdev->dev, "request: allocated %s\n", req->debug_str); dev_dbg(mdev->dev, "request: allocated %s\n", req->debug_str);
fd_install(fd, filp);
return 0; return 0;
err_put_fd:
put_unused_fd(fd);
err_free_req: err_free_req:
if (mdev->ops->req_free) if (mdev->ops->req_free)
mdev->ops->req_free(req); mdev->ops->req_free(req);