1 // SPDX-License-Identifier: GPL-2.0 2 3 // Copyright (C) 2024 Google LLC. 4 5 //! Logic for static keys. 6 //! 7 //! C header: [`include/linux/jump_label.h`](srctree/include/linux/jump_label.h). 8 9 /// Branch based on a static key. 10 /// 11 /// Takes three arguments: 12 /// 13 /// * `key` - the path to the static variable containing the `static_key`. 14 /// * `keytyp` - the type of `key`. 15 /// * `field` - the name of the field of `key` that contains the `static_key`. 16 /// 17 /// # Safety 18 /// 19 /// The macro must be used with a real static key defined by C. 20 #[macro_export] 21 macro_rules! static_branch_unlikely { 22 ($key:path, $keytyp:ty, $field:ident) => {{ 23 let _key: *const $keytyp = ::core::ptr::addr_of!($key); 24 let _key: *const $crate::bindings::static_key_false = ::core::ptr::addr_of!((*_key).$field); 25 let _key: *const $crate::bindings::static_key = _key.cast(); 26 27 $crate::bindings::static_key_count(_key.cast_mut()) > 0 28 }}; 29 } 30 pub use static_branch_unlikely; 31