From: Jens Axboe Date: Fri, 8 Oct 2010 17:58:11 +0000 (+0200) Subject: Refactor command validation X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=2e59579daed197456adcf668168c26eae19fd355;p=binject.git Refactor command validation Signed-off-by: Jens Axboe --- diff --git a/main.c b/main.c index 45da4f6..3d9144c 100644 --- a/main.c +++ b/main.c @@ -290,23 +290,23 @@ static void b_dev_complete_commands(struct b_dev *bd) static int b_dev_validate_command(struct b_user_cmd *buc) { + int i; + if (!binject_buc_check_magic(buc)) return -EINVAL; - switch (buc->type) { - case B_TYPE_WRITE: - case B_TYPE_READ: - case B_TYPE_DISCARD: - case B_TYPE_READVOID: - case B_TYPE_WRITEZERO: - case B_TYPE_READBARRIER: - case B_TYPE_WRITEBARRIER: - if (buc->len) - return 0; - return -EINVAL; - default: - return -EINVAL; + for (i = 0; i < B_TYPE_NR; i++) { + const struct uc_map *ucm = &uc_map[i]; + + if (ucm->type != buc->type) + continue; + if (ucm->data_transfer && !buc->len) + break; + + return 0; } + + return -EINVAL; } static void b_cmd_endio(struct bio *bio, int error)