Bug Summary

File:dev/pci/drm/amd/amdgpu/amdgpu_fru_eeprom.c
Warning:line 41, column 23
Value stored to 'atom_ctx' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name amdgpu_fru_eeprom.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -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 static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -ffreestanding -mcmodel=kernel -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -target-feature -sse2 -target-feature -sse -target-feature -3dnow -target-feature -mmx -target-feature +save-args -disable-red-zone -no-implicit-float -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -nostdsysteminc -nobuiltininc -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/sys -I /usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -I /usr/src/sys/arch -I /usr/src/sys/dev/pci/drm/include -I /usr/src/sys/dev/pci/drm/include/uapi -I /usr/src/sys/dev/pci/drm/amd/include/asic_reg -I /usr/src/sys/dev/pci/drm/amd/include -I /usr/src/sys/dev/pci/drm/amd/amdgpu -I /usr/src/sys/dev/pci/drm/amd/display -I /usr/src/sys/dev/pci/drm/amd/display/include -I /usr/src/sys/dev/pci/drm/amd/display/dc -I /usr/src/sys/dev/pci/drm/amd/display/amdgpu_dm -I /usr/src/sys/dev/pci/drm/amd/pm/inc -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu11 -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu12 -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/hwmgr -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/smumgr -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc/hw -I /usr/src/sys/dev/pci/drm/amd/display/dc/clk_mgr -I /usr/src/sys/dev/pci/drm/amd/display/modules/inc -I /usr/src/sys/dev/pci/drm/amd/display/modules/hdcp -I /usr/src/sys/dev/pci/drm/amd/display/dmub/inc -I /usr/src/sys/dev/pci/drm/i915 -D DDB -D DIAGNOSTIC -D KTRACE -D ACCOUNTING -D KMEMSTATS -D PTRACE -D POOL_DEBUG -D CRYPTO -D SYSVMSG -D SYSVSEM -D SYSVSHM -D UVM_SWAP_ENCRYPT -D FFS -D FFS2 -D FFS_SOFTUPDATES -D UFS_DIRHASH -D QUOTA -D EXT2FS -D MFS -D NFSCLIENT -D NFSSERVER -D CD9660 -D UDF -D MSDOSFS -D FIFO -D FUSE -D SOCKET_SPLICE -D TCP_ECN -D TCP_SIGNATURE -D INET6 -D IPSEC -D PPP_BSDCOMP -D PPP_DEFLATE -D PIPEX -D MROUTING -D MPLS -D BOOT_CONFIG -D USER_PCICONF -D APERTURE -D MTRR -D NTFS -D HIBERNATE -D PCIVERBOSE -D USBVERBOSE -D WSDISPLAY_COMPAT_USL -D WSDISPLAY_COMPAT_RAWKBD -D WSDISPLAY_DEFAULTSCREENS=6 -D X86EMU -D ONEWIREVERBOSE -D MULTIPROCESSOR -D MAXUSERS=80 -D _KERNEL -D CONFIG_DRM_AMD_DC_DCN3_0 -O2 -Wno-pointer-sign -Wno-address-of-packed-member -Wno-constant-conversion -Wno-unused-but-set-variable -Wno-gnu-folding-constant -fdebug-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -o /usr/obj/sys/arch/amd64/compile/GENERIC.MP/scan-build/2022-01-12-131800-47421-1 -x c /usr/src/sys/dev/pci/drm/amd/amdgpu/amdgpu_fru_eeprom.c
1/*
2 * Copyright 2019 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 */
23#include <linux/pci.h>
24
25#include "amdgpu.h"
26#include "amdgpu_i2c.h"
27#include "smu_v11_0_i2c.h"
28#include "atom.h"
29#include "amdgpu_fru_eeprom.h"
30
31#define I2C_PRODUCT_INFO_ADDR0xAC 0xAC
32#define I2C_PRODUCT_INFO_ADDR_SIZE0x2 0x2
33#define I2C_PRODUCT_INFO_OFFSET0xC0 0xC0
34
35static bool_Bool is_fru_eeprom_supported(struct amdgpu_device *adev)
36{
37 /* Only server cards have the FRU EEPROM
38 * TODO: See if we can figure this out dynamically instead of
39 * having to parse VBIOS versions.
40 */
41 struct atom_context *atom_ctx = adev->mode_info.atom_context;
Value stored to 'atom_ctx' during its initialization is never read
42
43 /* VBIOS is of the format ###-DXXXYY-##. For SKU identification,
44 * we can use just the "DXXX" portion. If there were more models, we
45 * could convert the 3 characters to a hex integer and use a switch
46 * for ease/speed/readability. For now, 2 string comparisons are
47 * reasonable and not too expensive
48 */
49 switch (adev->asic_type) {
50 case CHIP_VEGA20:
51#ifdef notyet
52 /* D161 and D163 are the VG20 server SKUs */
53 if (strnstr(atom_ctx->vbios_version, "D161",
54 sizeof(atom_ctx->vbios_version)) ||
55 strnstr(atom_ctx->vbios_version, "D163",
56 sizeof(atom_ctx->vbios_version)))
57 return true1;
58 else
59#endif
60 return false0;
61 default:
62 return false0;
63 }
64}
65
66static int amdgpu_fru_read_eeprom(struct amdgpu_device *adev, uint32_t addrptr,
67 unsigned char *buff)
68{
69 int ret, size;
70 struct i2c_msg msg = {
71 .addr = I2C_PRODUCT_INFO_ADDR0xAC,
72 .flags = I2C_M_RD0x0001,
73 .buf = buff,
74 };
75 buff[0] = 0;
76 buff[1] = addrptr;
77 msg.len = I2C_PRODUCT_INFO_ADDR_SIZE0x2 + 1;
78 ret = i2c_transfer(&adev->pm.smu_i2c, &msg, 1);
79
80 if (ret < 1) {
81 DRM_WARN("FRU: Failed to get size field")printk("\0014" "[" "drm" "] " "FRU: Failed to get size field"
)
;
82 return ret;
83 }
84
85 /* The size returned by the i2c requires subtraction of 0xC0 since the
86 * size apparently always reports as 0xC0+actual size.
87 */
88 size = buff[2] - I2C_PRODUCT_INFO_OFFSET0xC0;
89 /* Add 1 since address field was 1 byte */
90 buff[1] = addrptr + 1;
91
92 msg.len = I2C_PRODUCT_INFO_ADDR_SIZE0x2 + size;
93 ret = i2c_transfer(&adev->pm.smu_i2c, &msg, 1);
94
95 if (ret < 1) {
96 DRM_WARN("FRU: Failed to get data field")printk("\0014" "[" "drm" "] " "FRU: Failed to get data field"
)
;
97 return ret;
98 }
99
100 return size;
101}
102
103int amdgpu_fru_get_product_info(struct amdgpu_device *adev)
104{
105 unsigned char buff[34];
106 int addrptr, size;
107 int len;
108
109 if (!is_fru_eeprom_supported(adev))
110 return 0;
111
112 /* If algo exists, it means that the i2c_adapter's initialized */
113 if (!adev->pm.smu_i2c.algo) {
114 DRM_WARN("Cannot access FRU, EEPROM accessor not initialized")printk("\0014" "[" "drm" "] " "Cannot access FRU, EEPROM accessor not initialized"
)
;
115 return -ENODEV19;
116 }
117
118 /* There's a lot of repetition here. This is due to the FRU having
119 * variable-length fields. To get the information, we have to find the
120 * size of each field, and then keep reading along and reading along
121 * until we get all of the data that we want. We use addrptr to track
122 * the address as we go
123 */
124
125 /* The first fields are all of size 1-byte, from 0-7 are offsets that
126 * contain information that isn't useful to us.
127 * Bytes 8-a are all 1-byte and refer to the size of the entire struct,
128 * and the language field, so just start from 0xb, manufacturer size
129 */
130 addrptr = 0xb;
131 size = amdgpu_fru_read_eeprom(adev, addrptr, buff);
132 if (size < 1) {
133 DRM_ERROR("Failed to read FRU Manufacturer, ret:%d", size)__drm_err("Failed to read FRU Manufacturer, ret:%d", size);
134 return -EINVAL22;
135 }
136
137 /* Increment the addrptr by the size of the field, and 1 due to the
138 * size field being 1 byte. This pattern continues below.
139 */
140 addrptr += size + 1;
141 size = amdgpu_fru_read_eeprom(adev, addrptr, buff);
142 if (size < 1) {
143 DRM_ERROR("Failed to read FRU product name, ret:%d", size)__drm_err("Failed to read FRU product name, ret:%d", size);
144 return -EINVAL22;
145 }
146
147 len = size;
148 /* Product name should only be 32 characters. Any more,
149 * and something could be wrong. Cap it at 32 to be safe
150 */
151 if (len >= sizeof(adev->product_name)) {
152 DRM_WARN("FRU Product Number is larger than 32 characters. This is likely a mistake")printk("\0014" "[" "drm" "] " "FRU Product Number is larger than 32 characters. This is likely a mistake"
)
;
153 len = sizeof(adev->product_name) - 1;
154 }
155 /* Start at 2 due to buff using fields 0 and 1 for the address */
156 memcpy(adev->product_name, &buff[2], len)__builtin_memcpy((adev->product_name), (&buff[2]), (len
))
;
157 adev->product_name[len] = '\0';
158
159 addrptr += size + 1;
160 size = amdgpu_fru_read_eeprom(adev, addrptr, buff);
161 if (size < 1) {
162 DRM_ERROR("Failed to read FRU product number, ret:%d", size)__drm_err("Failed to read FRU product number, ret:%d", size);
163 return -EINVAL22;
164 }
165
166 len = size;
167 /* Product number should only be 16 characters. Any more,
168 * and something could be wrong. Cap it at 16 to be safe
169 */
170 if (len >= sizeof(adev->product_number)) {
171 DRM_WARN("FRU Product Number is larger than 16 characters. This is likely a mistake")printk("\0014" "[" "drm" "] " "FRU Product Number is larger than 16 characters. This is likely a mistake"
)
;
172 len = sizeof(adev->product_number) - 1;
173 }
174 memcpy(adev->product_number, &buff[2], len)__builtin_memcpy((adev->product_number), (&buff[2]), (
len))
;
175 adev->product_number[len] = '\0';
176
177 addrptr += size + 1;
178 size = amdgpu_fru_read_eeprom(adev, addrptr, buff);
179
180 if (size < 1) {
181 DRM_ERROR("Failed to read FRU product version, ret:%d", size)__drm_err("Failed to read FRU product version, ret:%d", size);
182 return -EINVAL22;
183 }
184
185 addrptr += size + 1;
186 size = amdgpu_fru_read_eeprom(adev, addrptr, buff);
187
188 if (size < 1) {
189 DRM_ERROR("Failed to read FRU serial number, ret:%d", size)__drm_err("Failed to read FRU serial number, ret:%d", size);
190 return -EINVAL22;
191 }
192
193 len = size;
194 /* Serial number should only be 16 characters. Any more,
195 * and something could be wrong. Cap it at 16 to be safe
196 */
197 if (len >= sizeof(adev->serial)) {
198 DRM_WARN("FRU Serial Number is larger than 16 characters. This is likely a mistake")printk("\0014" "[" "drm" "] " "FRU Serial Number is larger than 16 characters. This is likely a mistake"
)
;
199 len = sizeof(adev->serial) - 1;
200 }
201 memcpy(adev->serial, &buff[2], len)__builtin_memcpy((adev->serial), (&buff[2]), (len));
202 adev->serial[len] = '\0';
203
204 return 0;
205}