diff options
| -rw-r--r-- | kernel/power/Kconfig | 6 | ||||
| -rw-r--r-- | kernel/power/wakelock.c | 31 |
2 files changed, 32 insertions, 5 deletions
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig index 1d534076d33a..08783eda9ce4 100644 --- a/kernel/power/Kconfig +++ b/kernel/power/Kconfig | |||
| @@ -119,6 +119,12 @@ config PM_WAKELOCKS | |||
| 119 | Allow user space to create, activate and deactivate wakeup source | 119 | Allow user space to create, activate and deactivate wakeup source |
| 120 | objects with the help of a sysfs-based interface. | 120 | objects with the help of a sysfs-based interface. |
| 121 | 121 | ||
| 122 | config PM_WAKELOCKS_LIMIT | ||
| 123 | int "Maximum number of user space wakeup sources (0 = no limit)" | ||
| 124 | range 0 100000 | ||
| 125 | default 100 | ||
| 126 | depends on PM_WAKELOCKS | ||
| 127 | |||
| 122 | config PM_RUNTIME | 128 | config PM_RUNTIME |
| 123 | bool "Run-time PM core functionality" | 129 | bool "Run-time PM core functionality" |
| 124 | depends on !IA64_HP_SIM | 130 | depends on !IA64_HP_SIM |
diff --git a/kernel/power/wakelock.c b/kernel/power/wakelock.c index 579700665e8c..dc34b9d3b7d8 100644 --- a/kernel/power/wakelock.c +++ b/kernel/power/wakelock.c | |||
| @@ -17,7 +17,6 @@ | |||
| 17 | #include <linux/rbtree.h> | 17 | #include <linux/rbtree.h> |
| 18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
| 19 | 19 | ||
| 20 | #define WL_NUMBER_LIMIT 100 | ||
| 21 | #define WL_GC_COUNT_MAX 100 | 20 | #define WL_GC_COUNT_MAX 100 |
| 22 | #define WL_GC_TIME_SEC 300 | 21 | #define WL_GC_TIME_SEC 300 |
| 23 | 22 | ||
| @@ -32,7 +31,6 @@ struct wakelock { | |||
| 32 | 31 | ||
| 33 | static struct rb_root wakelocks_tree = RB_ROOT; | 32 | static struct rb_root wakelocks_tree = RB_ROOT; |
| 34 | static LIST_HEAD(wakelocks_lru_list); | 33 | static LIST_HEAD(wakelocks_lru_list); |
| 35 | static unsigned int number_of_wakelocks; | ||
| 36 | static unsigned int wakelocks_gc_count; | 34 | static unsigned int wakelocks_gc_count; |
| 37 | 35 | ||
| 38 | ssize_t pm_show_wakelocks(char *buf, bool show_active) | 36 | ssize_t pm_show_wakelocks(char *buf, bool show_active) |
| @@ -58,6 +56,29 @@ ssize_t pm_show_wakelocks(char *buf, bool show_active) | |||
| 58 | return (str - buf); | 56 | return (str - buf); |
| 59 | } | 57 | } |
| 60 | 58 | ||
| 59 | #if CONFIG_PM_WAKELOCKS_LIMIT > 0 | ||
| 60 | static unsigned int number_of_wakelocks; | ||
| 61 | |||
| 62 | static inline bool wakelocks_limit_exceeded(void) | ||
| 63 | { | ||
| 64 | return number_of_wakelocks > CONFIG_PM_WAKELOCKS_LIMIT; | ||
| 65 | } | ||
| 66 | |||
| 67 | static inline void increment_wakelocks_number(void) | ||
| 68 | { | ||
| 69 | number_of_wakelocks++; | ||
| 70 | } | ||
| 71 | |||
| 72 | static inline void decrement_wakelocks_number(void) | ||
| 73 | { | ||
| 74 | number_of_wakelocks--; | ||
| 75 | } | ||
| 76 | #else /* CONFIG_PM_WAKELOCKS_LIMIT = 0 */ | ||
| 77 | static inline bool wakelocks_limit_exceeded(void) { return false; } | ||
| 78 | static inline void increment_wakelocks_number(void) {} | ||
| 79 | static inline void decrement_wakelocks_number(void) {} | ||
| 80 | #endif /* CONFIG_PM_WAKELOCKS_LIMIT */ | ||
| 81 | |||
| 61 | static struct wakelock *wakelock_lookup_add(const char *name, size_t len, | 82 | static struct wakelock *wakelock_lookup_add(const char *name, size_t len, |
| 62 | bool add_if_not_found) | 83 | bool add_if_not_found) |
| 63 | { | 84 | { |
| @@ -85,7 +106,7 @@ static struct wakelock *wakelock_lookup_add(const char *name, size_t len, | |||
| 85 | if (!add_if_not_found) | 106 | if (!add_if_not_found) |
| 86 | return ERR_PTR(-EINVAL); | 107 | return ERR_PTR(-EINVAL); |
| 87 | 108 | ||
| 88 | if (number_of_wakelocks > WL_NUMBER_LIMIT) | 109 | if (wakelocks_limit_exceeded()) |
| 89 | return ERR_PTR(-ENOSPC); | 110 | return ERR_PTR(-ENOSPC); |
| 90 | 111 | ||
| 91 | /* Not found, we have to add a new one. */ | 112 | /* Not found, we have to add a new one. */ |
| @@ -103,7 +124,7 @@ static struct wakelock *wakelock_lookup_add(const char *name, size_t len, | |||
| 103 | rb_link_node(&wl->node, parent, node); | 124 | rb_link_node(&wl->node, parent, node); |
| 104 | rb_insert_color(&wl->node, &wakelocks_tree); | 125 | rb_insert_color(&wl->node, &wakelocks_tree); |
| 105 | list_add(&wl->lru, &wakelocks_lru_list); | 126 | list_add(&wl->lru, &wakelocks_lru_list); |
| 106 | number_of_wakelocks++; | 127 | increment_wakelocks_number(); |
| 107 | return wl; | 128 | return wl; |
| 108 | } | 129 | } |
| 109 | 130 | ||
| @@ -175,7 +196,7 @@ static void wakelocks_gc(void) | |||
| 175 | list_del(&wl->lru); | 196 | list_del(&wl->lru); |
| 176 | kfree(wl->name); | 197 | kfree(wl->name); |
| 177 | kfree(wl); | 198 | kfree(wl); |
| 178 | number_of_wakelocks--; | 199 | decrement_wakelocks_number(); |
| 179 | } | 200 | } |
| 180 | } | 201 | } |
| 181 | wakelocks_gc_count = 0; | 202 | wakelocks_gc_count = 0; |
