| File: | .build-ci/../plugins/ocp/ocp-smart-extended-log.c |
| Warning: | line 45, column 9 Result of 'malloc' is converted to a pointer of type 'struct ocp_smart_extended_log', which is incompatible with sizeof operand type '__u8' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* Copyright (c) 2022 Meta Platforms, Inc. |
| 3 | * |
| 4 | * Authors: Arthur Shau <arthurshau@fb.com>, |
| 5 | * Wei Zhang <wzhang@fb.com>, |
| 6 | * Venkat Ramesh <venkatraghavan@fb.com> |
| 7 | */ |
| 8 | |
| 9 | #include <errno(*__errno_location ()).h> |
| 10 | #include <stdio.h> |
| 11 | |
| 12 | #include "common.h" |
| 13 | #include "nvme-print.h" |
| 14 | #include "ocp-nvme.h" |
| 15 | #include "ocp-print.h" |
| 16 | #include "ocp-smart-extended-log.h" |
| 17 | #include "ocp-utils.h" |
| 18 | |
| 19 | /* C0 SCAO Log Page */ |
| 20 | #define C0_SMART_CLOUD_ATTR_LEN0x200 0x200 |
| 21 | |
| 22 | static __u8 scao_guid[GUID_LEN16] = { |
| 23 | 0xC5, 0xAF, 0x10, 0x28, |
| 24 | 0xEA, 0xBF, 0xF2, 0xA4, |
| 25 | 0x9C, 0x4F, 0x6F, 0x7C, |
| 26 | 0xC9, 0x14, 0xD5, 0xAF |
| 27 | }; |
| 28 | |
| 29 | static int get_c0_log_page(struct libnvme_transport_handle *hdl, char *format, |
| 30 | unsigned int format_version) |
| 31 | { |
| 32 | struct ocp_smart_extended_log *data; |
| 33 | struct libnvme_passthru_cmd cmd; |
| 34 | nvme_print_flags_t fmt; |
| 35 | __u8 uidx; |
| 36 | int ret; |
| 37 | int i; |
| 38 | |
| 39 | ret = validate_output_format(format, &fmt); |
| 40 | if (ret < 0) { |
| 41 | fprintf(stderrstderr, "ERROR : OCP : invalid output format\n"); |
| 42 | return ret; |
| 43 | } |
| 44 | |
| 45 | data = malloc(sizeof(__u8) * C0_SMART_CLOUD_ATTR_LEN0x200); |
Result of 'malloc' is converted to a pointer of type 'struct ocp_smart_extended_log', which is incompatible with sizeof operand type '__u8' | |
| 46 | if (!data) { |
| 47 | fprintf(stderrstderr, "ERROR : OCP : malloc : %s\n", libnvme_strerror(errno(*__errno_location ()))); |
| 48 | return -1; |
| 49 | } |
| 50 | memset(data, 0, sizeof(__u8) * C0_SMART_CLOUD_ATTR_LEN0x200); |
| 51 | |
| 52 | ocp_get_uuid_index(hdl, &uidx); |
| 53 | nvme_init_get_log(&cmd, NVME_NSID_ALL, |
| 54 | (enum nvme_cmd_get_log_lid)OCP_LID_SMART, |
| 55 | NVME_CSI_NVM, data, C0_SMART_CLOUD_ATTR_LEN0x200); |
| 56 | cmd.cdw14 |= NVME_FIELD_ENCODE(uidx,(((__u32)(uidx) & (NVME_LOG_CDW14_UUID_MASK)) << (NVME_LOG_CDW14_UUID_SHIFT )) |
| 57 | NVME_LOG_CDW14_UUID_SHIFT,(((__u32)(uidx) & (NVME_LOG_CDW14_UUID_MASK)) << (NVME_LOG_CDW14_UUID_SHIFT )) |
| 58 | NVME_LOG_CDW14_UUID_MASK)(((__u32)(uidx) & (NVME_LOG_CDW14_UUID_MASK)) << (NVME_LOG_CDW14_UUID_SHIFT )); |
| 59 | ret = libnvme_get_log(hdl, &cmd, false0, NVME_LOG_PAGE_PDU_SIZE4096); |
| 60 | |
| 61 | if (strcmp(format, "json")) |
| 62 | fprintf(stderrstderr, "NVMe Status:%s(%x)\n", |
| 63 | libnvme_status_to_string(ret, false0), ret); |
| 64 | |
| 65 | if (ret == 0) { |
| 66 | /* check log page guid */ |
| 67 | /* Verify GUID matches */ |
| 68 | for (i = 0; i < 16; i++) { |
| 69 | if (scao_guid[i] != data->log_page_guid[i]) { |
| 70 | int j; |
| 71 | |
| 72 | fprintf(stderrstderr, "ERROR : OCP : Unknown GUID in C0 Log Page data\n"); |
| 73 | fprintf(stderrstderr, "ERROR : OCP : Expected GUID: 0x"); |
| 74 | for (j = 0; j < 16; j++) |
| 75 | fprintf(stderrstderr, "%x", scao_guid[j]); |
| 76 | |
| 77 | fprintf(stderrstderr, "\nERROR : OCP : Actual GUID: 0x"); |
| 78 | for (j = 0; j < 16; j++) |
| 79 | fprintf(stderrstderr, "%x", data->log_page_guid[j]); |
| 80 | fprintf(stderrstderr, "\n"); |
| 81 | |
| 82 | ret = -1; |
| 83 | goto out; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /* print the data */ |
| 88 | ocp_smart_extended_log(data, format_version, fmt); |
| 89 | } else { |
| 90 | fprintf(stderrstderr, "ERROR : OCP : Unable to read C0 data from buffer\n"); |
| 91 | } |
| 92 | |
| 93 | out: |
| 94 | free(data); |
| 95 | return ret; |
| 96 | } |
| 97 | |
| 98 | int ocp_smart_add_log(int argc, char **argv, struct command *acmd, |
| 99 | struct plugin *plugin) |
| 100 | { |
| 101 | const char *desc = "Retrieve the extended SMART health data."; |
| 102 | __cleanup_nvme_global_ctx__attribute__((cleanup(cleanup_nvme_global_ctx))) struct libnvme_global_ctx *ctx = NULL((void*)0); |
| 103 | __cleanup_nvme_transport_handle__attribute__((cleanup(cleanup_nvme_transport_handle))) struct libnvme_transport_handle *hdl = NULL((void*)0); |
| 104 | int ret = 0; |
| 105 | |
| 106 | NVME_ARGS(opts)struct argconfig_commandline_options opts[] = { {"", 0, ((void *)0), CFG_GROUP_SEPARATOR, ((void*)0), 0, "Options", 0, ((void *)0)}, {"", 0, ((void*)0), CFG_GROUP_SEPARATOR, ((void*)0), 0 , "Global options", 0, ((void*)0)}, {"verbose", 'v', "NUM", CFG_INCREMENT , &nvme_args.verbose, 0, "Increase output verbosity", 0, } , {"output-format", 'o', "FMT", CFG_STRING, &nvme_args.output_format , 1, "Output format: normal|json|binary|tabular", 0, }, {"timeout" , 0, "NUM", CFG_POSITIVE, &nvme_args.timeout, 1, "timeout value, in milliseconds" , 0, }, {"dry-run", 0, ((void*)0), CFG_FLAG, &nvme_args.dry_run , 0, "show command instead of executing", 0, }, {"no-retries" , 0, ((void*)0), CFG_FLAG, &nvme_args.no_retries, 0, "disable retry logic on errors" , 0, }, {"no-ioctl-probing", 0, ((void*)0), CFG_FLAG, &nvme_args .no_ioctl_probing, 0, "disable 64-bit IOCTL support probing", 0, }, {"output-format-version", 0, "NUM", CFG_POSITIVE, & nvme_args.output_format_ver, 1, "output format version: 1|2", 0, }, {"human-readable", 'H', ((void*)0), CFG_FLAG, &nvme_args .verbose, 0, ((void*)0), 0, ((void*)0), 1}, { ((void*)0) } }; |
| 107 | |
| 108 | ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); |
| 109 | if (ret) |
| 110 | return ret; |
| 111 | |
| 112 | ret = get_c0_log_page(hdl, nvme_args.output_format, |
| 113 | nvme_args.output_format_ver); |
| 114 | if (ret) |
| 115 | fprintf(stderrstderr, "ERROR : OCP : Failure reading the C0 Log Page, ret = %d\n", |
| 116 | ret); |
| 117 | return ret; |
| 118 | } |