Skip to content

Commit

Permalink
nvme: refactor nvme_add_user_metadata
Browse files Browse the repository at this point in the history
Pass struct request rather than bio. It helps to kill a parameter, and
some processing clean-up too.

Signed-off-by: Kanchan Joshi <joshi.k@samsung.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220930062749.152261-7-anuj20.g@samsung.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Kanchan Joshi authored and Jens Axboe committed Sep 30, 2022
1 parent 7f05635 commit 38c0dda
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions drivers/nvme/host/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ static void __user *nvme_to_user_ptr(uintptr_t ptrval)
return (void __user *)ptrval;
}

static void *nvme_add_user_metadata(struct bio *bio, void __user *ubuf,
unsigned len, u32 seed, bool write)
static void *nvme_add_user_metadata(struct request *req, void __user *ubuf,
unsigned len, u32 seed)
{
struct bio_integrity_payload *bip;
int ret = -ENOMEM;
void *buf;
struct bio *bio = req->bio;

buf = kmalloc(len, GFP_KERNEL);
if (!buf)
goto out;

ret = -EFAULT;
if (write && copy_from_user(buf, ubuf, len))
if ((req_op(req) == REQ_OP_DRV_OUT) && copy_from_user(buf, ubuf, len))
goto out_free_meta;

bip = bio_integrity_alloc(bio, GFP_KERNEL, 1);
Expand All @@ -45,9 +46,13 @@ static void *nvme_add_user_metadata(struct bio *bio, void __user *ubuf,
bip->bip_iter.bi_sector = seed;
ret = bio_integrity_add_page(bio, virt_to_page(buf), len,
offset_in_page(buf));
if (ret == len)
return buf;
ret = -ENOMEM;
if (ret != len) {
ret = -ENOMEM;
goto out_free_meta;
}

req->cmd_flags |= REQ_INTEGRITY;
return buf;
out_free_meta:
kfree(buf);
out:
Expand All @@ -70,7 +75,6 @@ static struct request *nvme_alloc_user_request(struct request_queue *q,
u32 meta_seed, void **metap, unsigned timeout, bool vec,
blk_opf_t rq_flags, blk_mq_req_flags_t blk_flags)
{
bool write = nvme_is_write(cmd);
struct nvme_ns *ns = q->queuedata;
struct block_device *bdev = ns ? ns->disk->part0 : NULL;
struct request *req;
Expand All @@ -96,13 +100,12 @@ static struct request *nvme_alloc_user_request(struct request_queue *q,
if (bdev)
bio_set_dev(bio, bdev);
if (bdev && meta_buffer && meta_len) {
meta = nvme_add_user_metadata(bio, meta_buffer, meta_len,
meta_seed, write);
meta = nvme_add_user_metadata(req, meta_buffer,
meta_len, meta_seed);
if (IS_ERR(meta)) {
ret = PTR_ERR(meta);
goto out_unmap;
}
req->cmd_flags |= REQ_INTEGRITY;
*metap = meta;
}
}
Expand Down

0 comments on commit 38c0dda

Please sign in to comment.