Skip to content

Commit

Permalink
ocp: checkpatch.pl and code scanner fixes
Browse files Browse the repository at this point in the history
Signed-off-by: jeff-lien-wdc <[email protected]>
  • Loading branch information
jeff-lien-wdc committed Sep 23, 2024
1 parent 50f78ee commit 1da23bf
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 64 deletions.
2 changes: 1 addition & 1 deletion plugins/ocp/ocp-nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ static int get_telemetry_dump(struct nvme_dev *dev, char *filename, char *sn,

char *da1_fifo = calloc(da1_sz, sizeof(char));

printf("Get DA 1 FIFO addr: %p, offset 0x%llx \n",
printf("Get DA 1 FIFO addr: %p, offset 0x%llx\n",

Check failure on line 1332 in plugins/ocp/ocp-nvme.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: unnecessary whitespace before a quoted newline
da1_fifo, da1_off);
err = get_telemetry_data(dev, nsid, tele_type,
(da1->event_fifos[i].size) * 4,
Expand Down
160 changes: 97 additions & 63 deletions plugins/ocp/ocp-telemetry-decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,16 +656,18 @@ void parse_time_stamp_event(struct nvme_ocp_telemetry_event_descriptor *pevent_d
vu_data = true;
vu_data_size =
((pevent_descriptor->event_data_size * SIZE_OF_DWORD) -
(sizeof(struct nvme_ocp_time_stamp_dbg_evt_class_format) + SIZE_OF_VU_EVENT_ID));
(sizeof(struct nvme_ocp_time_stamp_dbg_evt_class_format) +

Check failure on line 659 in plugins/ocp/ocp-telemetry-decode.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 106 exceeds 100 columns
SIZE_OF_VU_EVENT_ID));

ptime_stamp_event_vu_data = (struct nvme_ocp_common_dbg_evt_class_vu_data *)
(ptime_stamp_event + sizeof(struct nvme_ocp_time_stamp_dbg_evt_class_format));
ptime_stamp_event_vu_data =

Check failure on line 662 in plugins/ocp/ocp-telemetry-decode.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 102 exceeds 100 columns
(struct nvme_ocp_common_dbg_evt_class_vu_data *)ptime_stamp_event +
sizeof(struct nvme_ocp_time_stamp_dbg_evt_class_format);

Check failure

Code scanning / CodeQL

Suspicious add with sizeof High

Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is
nvme_ocp_common_dbg_evt_class_vu_data *
.
vu_event_id = ptime_stamp_event_vu_data->vu_event_identifier;
pdata = (__u8 *)&(ptime_stamp_event_vu_data->data);

parse_ocp_telemetry_string_log(0, vu_event_id,
pevent_descriptor->debug_event_class_type,
VU_EVENT_STRING, description_str);
pevent_descriptor->debug_event_class_type,
VU_EVENT_STRING, description_str);
}

if (pevent_fifos_object != NULL) {
Expand Down Expand Up @@ -718,15 +720,18 @@ void parse_pcie_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descrip
vu_data = true;
vu_data_size =
((pevent_descriptor->event_data_size * SIZE_OF_DWORD) -
(sizeof(struct nvme_ocp_pcie_dbg_evt_class_format) + SIZE_OF_VU_EVENT_ID));
(sizeof(struct nvme_ocp_pcie_dbg_evt_class_format) +
SIZE_OF_VU_EVENT_ID));

ppcie_event_vu_data = (struct nvme_ocp_common_dbg_evt_class_vu_data *)
(ppcie_event + sizeof(struct nvme_ocp_pcie_dbg_evt_class_format));
ppcie_event_vu_data =
(struct nvme_ocp_common_dbg_evt_class_vu_data *)ppcie_event +
sizeof(struct nvme_ocp_pcie_dbg_evt_class_format);

Check failure

Code scanning / CodeQL

Suspicious add with sizeof High

Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is
nvme_ocp_common_dbg_evt_class_vu_data *
.
vu_event_id = ppcie_event_vu_data->vu_event_identifier;
pdata = (__u8 *)&(ppcie_event_vu_data->data);

parse_ocp_telemetry_string_log(0, vu_event_id,
pevent_descriptor->debug_event_class_type, VU_EVENT_STRING, description_str);
pevent_descriptor->debug_event_class_type,
VU_EVENT_STRING, description_str);
}

if (pevent_fifos_object != NULL) {
Expand Down Expand Up @@ -779,15 +784,19 @@ void parse_nvme_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descrip
vu_data = true;
vu_data_size =
((pevent_descriptor->event_data_size * SIZE_OF_DWORD) -
(sizeof(struct nvme_ocp_nvme_dbg_evt_class_format) + SIZE_OF_VU_EVENT_ID));
pnvme_event_vu_data = (struct nvme_ocp_common_dbg_evt_class_vu_data *)
(pnvme_event + sizeof(struct nvme_ocp_nvme_dbg_evt_class_format));
(sizeof(struct nvme_ocp_nvme_dbg_evt_class_format) +
SIZE_OF_VU_EVENT_ID));
pnvme_event_vu_data =
(struct nvme_ocp_common_dbg_evt_class_vu_data *)pnvme_event +

Check failure on line 790 in plugins/ocp/ocp-telemetry-decode.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 101 exceeds 100 columns
sizeof(struct nvme_ocp_nvme_dbg_evt_class_format);

Check failure

Code scanning / CodeQL

Suspicious add with sizeof High

Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is
nvme_ocp_common_dbg_evt_class_vu_data *
.

vu_event_id = pnvme_event_vu_data->vu_event_identifier;
pdata = (__u8 *)&(pnvme_event_vu_data->data);

parse_ocp_telemetry_string_log(0, vu_event_id,
pevent_descriptor->debug_event_class_type, VU_EVENT_STRING, description_str);
pevent_descriptor->debug_event_class_type,
VU_EVENT_STRING,
description_str);
}

if (pevent_fifos_object != NULL) {
Expand Down Expand Up @@ -828,17 +837,18 @@ void parse_common_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descr
{
if (pevent_specific_data) {
struct nvme_ocp_common_dbg_evt_class_vu_data *pcommon_debug_event_vu_data =
(struct nvme_ocp_common_dbg_evt_class_vu_data *) pevent_specific_data;
(struct nvme_ocp_common_dbg_evt_class_vu_data *) pevent_specific_data;

Check failure on line 841 in plugins/ocp/ocp-telemetry-decode.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 104 exceeds 100 columns
__le16 vu_event_id = pcommon_debug_event_vu_data->vu_event_identifier;;
__le16 vu_event_id = pcommon_debug_event_vu_data->vu_event_identifier;
char description_str[256] = "";
__u8 *pdata = (__u8 *)&(pcommon_debug_event_vu_data->data);

unsigned int vu_data_size = ((pevent_descriptor->event_data_size *
SIZE_OF_DWORD) - SIZE_OF_VU_EVENT_ID);

parse_ocp_telemetry_string_log(0, vu_event_id,
pevent_descriptor->debug_event_class_type, VU_EVENT_STRING, description_str);
pevent_descriptor->debug_event_class_type,
VU_EVENT_STRING, description_str);

if (pevent_fifos_object != NULL) {
json_add_formatted_u32_str(pevent_descriptor_obj, STR_VU_EVENT_ID_STRING,
Expand Down Expand Up @@ -880,15 +890,19 @@ void parse_media_wear_event(struct nvme_ocp_telemetry_event_descriptor *pevent_d
vu_data = true;
vu_data_size =
((pevent_descriptor->event_data_size * SIZE_OF_DWORD) -
(sizeof(struct nvme_ocp_media_wear_dbg_evt_class_format) + SIZE_OF_VU_EVENT_ID));
(sizeof(struct nvme_ocp_media_wear_dbg_evt_class_format) +
SIZE_OF_VU_EVENT_ID));

pmedia_wear_event_vu_data = (struct nvme_ocp_common_dbg_evt_class_vu_data *)
(pmedia_wear_event + sizeof(struct nvme_ocp_media_wear_dbg_evt_class_format));
pmedia_wear_event_vu_data =
(struct nvme_ocp_common_dbg_evt_class_vu_data *)pmedia_wear_event +
sizeof(struct nvme_ocp_media_wear_dbg_evt_class_format);

Check failure

Code scanning / CodeQL

Suspicious add with sizeof High

Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is
nvme_ocp_common_dbg_evt_class_vu_data *
.
vu_event_id = pmedia_wear_event_vu_data->vu_event_identifier;
pdata = (__u8 *)&(pmedia_wear_event_vu_data->data);

parse_ocp_telemetry_string_log(0, vu_event_id,
pevent_descriptor->debug_event_class_type, VU_EVENT_STRING, description_str);
pevent_descriptor->debug_event_class_type,
VU_EVENT_STRING,
description_str);
}

if (pevent_fifos_object != NULL) {
Expand Down Expand Up @@ -983,6 +997,7 @@ int parse_event_fifo(unsigned int fifo_num, unsigned char *pfifo_start,
SIZE_OF_DWORD;

__u8 *pevent_specific_data = NULL;

if (pevent_descriptor != NULL && pevent_descriptor->event_data_size > 0)
pevent_specific_data = (__u8 *)pevent_descriptor + event_des_size;

Expand Down Expand Up @@ -1034,49 +1049,65 @@ int parse_event_fifo(unsigned int fifo_num, unsigned char *pfifo_start,
}

switch (pevent_descriptor->debug_event_class_type) {
case TIME_STAMP_CLASS_TYPE:
parse_time_stamp_event(pevent_descriptor, pevent_descriptor_obj,
pevent_specific_data, pevent_fifos_object, fp);
break;
case PCIE_CLASS_TYPE:
parse_pcie_event(pevent_descriptor, pevent_descriptor_obj,
pevent_specific_data, pevent_fifos_object, fp);
break;
case NVME_CLASS_TYPE:
parse_nvme_event(pevent_descriptor, pevent_descriptor_obj,
pevent_specific_data, pevent_fifos_object, fp);
break;
case RESET_CLASS_TYPE:
case BOOT_SEQUENCE_CLASS_TYPE:
case FIRMWARE_ASSERT_CLASS_TYPE:
case TEMPERATURE_CLASS_TYPE:
case MEDIA_CLASS_TYPE:
parse_common_event(pevent_descriptor, pevent_descriptor_obj,
pevent_specific_data, pevent_fifos_object, fp);
break;
case MEDIA_WEAR_CLASS_TYPE:
parse_media_wear_event(pevent_descriptor, pevent_descriptor_obj,
pevent_specific_data, pevent_fifos_object, fp);
break;
case STATISTIC_SNAPSHOT_CLASS_TYPE: {
struct nvme_ocp_statistic_snapshot_evt_class_format
*pStaticSnapshotEvent =
(struct nvme_ocp_statistic_snapshot_evt_class_format *)
pevent_specific_data;
struct nvme_ocp_telemetry_statistic_descriptor *pstatistic_entry =
(struct nvme_ocp_telemetry_statistic_descriptor *)
(&pStaticSnapshotEvent->statisticDescriptorData);

parse_statistic(pstatistic_entry, pevent_descriptor_obj, fp);
break;
}
case RESERVED_CLASS_TYPE:
default:
break;
case TIME_STAMP_CLASS_TYPE:
parse_time_stamp_event(pevent_descriptor,
pevent_descriptor_obj,
pevent_specific_data,
pevent_fifos_object,
fp);
break;
case PCIE_CLASS_TYPE:
parse_pcie_event(pevent_descriptor,
pevent_descriptor_obj,
pevent_specific_data,
pevent_fifos_object,
fp);
break;
case NVME_CLASS_TYPE:
parse_nvme_event(pevent_descriptor,
pevent_descriptor_obj,
pevent_specific_data,
pevent_fifos_object,
fp);
break;
case RESET_CLASS_TYPE:
case BOOT_SEQUENCE_CLASS_TYPE:
case FIRMWARE_ASSERT_CLASS_TYPE:
case TEMPERATURE_CLASS_TYPE:
case MEDIA_CLASS_TYPE:
parse_common_event(pevent_descriptor,
pevent_descriptor_obj,
pevent_specific_data,
pevent_fifos_object,
fp);
break;
case MEDIA_WEAR_CLASS_TYPE:
parse_media_wear_event(pevent_descriptor,
pevent_descriptor_obj,
pevent_specific_data,
pevent_fifos_object,
fp);
break;
case STATISTIC_SNAPSHOT_CLASS_TYPE: {
struct nvme_ocp_statistic_snapshot_evt_class_format
*pStaticSnapshotEvent =
(struct nvme_ocp_statistic_snapshot_evt_class_format *)
pevent_specific_data;
struct nvme_ocp_telemetry_statistic_descriptor *pstatistic_entry =
(struct nvme_ocp_telemetry_statistic_descriptor *)
(&pStaticSnapshotEvent->statisticDescriptorData);

parse_statistic(pstatistic_entry, pevent_descriptor_obj, fp);
break;
}
case RESERVED_CLASS_TYPE:
default:
break;
}

if (pevent_descriptor_obj != NULL && pevent_fifo_array != NULL)
json_array_add_value_object(pevent_fifo_array, pevent_descriptor_obj);
json_array_add_value_object(pevent_fifo_array,
pevent_descriptor_obj);
else {
if (fp)
fprintf(fp, STR_LINE2);
Expand All @@ -1086,7 +1117,8 @@ int parse_event_fifo(unsigned int fifo_num, unsigned char *pfifo_start,
} else
break;

offset_to_move += (pevent_descriptor->event_data_size * SIZE_OF_DWORD + event_des_size);
offset_to_move += (pevent_descriptor->event_data_size * SIZE_OF_DWORD +
event_des_size);
}

if (pevent_fifos_object != NULL && pevent_fifo_array != NULL)
Expand Down Expand Up @@ -1330,8 +1362,10 @@ int print_ocp_telemetry_normal(struct ocp_telemetry_parse_options *options)
(ARRAY_SIZE(host_log_page_header) == 0))
printf("skip generic_structure_parser\n");
else
generic_structure_parser(ptelemetry_buffer, host_log_page_header,
ARRAY_SIZE(host_log_page_header), NULL, 0, fp);
generic_structure_parser(ptelemetry_buffer,
host_log_page_header,
ARRAY_SIZE(host_log_page_header),
NULL, 0, fp);
}
else if (!strcmp(options->telemetry_type, "controller"))
generic_structure_parser(ptelemetry_buffer,
Expand Down

0 comments on commit 1da23bf

Please sign in to comment.