From: Christoph Hellwig Date: Fri, 6 May 2022 06:53:11 +0000 (+0200) Subject: helpers X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a4ee6bbe76fef38e01cbe54fc23e07ea8b7c33b5;p=users%2Fhch%2Fblock.git helpers --- diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 0fd6850c0213..62bd2033bce9 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -20,6 +20,17 @@ static void __user *nvme_to_user_ptr(uintptr_t ptrval) return (void __user *)ptrval; } +static struct nvme_ns *file_to_ns(struct file *file) +{ + return container_of(file_inode(file)->i_cdev, struct nvme_ns, cdev); +} + +static struct nvme_ns_head *file_to_ns_head(struct file *file) +{ + return container_of(file_inode(file)->i_cdev, struct nvme_ns_head, + cdev); +} + static void *nvme_add_user_metadata(struct bio *bio, void __user *ubuf, unsigned len, u32 seed, bool write) { @@ -550,10 +561,7 @@ int nvme_ioctl(struct block_device *bdev, fmode_t mode, long nvme_ns_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct nvme_ns *ns = - container_of(file_inode(file)->i_cdev, struct nvme_ns, cdev); - - return __nvme_ioctl(ns, cmd, (void __user *)arg); + return __nvme_ioctl(file_to_ns(file), cmd, (void __user *)arg); } static int nvme_ns_uring_cmd(struct nvme_ns *ns, struct io_uring_cmd *ioucmd, @@ -586,10 +594,7 @@ static int nvme_ns_uring_cmd(struct nvme_ns *ns, struct io_uring_cmd *ioucmd, int nvme_ns_chr_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags) { - struct nvme_ns *ns = container_of(file_inode(ioucmd->file)->i_cdev, - struct nvme_ns, cdev); - - return nvme_ns_uring_cmd(ns, ioucmd, issue_flags); + return nvme_ns_uring_cmd(file_to_ns(ioucmd->file), ioucmd, issue_flags); } #ifdef CONFIG_NVME_MULTIPATH @@ -638,9 +643,7 @@ out_unlock: long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct cdev *cdev = file_inode(file)->i_cdev; - struct nvme_ns_head *head = - container_of(cdev, struct nvme_ns_head, cdev); + struct nvme_ns_head *head = file_to_ns_head(file); void __user *argp = (void __user *)arg; struct nvme_ns *ns; int srcu_idx, ret = -EWOULDBLOCK; @@ -662,8 +665,7 @@ out_unlock: int nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags) { - struct cdev *cdev = file_inode(ioucmd->file)->i_cdev; - struct nvme_ns_head *head = container_of(cdev, struct nvme_ns_head, cdev); + struct nvme_ns_head *head = file_to_ns_head(ioucmd->file); int srcu_idx = srcu_read_lock(&head->srcu); struct nvme_ns *ns = nvme_find_path(head); int ret;