Bug Summary

File:arch/amd64/amd64/dkcsum.c
Warning:line 125, column 4
Value stored to 'error' 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 dkcsum.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/arch/amd64/amd64/dkcsum.c
1/* $OpenBSD: dkcsum.c,v 1.21 2014/09/14 14:17:23 jsg Exp $ */
2
3/*-
4 * Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27/*
28 * A checksumming pseudo device used to get unique labels of each disk
29 * that needs to be matched to BIOS disks.
30 */
31
32#include <sys/param.h>
33#include <sys/buf.h>
34#include <sys/conf.h>
35#include <sys/device.h>
36#include <sys/disklabel.h>
37#include <sys/fcntl.h>
38#include <sys/reboot.h>
39#include <sys/stat.h>
40#include <sys/systm.h>
41
42#include <machine/biosvar.h>
43
44#include <lib/libz/zlib.h>
45
46dev_t dev_rawpart(struct device *); /* XXX */
47
48extern u_int32_t bios_cksumlen;
49extern bios_diskinfo_t *bios_diskinfo;
50extern dev_t bootdev;
51
52void
53dkcsumattach(void)
54{
55 struct device *dv;
56 struct buf *bp;
57 struct bdevsw *bdsw;
58 dev_t dev, pribootdev, altbootdev;
59 int error, picked;
60 u_int32_t csum;
61 bios_diskinfo_t *bdi, *hit;
62
63 /* do nothing if no diskinfo passed from /boot, or a bad length */
64 if (bios_diskinfo == NULL((void *)0) || bios_cksumlen * DEV_BSIZE(1 << 9) > MAXBSIZE(64 * 1024))
65 return;
66
67 /* Do nothing if bootdev is a CD drive. */
68 if (B_TYPE(bootdev)(((bootdev) >> 0) & 0xff) == 6)
69 return;
70
71#ifdef DEBUG
72 printf("dkcsum: bootdev=%#x\n", bootdev);
73 for (bdi = bios_diskinfo; bdi->bios_number != -1; bdi++) {
74 if (bdi->bios_number & 0x80) {
75 printf("dkcsum: BIOS drive %#x bsd_dev=%#x "
76 "checksum=%#x\n", bdi->bios_number, bdi->bsd_dev,
77 bdi->checksum);
78 }
79 }
80#endif
81 pribootdev = altbootdev = 0;
82
83 /*
84 * XXX What if DEV_BSIZE is changed to something else than the BIOS
85 * blocksize? Today, /boot doesn't cover that case so neither need
86 * I care here.
87 */
88 bp = geteblk(bios_cksumlen * DEV_BSIZE(1 << 9)); /* XXX error check? */
89
90 TAILQ_FOREACH(dv, &alldevs, dv_list)for((dv) = ((&alldevs)->tqh_first); (dv) != ((void *)0
); (dv) = ((dv)->dv_list.tqe_next))
{
91 if (dv->dv_class != DV_DISK)
92 continue;
93 bp->b_dev = dev = dev_rawpart(dv);
94 if (dev == NODEV(dev_t)(-1))
95 continue;
96 bdsw = &bdevsw[major(dev)(((unsigned)(dev) >> 8) & 0xff)];
97
98 /*
99 * This open operation guarantees a proper initialization
100 * of the device, for future strategy calls.
101 */
102 error = (*bdsw->d_open)(dev, FREAD0x0001, S_IFCHR0020000, curproc({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r"
(__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self)));
__ci;})->ci_curproc
);
103 if (error) {
104 /* XXX What to do here? */
105#ifdef DEBUG
106 printf("dkcsum: %s open failed (%d)\n",
107 dv->dv_xname, error);
108#endif
109 continue;
110 }
111
112 /* Read blocks to cksum. XXX maybe a d_read should be used. */
113 bp->b_blkno = 0;
114 bp->b_bcount = bios_cksumlen * DEV_BSIZE(1 << 9);
115 bp->b_error = 0; /* B_ERROR and b_error may have stale data. */
116 CLR(bp->b_flags, B_READ | B_WRITE | B_DONE | B_ERROR)((bp->b_flags) &= ~(0x00008000 | 0x00000000 | 0x00000100
| 0x00000400))
;
117 SET(bp->b_flags, B_BUSY | B_READ | B_RAW)((bp->b_flags) |= (0x00000010 | 0x00008000 | 0x00004000));
118 (*bdsw->d_strategy)(bp);
119 if ((error = biowait(bp))) {
120 /* XXX What to do here? */
121#ifdef DEBUG
122 printf("dkcsum: %s read failed (%d)\n",
123 dv->dv_xname, error);
124#endif
125 error = (*bdsw->d_close)(dev, 0, S_IFCHR0020000, curproc({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r"
(__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self)));
__ci;})->ci_curproc
)
;
Value stored to 'error' is never read
126#ifdef DEBUG
127 if (error)
128 printf("dkcsum: %s close failed (%d)\n",
129 dv->dv_xname, error);
130#endif
131 continue;
132 }
133 error = (*bdsw->d_close)(dev, FREAD0x0001, S_IFCHR0020000, curproc({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r"
(__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self)));
__ci;})->ci_curproc
);
134 if (error) {
135 /* XXX What to do here? */
136#ifdef DEBUG
137 printf("dkcsum: %s closed failed (%d)\n",
138 dv->dv_xname, error);
139#endif
140 continue;
141 }
142
143 csum = adler32(0, bp->b_data, bios_cksumlen * DEV_BSIZE(1 << 9));
144#ifdef DEBUG
145 printf("dkcsum: %s checksum is %#x\n", dv->dv_xname, csum);
146#endif
147
148 /* Find the BIOS device */
149 hit = 0;
150 for (bdi = bios_diskinfo; bdi->bios_number != -1; bdi++) {
151 /* Skip non-harddrives */
152 if (!(bdi->bios_number & 0x80))
153 continue;
154 if (bdi->checksum != csum)
155 continue;
156 picked = hit || (bdi->flags & BDI_PICKED0x80000000);
157 if (!picked)
158 hit = bdi;
159#ifdef DEBUG
160 printf("dkcsum: %s matches BIOS drive %#x%s\n",
161 dv->dv_xname, bdi->bios_number,
162 (picked ? " IGNORED" : ""));
163#endif
164 }
165
166 /*
167 * If we have no hit, that's OK, we can see a lot more devices
168 * than the BIOS can, so this case is pretty normal.
169 */
170 if (!hit) {
171#ifdef DEBUG
172 printf("dkcsum: %s has no matching BIOS drive\n",
173 dv->dv_xname);
174#endif
175 continue;
176 }
177
178 /*
179 * Fixup bootdev if units match. This means that all of
180 * hd*, sd*, wd*, will be interpreted the same. Not 100%
181 * backwards compatible, but sd* and wd* should be phased-
182 * out in the bootblocks.
183 */
184
185 /* B_TYPE dependent hd unit counting bootblocks */
186 if ((B_ADAPTOR(bootdev)(((bootdev) >> 24) & 0x0f) == B_ADAPTOR(hit->bsd_dev)(((hit->bsd_dev) >> 24) & 0x0f)) &&
187 (B_CONTROLLER(bootdev)(((bootdev)>>20) & 0xf) == B_CONTROLLER(hit->bsd_dev)(((hit->bsd_dev)>>20) & 0xf)) &&
188 (B_TYPE(bootdev)(((bootdev) >> 0) & 0xff) == B_TYPE(hit->bsd_dev)(((hit->bsd_dev) >> 0) & 0xff)) &&
189 (B_UNIT(bootdev)(((bootdev) >> 16) & 0xf) == B_UNIT(hit->bsd_dev)(((hit->bsd_dev) >> 16) & 0xf))) {
190 int type, ctrl, adap, part, unit;
191
192 type = major(bp->b_dev)(((unsigned)(bp->b_dev) >> 8) & 0xff);
193 adap = B_ADAPTOR(bootdev)(((bootdev) >> 24) & 0x0f);
194 ctrl = B_CONTROLLER(bootdev)(((bootdev)>>20) & 0xf);
195 unit = DISKUNIT(bp->b_dev)(((unsigned)((bp->b_dev) & 0xff) | (((bp->b_dev) &
0xffff0000) >> 8)) / 16)
;
196 part = B_PARTITION(bootdev)(((bootdev) >> 8) & 0xff);
197
198 pribootdev = MAKEBOOTDEV(type, ctrl, adap, unit, part)(((type) << 0) | ((ctrl) << 24) | ((adap) <<
20) | ((unit) << 16) | ((part) << 8) | 0xa0000000
)
;
199#ifdef DEBUG
200 printf("dkcsum: %s is primary boot disk\n",
201 dv->dv_xname);
202#endif
203 }
204 /* B_TYPE independent hd unit counting bootblocks */
205 if (B_UNIT(bootdev)(((bootdev) >> 16) & 0xf) == (hit->bios_number & 0x7F)) {
206 int type, ctrl, adap, part, unit;
207
208 type = major(bp->b_dev)(((unsigned)(bp->b_dev) >> 8) & 0xff);
209 adap = B_ADAPTOR(bootdev)(((bootdev) >> 24) & 0x0f);
210 ctrl = B_CONTROLLER(bootdev)(((bootdev)>>20) & 0xf);
211 unit = DISKUNIT(bp->b_dev)(((unsigned)((bp->b_dev) & 0xff) | (((bp->b_dev) &
0xffff0000) >> 8)) / 16)
;
212 part = B_PARTITION(bootdev)(((bootdev) >> 8) & 0xff);
213
214 altbootdev = MAKEBOOTDEV(type, ctrl, adap, unit, part)(((type) << 0) | ((ctrl) << 24) | ((adap) <<
20) | ((unit) << 16) | ((part) << 8) | 0xa0000000
)
;
215#ifdef DEBUG
216 printf("dkcsum: %s is alternate boot disk\n",
217 dv->dv_xname);
218#endif
219 }
220
221 /* This will overwrite /boot's guess, just so you remember */
222 hit->bsd_dev = MAKEBOOTDEV(major(bp->b_dev), 0, 0,((((((unsigned)(bp->b_dev) >> 8) & 0xff)) <<
0) | ((0) << 24) | ((0) << 20) | (((((unsigned)(
(bp->b_dev) & 0xff) | (((bp->b_dev) & 0xffff0000
) >> 8)) / 16)) << 16) | ((2) << 8) | 0xa0000000
)
223 DISKUNIT(bp->b_dev), RAW_PART)((((((unsigned)(bp->b_dev) >> 8) & 0xff)) <<
0) | ((0) << 24) | ((0) << 20) | (((((unsigned)(
(bp->b_dev) & 0xff) | (((bp->b_dev) & 0xffff0000
) >> 8)) / 16)) << 16) | ((2) << 8) | 0xa0000000
)
;
224 hit->flags |= BDI_PICKED0x80000000;
225 }
226 bootdev = pribootdev ? pribootdev : altbootdev ? altbootdev : bootdev;
227
228 bp->b_flags |= B_INVAL0x00000800;
229 brelse(bp);
230}