From df0c2d5e04b13d3b7ace2b3c39257abc7677875a Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Mon, 5 Dec 2016 18:32:28 +0900 Subject: [PATCH] tcmu: check error before checking the result of length --- internal/tcmu/commands.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/tcmu/commands.go b/internal/tcmu/commands.go index ee17d0b..19b69d1 100644 --- a/internal/tcmu/commands.go +++ b/internal/tcmu/commands.go @@ -52,14 +52,14 @@ func (h *torusHandler) handleWrite(cmd *tcmu.SCSICmd) (tcmu.SCSIResponse, error) cmd.Buf = make([]byte, length) } n, err := cmd.Read(cmd.Buf[:int(length)]) - if n < length { - clog.Error("write/read failed: unable to copy enough") - return cmd.MediumError(), nil - } if err != nil { clog.Errorf("write/read failed: error: %v", err) return cmd.MediumError(), nil } + if n < length { + clog.Error("write/read failed: unable to copy enough") + return cmd.MediumError(), nil + } n, err = h.file.WriteAt(cmd.Buf[:length], int64(offset)) if n < length { clog.Error("write/write failed: unable to copy enough")