Bug Summary

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'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name ocp-smart-extended-log.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/__w/nvme-cli/nvme-cli/.build-ci -fcoverage-compilation-dir=/__w/nvme-cli/nvme-cli/.build-ci -resource-dir /usr/lib/llvm-19/lib/clang/19 -include /__w/nvme-cli/nvme-cli/.build-ci/nvme-config.h -I nvme.p -I . -I .. -I ccan -I ../ccan -I libnvme/src -I ../libnvme/src -I /usr/include/json-c -D _FILE_OFFSET_BITS=64 -D _GNU_SOURCE -U NDEBUG -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -std=gnu99 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-opt-analyze-headers -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /__w/nvme-cli/nvme-cli/.build-ci/scan-results/2026-06-24-175442-590-1 -x c ../plugins/ocp/ocp-smart-extended-log.c
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
22static __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
29static 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
93out:
94 free(data);
95 return ret;
96}
97
98int 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}