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.

platform/x86: thinkpad_acpi: use lockdep annotations

Instead of relying on free-form comments to document locking
requirements use well-known lockdep annotations.
These can also be validated at runtime make sure the invariants are not
violated.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20230704-thinkpad_acpi-lockdep-v1-2-60129548a738@weissschuh.net
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

authored by

Thomas Weißschuh and committed by
Hans de Goede
38831eaf ce55dbe5

+24 -17
+24 -17
drivers/platform/x86/thinkpad_acpi.c
··· 50 50 #include <linux/kthread.h> 51 51 #include <linux/leds.h> 52 52 #include <linux/list.h> 53 + #include <linux/lockdep.h> 53 54 #include <linux/module.h> 54 55 #include <linux/mutex.h> 55 56 #include <linux/nvram.h> ··· 2072 2071 * hotkey_acpi_mask accordingly. Also resets any bits 2073 2072 * from hotkey_user_mask that are unavailable to be 2074 2073 * delivered (shadow requirement of the userspace ABI). 2075 - * 2076 - * Call with hotkey_mutex held 2077 2074 */ 2078 2075 static int hotkey_mask_get(void) 2079 2076 { 2077 + lockdep_assert_held(&hotkey_mutex); 2078 + 2080 2079 if (tp_features.hotkey_mask) { 2081 2080 u32 m = 0; 2082 2081 ··· 2112 2111 * Also calls hotkey_mask_get to update hotkey_acpi_mask. 2113 2112 * 2114 2113 * NOTE: does not set bits in hotkey_user_mask, but may reset them. 2115 - * 2116 - * Call with hotkey_mutex held 2117 2114 */ 2118 2115 static int hotkey_mask_set(u32 mask) 2119 2116 { ··· 2119 2120 int rc = 0; 2120 2121 2121 2122 const u32 fwmask = mask & ~hotkey_source_mask; 2123 + 2124 + lockdep_assert_held(&hotkey_mutex); 2122 2125 2123 2126 if (tp_features.hotkey_mask) { 2124 2127 for (i = 0; i < 32; i++) { ··· 2153 2152 2154 2153 /* 2155 2154 * Sets hotkey_user_mask and tries to set the firmware mask 2156 - * 2157 - * Call with hotkey_mutex held 2158 2155 */ 2159 2156 static int hotkey_user_mask_set(const u32 mask) 2160 2157 { 2161 2158 int rc; 2159 + 2160 + lockdep_assert_held(&hotkey_mutex); 2162 2161 2163 2162 /* Give people a chance to notice they are doing something that 2164 2163 * is bound to go boom on their users sooner or later */ ··· 2520 2519 return 0; 2521 2520 } 2522 2521 2523 - /* call with hotkey_mutex held */ 2524 2522 static void hotkey_poll_stop_sync(void) 2525 2523 { 2524 + lockdep_assert_held(&hotkey_mutex); 2525 + 2526 2526 if (tpacpi_hotkey_task) { 2527 2527 kthread_stop(tpacpi_hotkey_task); 2528 2528 tpacpi_hotkey_task = NULL; 2529 2529 } 2530 2530 } 2531 2531 2532 - /* call with hotkey_mutex held */ 2533 2532 static void hotkey_poll_setup(const bool may_warn) 2534 2533 { 2535 2534 const u32 poll_driver_mask = hotkey_driver_mask & hotkey_source_mask; 2536 2535 const u32 poll_user_mask = hotkey_user_mask & hotkey_source_mask; 2536 + 2537 + lockdep_assert_held(&hotkey_mutex); 2537 2538 2538 2539 if (hotkey_poll_freq > 0 && 2539 2540 (poll_driver_mask || ··· 2565 2562 mutex_unlock(&hotkey_mutex); 2566 2563 } 2567 2564 2568 - /* call with hotkey_mutex held */ 2569 2565 static void hotkey_poll_set_freq(unsigned int freq) 2570 2566 { 2567 + lockdep_assert_held(&hotkey_mutex); 2568 + 2571 2569 if (!freq) 2572 2570 hotkey_poll_stop_sync(); 2573 2571 ··· 6668 6664 6669 6665 static struct mutex brightness_mutex; 6670 6666 6671 - /* NVRAM brightness access, 6672 - * call with brightness_mutex held! */ 6667 + /* NVRAM brightness access */ 6673 6668 static unsigned int tpacpi_brightness_nvram_get(void) 6674 6669 { 6675 6670 u8 lnvram; 6671 + 6672 + lockdep_assert_held(&brightness_mutex); 6676 6673 6677 6674 lnvram = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) 6678 6675 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) ··· 6722 6717 } 6723 6718 6724 6719 6725 - /* call with brightness_mutex held! */ 6726 6720 static int tpacpi_brightness_get_raw(int *status) 6727 6721 { 6728 6722 u8 lec = 0; 6723 + 6724 + lockdep_assert_held(&brightness_mutex); 6729 6725 6730 6726 switch (brightness_mode) { 6731 6727 case TPACPI_BRGHT_MODE_UCMS_STEP: ··· 6743 6737 } 6744 6738 } 6745 6739 6746 - /* call with brightness_mutex held! */ 6747 6740 /* do NOT call with illegal backlight level value */ 6748 6741 static int tpacpi_brightness_set_ec(unsigned int value) 6749 6742 { 6750 6743 u8 lec = 0; 6744 + 6745 + lockdep_assert_held(&brightness_mutex); 6751 6746 6752 6747 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) 6753 6748 return -EIO; ··· 6761 6754 return 0; 6762 6755 } 6763 6756 6764 - /* call with brightness_mutex held! */ 6765 6757 static int tpacpi_brightness_set_ucmsstep(unsigned int value) 6766 6758 { 6767 6759 int cmos_cmd, inc; 6768 6760 unsigned int current_value, i; 6761 + 6762 + lockdep_assert_held(&brightness_mutex); 6769 6763 6770 6764 current_value = tpacpi_brightness_nvram_get(); 6771 6765 ··· 8216 8208 return true; 8217 8209 } 8218 8210 8219 - /* 8220 - * Call with fan_mutex held 8221 - */ 8222 8211 static void fan_update_desired_level(u8 status) 8223 8212 { 8213 + lockdep_assert_held(&fan_mutex); 8214 + 8224 8215 if ((status & 8225 8216 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { 8226 8217 if (status > 7)