]> www.infradead.org Git - users/hch/block.git/commitdiff
helpers
authorChristoph Hellwig <hch@lst.de>
Fri, 6 May 2022 06:53:11 +0000 (08:53 +0200)
committerChristoph Hellwig <hch@lst.de>
Fri, 6 May 2022 06:58:26 +0000 (08:58 +0200)
drivers/nvme/host/ioctl.c

index 0fd6850c021375a8af5985eae3c22b9f8702a604..62bd2033bce984d5c01d69e301058d95382427b9 100644 (file)
@@ -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;