Bug Summary

File:dev/cardbus/cardbus_map.c
Warning:line 115, column 12
Assigned value is garbage or undefined

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 cardbus_map.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/cardbus/cardbus_map.c
1/* $OpenBSD: cardbus_map.c,v 1.15 2015/03/14 03:38:47 jsg Exp $ */
2/* $NetBSD: cardbus_map.c,v 1.10 2000/03/07 00:31:46 mycroft Exp $ */
3
4/*
5 * Copyright (c) 1999 and 2000
6 * HAYAKAWA Koichi. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31
32#include <sys/param.h>
33#include <sys/systm.h>
34
35#include <machine/bus.h>
36
37#include <dev/cardbus/cardbusvar.h>
38
39#include <dev/pci/pcireg.h> /* XXX */
40
41#if defined DEBUG && !defined CARDBUS_MAP_DEBUG
42#define CARDBUS_MAP_DEBUG
43#endif
44
45#if defined CARDBUS_MAP_DEBUG
46#define STATIC
47#define DPRINTF(a) printf a
48#else
49#ifdef DDB1
50#define STATIC
51#else
52#define STATIC static
53#endif
54#define DPRINTF(a)
55#endif
56
57/*
58 * int cardbus_mapreg_map(struct cardbus_softc *, int, int, pcireg_t,
59 * int bus_space_tag_t *, bus_space_handle_t *,
60 * bus_addr_t *, bus_size_t *)
61 * This function maps bus-space on the value of Base Address
62 * Register (BAR) indexed by the argument `reg' (the second argument).
63 * When the value of the BAR is not valid, such as 0x00000000, a new
64 * address should be allocated for the BAR and new address values is
65 * written on the BAR.
66 */
67int
68cardbus_mapreg_map(struct cardbus_softc *sc, int func, int reg,
69 pcireg_t type, int busflags, bus_space_tag_t *tagp,
70 bus_space_handle_t *handlep, bus_addr_t *basep, bus_size_t *sizep)
71{
72 cardbus_chipset_tag_t cc = sc->sc_cc;
73 pci_chipset_tag_t pc = sc->sc_pc;
74 cardbus_function_tag_t cf = sc->sc_cf;
75 bus_space_tag_t bustag;
76 rbus_tag_t rbustag;
77 bus_space_handle_t handle;
1
'handle' declared without an initial value
78 bus_addr_t base;
79 bus_size_t size;
80 int flags;
81 int status = 0;
82
83 pcitag_t tag = pci_make_tag(pc, sc->sc_bus,
84 sc->sc_device, func);
85
86 DPRINTF(("cardbus_mapreg_map called: %s %x\n", sc->sc_dev.dv_xname,
87 type));
88
89 if (pci_mapreg_info(pc, tag, reg, type, &base, &size, &flags))
2
Assuming the condition is true
3
Taking true branch
90 status = 1;
91
92 if (PCI_MAPREG_TYPE(type)((type) & 0x00000001) == PCI_MAPREG_TYPE_IO0x00000001) {
4
Assuming the condition is false
5
Taking false branch
93 bustag = sc->sc_iot;
94 rbustag = sc->sc_rbus_iot;
95 } else {
96 bustag = sc->sc_memt;
97 rbustag = sc->sc_rbus_memt;
98 }
99 if (status
5.1
'status' is not equal to 0
== 0) {
6
Taking false branch
100 bus_addr_t mask = size - 1;
101 if (base != 0)
102 mask = 0xffffffff;
103 if ((*cf->cardbus_space_alloc)(cc, rbustag, base, size, mask,
104 size, busflags | flags, &base, &handle)) {
105 panic("io alloc");
106 }
107 }
108 pci_conf_write(pc, tag, reg, base);
109
110 DPRINTF(("cardbus_mapreg_map: physaddr %lx\n", (unsigned long)base));
111
112 if (tagp != 0)
7
Assuming 'tagp' is equal to null
8
Taking false branch
113 *tagp = bustag;
114 if (handlep != 0)
9
Assuming 'handlep' is not equal to null
10
Taking true branch
115 *handlep = handle;
11
Assigned value is garbage or undefined
116 if (basep != 0)
117 *basep = base;
118 if (sizep != 0)
119 *sizep = size;
120
121 return (0);
122}
123
124/*
125 * int cardbus_mapreg_unmap(struct cardbus_softc *sc, int func, int reg,
126 * bus_space_tag_t tag, bus_space_handle_t handle,
127 * bus_size_t size)
128 *
129 * This function releases bus-space region and close memory or io
130 * window on the bridge.
131 *
132 * Arguments:
133 * struct cardbus_softc *sc; the pointer to the device structure of cardbus.
134 * int func; the number of function on the device.
135 * int reg; the offset of BAR register.
136 */
137int
138cardbus_mapreg_unmap(struct cardbus_softc *sc, int func, int reg,
139 bus_space_tag_t tag, bus_space_handle_t handle, bus_size_t size)
140{
141 cardbus_chipset_tag_t cc = sc->sc_cc;
142 pci_chipset_tag_t pc = sc->sc_pc;
143 cardbus_function_tag_t cf = sc->sc_cf;
144 int st = 1;
145 pcitag_t cardbustag;
146 rbus_tag_t rbustag;
147
148 if (sc->sc_iot == tag) {
149 /* bus space is io space */
150 DPRINTF(("%s: unmap i/o space\n", sc->sc_dev.dv_xname));
151 rbustag = sc->sc_rbus_iot;
152 } else if (sc->sc_memt == tag) {
153 /* bus space is memory space */
154 DPRINTF(("%s: unmap mem space\n", sc->sc_dev.dv_xname));
155 rbustag = sc->sc_rbus_memt;
156 } else
157 return (1);
158
159 cardbustag = pci_make_tag(pc, sc->sc_bus, sc->sc_device, func);
160
161 pci_conf_write(pc, cardbustag, reg, 0);
162
163 (*cf->cardbus_space_free)(cc, rbustag, handle, size);
164
165 return (st);
166}