Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

irqbypass: Drop pointless and misleading THIS_MODULE get/put

Drop irqbypass.ko's superfluous and misleading get/put calls on
THIS_MODULE. A module taking a reference to itself is useless; no amount
of checks will prevent doom and destruction if the caller hasn't already
guaranteed the liveliness of the module (this goes for any module). E.g.
if try_module_get() fails because irqbypass.ko is being unloaded, then the
kernel has already hit a use-after-free by virtue of executing code whose
lifecycle is tied to irqbypass.ko.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
Link: https://lore.kernel.org/r/20250516230734.2564775-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>

-20
-20
virt/lib/irqbypass.c
··· 92 92 93 93 might_sleep(); 94 94 95 - if (!try_module_get(THIS_MODULE)) 96 - return -ENODEV; 97 - 98 95 mutex_lock(&lock); 99 96 100 97 list_for_each_entry(tmp, &producers, node) { ··· 117 120 return 0; 118 121 out_err: 119 122 mutex_unlock(&lock); 120 - module_put(THIS_MODULE); 121 123 return ret; 122 124 } 123 125 EXPORT_SYMBOL_GPL(irq_bypass_register_producer); ··· 138 142 139 143 might_sleep(); 140 144 141 - if (!try_module_get(THIS_MODULE)) 142 - return; /* nothing in the list anyway */ 143 - 144 145 mutex_lock(&lock); 145 146 146 147 list_for_each_entry(tmp, &producers, node) { ··· 152 159 } 153 160 154 161 list_del(&producer->node); 155 - module_put(THIS_MODULE); 156 162 break; 157 163 } 158 164 159 165 mutex_unlock(&lock); 160 - 161 - module_put(THIS_MODULE); 162 166 } 163 167 EXPORT_SYMBOL_GPL(irq_bypass_unregister_producer); 164 168 ··· 177 187 return -EINVAL; 178 188 179 189 might_sleep(); 180 - 181 - if (!try_module_get(THIS_MODULE)) 182 - return -ENODEV; 183 190 184 191 mutex_lock(&lock); 185 192 ··· 203 216 return 0; 204 217 out_err: 205 218 mutex_unlock(&lock); 206 - module_put(THIS_MODULE); 207 219 return ret; 208 220 } 209 221 EXPORT_SYMBOL_GPL(irq_bypass_register_consumer); ··· 224 238 225 239 might_sleep(); 226 240 227 - if (!try_module_get(THIS_MODULE)) 228 - return; /* nothing in the list anyway */ 229 - 230 241 mutex_lock(&lock); 231 242 232 243 list_for_each_entry(tmp, &consumers, node) { ··· 238 255 } 239 256 240 257 list_del(&consumer->node); 241 - module_put(THIS_MODULE); 242 258 break; 243 259 } 244 260 245 261 mutex_unlock(&lock); 246 - 247 - module_put(THIS_MODULE); 248 262 } 249 263 EXPORT_SYMBOL_GPL(irq_bypass_unregister_consumer);