Skip to content

Commit

Permalink
Fix Xcvrd crash due to invalid key access in type_of_media_interface,…
Browse files Browse the repository at this point in the history
… host_electrical_interface, connector_dict (#206)

Due to wrong page selection, the eeprom read returned a value 0xff which was an invalid key into connector_dict[]. Now we verify the key validity before accessing the dict element. The fix for why the eeprom read returned 0xff is being investigated separately.

Signed-off-by: Prince George <prgeor@microsoft.com>
  • Loading branch information
prgeor authored and lguohan committed Jul 14, 2021
1 parent 67b8a77 commit 2d36a79
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions sonic_platform_base/sonic_sfp/qsfp_dd.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def decode_module_state(self, eeprom_data, offset, size):

def decode_connector(self, eeprom_data, offset, size):
connector_id = eeprom_data[offset]
return connector_dict[connector_id]
if connector_id in connector_dict.keys():
return connector_dict[connector_id]
else:
return 'N/A'

def decode_ext_id(self, eeprom_data, offset, size):
# bits 5-7 represent Module Card Power Class
Expand Down Expand Up @@ -76,7 +79,12 @@ def decode_cable_len(self, eeprom_data, offset, size):

def decode_media_type(self, eeprom_data, offset, size):
media_type_code = eeprom_data[0]

if media_type_code not in type_of_media_interface.keys():
return None

dict_name = type_of_media_interface[media_type_code]

if dict_name == "nm_850_media_interface":
return nm_850_media_interface
elif dict_name == "sm_media_interface":
Expand All @@ -91,11 +99,14 @@ def decode_media_type(self, eeprom_data, offset, size):
return None

def parse_application(self, sfp_media_type_dict, host_interface, media_interface):
host_result = host_electrical_interface[host_interface]
media_result = 'Unknown'
host_result = 'Unknown'

if host_interface in host_electrical_interface:
host_result = host_electrical_interface[host_interface]

if media_interface in sfp_media_type_dict.keys():
media_result = sfp_media_type_dict[media_interface]
else:
media_result = 'Unknown'
return host_result, media_result

version = '1.0'
Expand Down Expand Up @@ -213,7 +224,7 @@ def parse_vendor_sn(self, sn_raw_data, start_pos):

def parse_vendor_date(self, date_raw_data, start_pos):
return sffbase.parse(self, self.vendor_date, date_raw_data, start_pos)

def parse_vendor_oui(self, vendor_oui_data, start_pos):
return sffbase.parse(self, self.vendor_oui, vendor_oui_data, start_pos)

Expand Down Expand Up @@ -700,7 +711,7 @@ def parse_voltage(self, eeprom_raw_data, start_pos):
def parse_channel_monitor_params(self, eeprom_raw_data, start_pos):
return sffbase.parse(self, self.dom_channel_monitor_params, eeprom_raw_data,
start_pos)

def parse_dom_tx_bias(self, eeprom_raw_data, start_pos):
return sffbase.parse(self, self.dom_tx_bias, eeprom_raw_data,
start_pos)
Expand Down

0 comments on commit 2d36a79

Please sign in to comment.