Skip to content

Commit

Permalink
blktests: src/miniublk.c: fix segment fault when io_uring is disabled
Browse files Browse the repository at this point in the history
When io_uring is disabled, ublk_ctrl_init() will return NULL, so we
have to check the result.

Fixes segment fault reported from Yi.

Reported-by: Zhang Yi <[email protected]>
Signed-off-by: Ming Lei <[email protected]>
Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
  • Loading branch information
Ming Lei authored and kawasaki committed Dec 18, 2024
1 parent 54d0175 commit ce767b4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/miniublk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1136,9 +1136,14 @@ static int ublk_stop_io_daemon(const struct ublk_dev *dev)
static int __cmd_dev_del(int number, bool log)
{
struct ublk_dev *dev;
int ret;
int ret = -ENODEV;

dev = ublk_ctrl_init();
if (!dev) {
ublk_err("del dev %d failed\n", number);
goto fail;
}

dev->dev_info.dev_id = number;

ret = ublk_ctrl_get_info(dev);
Expand Down Expand Up @@ -1208,8 +1213,14 @@ static int cmd_dev_del(int argc, char *argv[])

static int __cmd_dev_list(int number, bool log)
{
struct ublk_dev *dev = ublk_ctrl_init();
int ret;
struct ublk_dev *dev;
int ret = -ENODEV;

dev = ublk_ctrl_init();
if (!dev) {
ublk_err("list dev %d failed\n", number);
goto exit;
}

dev->dev_info.dev_id = number;

Expand All @@ -1223,7 +1234,7 @@ static int __cmd_dev_list(int number, bool log)
}

ublk_ctrl_deinit(dev);

exit:
return ret;
}

Expand Down

0 comments on commit ce767b4

Please sign in to comment.