Skip to content

Commit d23549f

Browse files
Ming Leikawasaki
authored andcommitted
ublk: add helper ublk_check_fetch_buf()
Add helper ublk_check_fetch_buf() for checking buffer only. Signed-off-by: Ming Lei <[email protected]>
1 parent 37e1c9a commit d23549f

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

drivers/block/ublk_drv.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,22 @@ static int ublk_unregister_io_buf(struct io_uring_cmd *cmd,
21652165
return io_buffer_unregister_bvec(cmd, index, issue_flags);
21662166
}
21672167

2168+
static int ublk_check_fetch_buf(const struct ublk_queue *ubq, __u64 buf_addr)
2169+
{
2170+
if (ublk_need_map_io(ubq)) {
2171+
/*
2172+
* FETCH_RQ has to provide IO buffer if NEED GET
2173+
* DATA is not enabled
2174+
*/
2175+
if (!buf_addr && !ublk_need_get_data(ubq))
2176+
return -EINVAL;
2177+
} else if (buf_addr) {
2178+
/* User copy requires addr to be unset */
2179+
return -EINVAL;
2180+
}
2181+
return 0;
2182+
}
2183+
21682184
static int ublk_fetch(struct io_uring_cmd *cmd, struct ublk_queue *ubq,
21692185
struct ublk_io *io, __u64 buf_addr)
21702186
{
@@ -2191,19 +2207,6 @@ static int ublk_fetch(struct io_uring_cmd *cmd, struct ublk_queue *ubq,
21912207

21922208
WARN_ON_ONCE(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV);
21932209

2194-
if (ublk_need_map_io(ubq)) {
2195-
/*
2196-
* FETCH_RQ has to provide IO buffer if NEED GET
2197-
* DATA is not enabled
2198-
*/
2199-
if (!buf_addr && !ublk_need_get_data(ubq))
2200-
goto out;
2201-
} else if (buf_addr) {
2202-
/* User copy requires addr to be unset */
2203-
ret = -EINVAL;
2204-
goto out;
2205-
}
2206-
22072210
ublk_fill_io_cmd(io, cmd, 0);
22082211
ret = ublk_config_io_buf(ubq, io, cmd, buf_addr, NULL);
22092212
if (ret)
@@ -2316,6 +2319,9 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
23162319
io = &ubq->ios[tag];
23172320
/* UBLK_IO_FETCH_REQ can be handled on any task, which sets io->task */
23182321
if (unlikely(_IOC_NR(cmd_op) == UBLK_IO_FETCH_REQ)) {
2322+
ret = ublk_check_fetch_buf(ubq, ub_cmd->addr);
2323+
if (ret)
2324+
goto out;
23192325
ret = ublk_fetch(cmd, ubq, io, ub_cmd->addr);
23202326
if (ret)
23212327
goto out;

0 commit comments

Comments
 (0)