Skip to content

Commit

Permalink
Identify inability to open a switch, avoid nil dereference
Browse files Browse the repository at this point in the history
In the case where we cannot open a /dev/switchtecX device, give a useful
panic message rather than just dereferencing a nil pointer.

Earlier in the log there will be an error stating "Error opening path", and
another stating "Failed to identify switch". The nil deference was happening
much later, so it was not obviously connected to those.

See NearNodeFlash/NearNodeFlash.github.io#178
for more details.

Signed-off-by: Dean Roehrich <[email protected]>
  • Loading branch information
roehrich-hpe committed Jul 8, 2024
1 parent 9d0ccb5 commit 1ae64c9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/manager-fabric/manager.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020, 2021, 2022 Hewlett Packard Enterprise Development LP
* Copyright 2020-2024 Hewlett Packard Enterprise Development LP
* Other additional copyright holders may be indicated within.
*
* The entirety of this work is licensed under the Apache License,
Expand Down Expand Up @@ -381,6 +381,7 @@ func (s *Switch) identify() error {
if os.IsNotExist(err) {
continue
} else if err != nil {
s.path = "" // Test this; it's easier than testing s.dev.
log.Error(err, "Error opening path")
return err
}
Expand Down Expand Up @@ -787,6 +788,11 @@ func (p *Port) bind() error {
break
}

if s.path == "" {
// See s.identify()
panic(fmt.Sprintf("Unable to identify switch for port: Initiator Port %d, Logical Port %d, PDFID: %#04x", initiatorPort.config.Port, logicalPortId, endpoint.pdfid))
}

log.Info("Binding Port")
if err := s.dev.Bind(uint8(initiatorPort.config.Port), uint8(logicalPortId), endpoint.pdfid); err != nil {
log.Error(err, "Bind Failed")
Expand Down

0 comments on commit 1ae64c9

Please sign in to comment.