Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Wrong usage of break statement #46

@QiAnXinCodeSafe

Description

@QiAnXinCodeSafe

There is no need for a break statement in the case block in golang.

switch int(event) {
case VirtioConsoleDeviceReady:
vchannel.Debug("device-ready")
device.sendCtrl(0, VirtioConsolePortAdd, 1)
break
case VirtioConsolePortAdd:
vchannel.Debug("port-add?")
break
case VirtioConsolePortRemove:
vchannel.Debug("port-remove?")
break
case VirtioConsolePortReady:
vchannel.Debug("port-ready")
if id == 0 && value == 1 {
// No, this is not a console.
device.sendCtrl(0, VirtioConsolePortConsole, 0)
device.sendCtrl(0, VirtioConsolePortOpen, 1)
if !device.Opened {
device.Opened = true
device.read_lock.Unlock()
device.write_lock.Unlock()
}
}
break
case VirtioConsolePortConsole:
vchannel.Debug("port-console?")
break
case VirtioConsolePortResize:
vchannel.Debug("port-resize")
break
case VirtioConsolePortOpen:
vchannel.Debug("port-open")
break
case VirtioConsolePortName:
vchannel.Debug("port-name")
break
default:
vchannel.Debug("unknown?")
break
}

switch int(cmd_type) {
case VirtioBlockTIn:
_, err := buf.PRead(device.Fd, offset, 16, buf.Length()-17)
if err != nil {
device.Debug(
"read err [%x,%x] -> %s",
offset,
int(offset)+buf.Length()-18,
err.Error())
status.Set8(0, VirtioBlockSIoErr)
} else {
device.Debug(
"read ok [%x,%x]",
offset,
int(offset)+buf.Length()-18)
status.Set8(0, VirtioBlockSOk)
}
break
case VirtioBlockTOut:
_, err := buf.PWrite(device.Fd, offset, 16, buf.Length()-17)
if err != nil {
device.Debug(
"write err [%x,%x] -> %s",
offset,
int(offset)+buf.Length()-18,
err.Error())
status.Set8(0, VirtioBlockSIoErr)
} else {
device.Debug(
"write ok [%x,%x]",
offset,
int(offset)+buf.Length()-18)
status.Set8(0, VirtioBlockSOk)
}
break
default:
device.Debug("unknown command '%d'?", cmd_type)
status.Set8(0, VirtioBlockSUnsupported)
break
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions