Bug Summary

File:dev/pci/drm/drm_irq.c
Warning:line 126, column 3
Value stored to 'sh_flags' 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 drm_irq.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/drm_irq.c
1/*
2 * drm_irq.c IRQ and vblank support
3 *
4 * \author Rickard E. (Rik) Faith <faith@valinux.com>
5 * \author Gareth Hughes <gareth@valinux.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27/*
28 * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
29 *
30 * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
31 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
32 * All Rights Reserved.
33 *
34 * Permission is hereby granted, free of charge, to any person obtaining a
35 * copy of this software and associated documentation files (the "Software"),
36 * to deal in the Software without restriction, including without limitation
37 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
38 * and/or sell copies of the Software, and to permit persons to whom the
39 * Software is furnished to do so, subject to the following conditions:
40 *
41 * The above copyright notice and this permission notice (including the next
42 * paragraph) shall be included in all copies or substantial portions of the
43 * Software.
44 *
45 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
49 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
50 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
51 * OTHER DEALINGS IN THE SOFTWARE.
52 */
53
54
55#include <linux/export.h>
56#include <linux/interrupt.h> /* For task queue support */
57#include <linux/pci.h>
58#include <linux/vgaarb.h>
59
60#include <drm/drm.h>
61#include <drm/drm_device.h>
62#include <drm/drm_drv.h>
63#include <drm/drm_irq.h>
64#include <drm/drm_print.h>
65#include <drm/drm_vblank.h>
66
67#include "drm_internal.h"
68
69/**
70 * DOC: irq helpers
71 *
72 * The DRM core provides very simple support helpers to enable IRQ handling on a
73 * device through the drm_irq_install() and drm_irq_uninstall() functions. This
74 * only supports devices with a single interrupt on the main device stored in
75 * &drm_device.dev and set as the device paramter in drm_dev_alloc().
76 *
77 * These IRQ helpers are strictly optional. Drivers which roll their own only
78 * need to set &drm_device.irq_enabled to signal the DRM core that vblank
79 * interrupts are working. Since these helpers don't automatically clean up the
80 * requested interrupt like e.g. devm_request_irq() they're not really
81 * recommended.
82 */
83
84/**
85 * drm_irq_install - install IRQ handler
86 * @dev: DRM device
87 * @irq: IRQ number to install the handler for
88 *
89 * Initializes the IRQ related data. Installs the handler, calling the driver
90 * &drm_driver.irq_preinstall and &drm_driver.irq_postinstall functions before
91 * and after the installation.
92 *
93 * This is the simplified helper interface provided for drivers with no special
94 * needs. Drivers which need to install interrupt handlers for multiple
95 * interrupts must instead set &drm_device.irq_enabled to signal the DRM core
96 * that vblank interrupts are available.
97 *
98 * @irq must match the interrupt number that would be passed to request_irq(),
99 * if called directly instead of using this helper function.
100 *
101 * &drm_driver.irq_handler is called to handle the registered interrupt.
102 *
103 * Returns:
104 * Zero on success or a negative error code on failure.
105 */
106int drm_irq_install(struct drm_device *dev, int irq)
107{
108 int ret;
109 unsigned long sh_flags = 0;
110
111 if (irq == 0)
112 return -EINVAL22;
113
114 if (dev->irq_enabled)
115 return -EBUSY16;
116 dev->irq_enabled = true1;
117
118 DRM_DEBUG("irq=%d\n", irq)__drm_dbg(DRM_UT_CORE, "irq=%d\n", irq);
119
120 /* Before installing handler */
121 if (dev->driver->irq_preinstall)
122 dev->driver->irq_preinstall(dev);
123
124 /* PCI devices require shared interrupts. */
125 if (dev->pdev)
126 sh_flags = IRQF_SHARED0;
Value stored to 'sh_flags' is never read
127
128 ret = request_irq(irq, dev->driver->irq_handler,(0)
129 sh_flags, dev->driver->name, dev)(0);
130
131 if (ret < 0) {
132 dev->irq_enabled = false0;
133 return ret;
134 }
135
136 /* After installing handler */
137 if (dev->driver->irq_postinstall)
138 ret = dev->driver->irq_postinstall(dev);
139
140 if (ret < 0) {
141 dev->irq_enabled = false0;
142 if (drm_core_check_feature(dev, DRIVER_LEGACY))
143 vga_client_register(dev->pdev, NULL((void *)0), NULL((void *)0), NULL((void *)0));
144 free_irq(irq, dev);
145 } else {
146 dev->irq = irq;
147 }
148
149 return ret;
150}
151EXPORT_SYMBOL(drm_irq_install);
152
153/**
154 * drm_irq_uninstall - uninstall the IRQ handler
155 * @dev: DRM device
156 *
157 * Calls the driver's &drm_driver.irq_uninstall function and unregisters the IRQ
158 * handler. This should only be called by drivers which used drm_irq_install()
159 * to set up their interrupt handler. Other drivers must only reset
160 * &drm_device.irq_enabled to false.
161 *
162 * Note that for kernel modesetting drivers it is a bug if this function fails.
163 * The sanity checks are only to catch buggy user modesetting drivers which call
164 * the same function through an ioctl.
165 *
166 * Returns:
167 * Zero on success or a negative error code on failure.
168 */
169int drm_irq_uninstall(struct drm_device *dev)
170{
171 unsigned long irqflags;
172 bool_Bool irq_enabled;
173 int i;
174
175 irq_enabled = dev->irq_enabled;
176 dev->irq_enabled = false0;
177
178 /*
179 * Wake up any waiters so they don't hang. This is just to paper over
180 * issues for UMS drivers which aren't in full control of their
181 * vblank/irq handling. KMS drivers must ensure that vblanks are all
182 * disabled when uninstalling the irq handler.
183 */
184 if (drm_dev_has_vblank(dev)) {
185 spin_lock_irqsave(&dev->vbl_lock, irqflags)do { irqflags = 0; mtx_enter(&dev->vbl_lock); } while (
0)
;
186 for (i = 0; i < dev->num_crtcs; i++) {
187 struct drm_vblank_crtc *vblank = &dev->vblank[i];
188
189 if (!vblank->enabled)
190 continue;
191
192 WARN_ON(drm_core_check_feature(dev, DRIVER_MODESET))({ int __ret = !!(drm_core_check_feature(dev, DRIVER_MODESET)
); if (__ret) printf("WARNING %s failed at %s:%d\n", "drm_core_check_feature(dev, DRIVER_MODESET)"
, "/usr/src/sys/dev/pci/drm/drm_irq.c", 192); __builtin_expect
(!!(__ret), 0); })
;
193
194 drm_vblank_disable_and_save(dev, i);
195 wake_up(&vblank->queue);
196 }
197 spin_unlock_irqrestore(&dev->vbl_lock, irqflags)do { (void)(irqflags); mtx_leave(&dev->vbl_lock); } while
(0)
;
198 }
199
200 if (!irq_enabled)
201 return -EINVAL22;
202
203 DRM_DEBUG("irq=%d\n", dev->irq)__drm_dbg(DRM_UT_CORE, "irq=%d\n", dev->irq);
204
205 if (drm_core_check_feature(dev, DRIVER_LEGACY))
206 vga_client_register(dev->pdev, NULL((void *)0), NULL((void *)0), NULL((void *)0));
207
208 if (dev->driver->irq_uninstall)
209 dev->driver->irq_uninstall(dev);
210
211 free_irq(dev->irq, dev);
212
213 return 0;
214}
215EXPORT_SYMBOL(drm_irq_uninstall);
216
217#if IS_ENABLED(CONFIG_DRM_LEGACY)0
218int drm_legacy_irq_control(struct drm_device *dev, void *data,
219 struct drm_file *file_priv)
220{
221 struct drm_control *ctl = data;
222 int ret = 0, irq;
223
224 /* if we haven't irq we fallback for compatibility reasons -
225 * this used to be a separate function in drm_dma.h
226 */
227
228 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
229 return 0;
230 if (!drm_core_check_feature(dev, DRIVER_LEGACY))
231 return 0;
232 /* UMS was only ever supported on pci devices. */
233 if (WARN_ON(!dev->pdev)({ int __ret = !!(!dev->pdev); if (__ret) printf("WARNING %s failed at %s:%d\n"
, "!dev->pdev", "/usr/src/sys/dev/pci/drm/drm_irq.c", 233)
; __builtin_expect(!!(__ret), 0); })
)
234 return -EINVAL22;
235
236 switch (ctl->func) {
237 case DRM_INST_HANDLER:
238 irq = dev->pdev->irq;
239
240 if (dev->if_version < DRM_IF_VERSION(1, 2)(1 << 16 | 2) &&
241 ctl->irq != irq)
242 return -EINVAL22;
243 mutex_lock(&dev->struct_mutex)rw_enter_write(&dev->struct_mutex);
244 ret = drm_irq_install(dev, irq);
245 mutex_unlock(&dev->struct_mutex)rw_exit_write(&dev->struct_mutex);
246
247 return ret;
248 case DRM_UNINST_HANDLER:
249 mutex_lock(&dev->struct_mutex)rw_enter_write(&dev->struct_mutex);
250 ret = drm_irq_uninstall(dev);
251 mutex_unlock(&dev->struct_mutex)rw_exit_write(&dev->struct_mutex);
252
253 return ret;
254 default:
255 return -EINVAL22;
256 }
257}
258#endif