From: Dongli Zhang Date: Wed, 23 Jan 2019 07:48:36 +0000 (+0800) Subject: xen/blkback: rework validate_io_op() X-Git-Tag: v4.1.12-124.31.3~303 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=ebd6f4c1518234182cf6c36f060c40b519b487bf;p=users%2Fjedix%2Flinux-maple.git xen/blkback: rework validate_io_op() Rework many if statements in validate_io_op() into a switch statement. Orabug: 29199843 Suggested-by: Ankur Arora Signed-off-by: Dongli Zhang Reviewed-by: Ankur Arora Signed-off-by: Brian Maly --- diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c index 1f892410342a9..e14b87c422667 100644 --- a/drivers/block/xen-blkback/blkback.c +++ b/drivers/block/xen-blkback/blkback.c @@ -1148,33 +1148,43 @@ static bool validate_io_op(const struct blkif_request *req, unsigned int nseg) unsigned short req_operation = req->operation == BLKIF_OP_INDIRECT ? req->u.indirect.indirect_op : req->operation; - if (unlikely(req_operation == BLKIF_OP_RESERVED_1)) + switch (req_operation) { + case BLKIF_OP_RESERVED_1: goto fail; - /* For discard, nseg is not meaninful */ - if (unlikely(req_operation == BLKIF_OP_DISCARD)) + case BLKIF_OP_DISCARD: + /* For discard, nseg is not meaninful */ return true; - if ((req_operation > BLKIF_OP_INDIRECT) || /* valid operation? */ - ((req->operation == BLKIF_OP_INDIRECT) && /* valid indirect-op */ - (req_operation != BLKIF_OP_READ) && - (req_operation != BLKIF_OP_WRITE))) { - goto fail; - } - - if (unlikely(nseg == 0)) { /* if nseg == 0, is op in the correct set? */ - if (req_operation != BLKIF_OP_FLUSH_DISKCACHE && - req_operation != BLKIF_OP_WRITE_BARRIER) + case BLKIF_OP_READ: + case BLKIF_OP_WRITE: + /* if nseg == 0, is op in the correct set? */ + if (unlikely(nseg == 0)) goto fail; - } else { /* if nseg > 0, check if nseg makes sense. */ - if (((req->operation != BLKIF_OP_INDIRECT) && - (nseg > BLKIF_MAX_SEGMENTS_PER_REQUEST)) || - ((req->operation == BLKIF_OP_INDIRECT) && - (nseg > MAX_INDIRECT_SEGMENTS))) { + break; + + case BLKIF_OP_WRITE_BARRIER: + case BLKIF_OP_FLUSH_DISKCACHE: + /* not valid indirect-op */ + if (req->operation == BLKIF_OP_INDIRECT) goto fail; - } + break; + + default: + /* req_operation should never >= BLKIF_OP_INDIRECT */ + goto fail; } + /* if nseg > 0, check if nseg makes sense. */ + if (req->operation != BLKIF_OP_INDIRECT && + nseg > BLKIF_MAX_SEGMENTS_PER_REQUEST) + goto fail; + + /* if nseg > 0, check if nseg makes sense. */ + if (req->operation == BLKIF_OP_INDIRECT && + nseg > MAX_INDIRECT_SEGMENTS) + goto fail; + return true; fail: pr_debug("Invalid indirect operation or bad number of "