bobuhiro11/gokvm

View on GitHub

Showing 29 of 29 total issues

Function _ has 219 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func _() {
    // An "invalid array index" compiler error signifies that the constant values have changed.
    // Re-run the stringer command to generate them again.
    var x [1]struct{}
    _ = x[CapIRQChip-0]
Severity: Major
Found in kvm/capability_string.go - About 7 hrs to fix

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

    func NewMSRS(data []byte) (*MSRS, error) {
        m := MSRS{}
    
        var buf bytes.Buffer
        if err := binary.Write(&buf, binary.LittleEndian, data); err != nil && !errors.Is(err, io.EOF) {
    Severity: Major
    Found in kvm/msr.go and 2 other locations - About 3 hrs to fix
    kvm/cpuid.go on lines 39..62
    kvm/irq.go on lines 179..202

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 275.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

    func NewCPUID(data []byte) (*CPUID, error) {
        c := CPUID{}
    
        var buf bytes.Buffer
        if err := binary.Write(&buf, binary.LittleEndian, data); err != nil && !errors.Is(err, io.EOF) {
    Severity: Major
    Found in kvm/cpuid.go and 2 other locations - About 3 hrs to fix
    kvm/irq.go on lines 179..202
    kvm/msr.go on lines 208..231

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 275.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

    func NewIRQRouting(data []byte) (*IRQRouting, error) {
        r := IRQRouting{}
    
        var buf bytes.Buffer
        if err := binary.Write(&buf, binary.LittleEndian, data); err != nil && !errors.Is(err, io.EOF) {
    Severity: Major
    Found in kvm/irq.go and 2 other locations - About 3 hrs to fix
    kvm/cpuid.go on lines 39..62
    kvm/msr.go on lines 208..231

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 275.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    func (c *CPUID) Bytes() ([]byte, error) {
        var buf bytes.Buffer
    
        if err := binary.Write(&buf, binary.LittleEndian, c.Nent); err != nil {
            return nil, err
    Severity: Major
    Found in kvm/cpuid.go and 1 other location - About 1 hr to fix
    kvm/irq.go on lines 159..177

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 184.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    func (r *IRQRouting) Bytes() ([]byte, error) {
        var buf bytes.Buffer
    
        if err := binary.Write(&buf, binary.LittleEndian, r.Nr); err != nil {
            return nil, err
    Severity: Major
    Found in kvm/irq.go and 1 other location - About 1 hr to fix
    kvm/cpuid.go on lines 19..37

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 184.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    func GetEmulatedCPUID(kvmFd uintptr, kvmCPUID *CPUID) error {
        var c *CPUID
    
        data, err := kvmCPUID.Bytes()
        if err != nil {
    Severity: Major
    Found in kvm/cpuid.go and 1 other location - About 1 hr to fix
    kvm/cpuid.go on lines 78..99

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 162.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    func GetSupportedCPUID(kvmFd uintptr, kvmCPUID *CPUID) error {
        var c *CPUID
    
        data, err := kvmCPUID.Bytes()
        if err != nil {
    Severity: Major
    Found in kvm/cpuid.go and 1 other location - About 1 hr to fix
    kvm/cpuid.go on lines 144..165

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 162.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function KVMCapabilities has 63 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func KVMCapabilities() error {
        X86tests := []kvm.Capability{
            kvm.CapIRQChip,
            kvm.CapUserMemory,
            kvm.CapSetTSSAddr,
    Severity: Minor
    Found in probe/capabilities.go - About 1 hr to fix

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

      func SetMSRs(vcpuFd uintptr, msrs *MSRS) error {
          var m *MSRS
      
          data, err := msrs.Bytes()
          if err != nil {
      Severity: Major
      Found in kvm/msr.go and 2 other locations - About 1 hr to fix
      kvm/cpuid.go on lines 120..141
      kvm/msr.go on lines 256..277

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 150.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

      func GetMSRs(vcpuFd uintptr, msrs *MSRS) error {
          var m *MSRS
      
          data, err := msrs.Bytes()
          if err != nil {
      Severity: Major
      Found in kvm/msr.go and 2 other locations - About 1 hr to fix
      kvm/cpuid.go on lines 120..141
      kvm/msr.go on lines 233..254

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 150.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

      func GetCPUID2(vcpuFd uintptr, kvmCPUID *CPUID) error {
          var c *CPUID
      
          data, err := kvmCPUID.Bytes()
          if err != nil {
      Severity: Major
      Found in kvm/cpuid.go and 2 other locations - About 1 hr to fix
      kvm/msr.go on lines 233..254
      kvm/msr.go on lines 256..277

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 150.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Function ParsePVHEntry has 57 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func ParsePVHEntry(fwimg io.ReaderAt, phdr *elf.Prog) (uint32, error) {
          node := elfNote{}
          off := int64(phdr.Off)
          readSize := 0
      
      
      Severity: Minor
      Found in pvh/pvhboot.go - About 1 hr to fix

        Function CheckPVH has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
        Open

        func CheckPVH(kern io.ReaderAt) (bool, error) {
            elfkern, err := elf.NewFile(kern)
            if err != nil {
                return false, nil //nolint:nilerr
            }
        Severity: Minor
        Found in pvh/pvhboot.go - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        func (h *HVMModListEntry) Bytes() ([]byte, error) {
            var buf bytes.Buffer
        
            for _, item := range []interface{}{
                h.Addr,
        Severity: Minor
        Found in pvh/pvhboot.go and 1 other location - About 55 mins to fix
        pvh/pvhboot.go on lines 119..134

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 127.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        func (h *HVMMemMapTableEntry) Bytes() ([]byte, error) {
            var buf bytes.Buffer
        
            for _, item := range []interface{}{
                h.Addr,
        Severity: Minor
        Found in pvh/pvhboot.go and 1 other location - About 55 mins to fix
        pvh/pvhboot.go on lines 87..102

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 127.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Function ParsePVHEntry has 8 return statements (exceeds 4 allowed).
        Open

        func ParsePVHEntry(fwimg io.ReaderAt, phdr *elf.Prog) (uint32, error) {
            node := elfNote{}
            off := int64(phdr.Off)
            readSize := 0
        
        
        Severity: Major
        Found in pvh/pvhboot.go - About 50 mins to fix

          Method Machine.Args has 7 return statements (exceeds 4 allowed).
          Open

          func (m *Machine) Args(cpu int, r *kvm.Regs, nargs int) ([]uintptr, error) {
              // We must always validate the cpu number, even if we don't absolutely need it.
              // i.e., for pure register args, the cpu is not needed, but it's
              // best to validate it.
              if _, err := m.CPUToFD(cpu); err != nil {
          Severity: Major
          Found in machine/debug_amd64.go - About 45 mins to fix

            Function CheckPVH has 7 return statements (exceeds 4 allowed).
            Open

            func CheckPVH(kern io.ReaderAt) (bool, error) {
                elfkern, err := elf.NewFile(kern)
                if err != nil {
                    return false, nil //nolint:nilerr
                }
            Severity: Major
            Found in pvh/pvhboot.go - About 45 mins to fix

              Method PCI.PciConfDataIn has 7 return statements (exceeds 4 allowed).
              Open

              func (p *PCI) PciConfDataIn(port uint64, values []byte) error {
                  // offset can be obtained from many source as below:
                  //        (address from IO port 0xcf8) & 0xfc + (IO port address for Data) - 0xCFC
                  // see pci_conf1_read in linux/arch/x86/pci/direct.c for more detail.
                  offset := int(p.addr.getRegisterOffset() + uint32(port-0xCFC))
              Severity: Major
              Found in pci/pci.go - About 45 mins to fix
                Severity
                Category
                Status
                Source
                Language