@@ -40,6 +40,8 @@ module_param_named(debug_mask, debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP);
40
40
#define WAKE_LOCK_AUTO_EXPIRE (1U << 10)
41
41
#define WAKE_LOCK_PREVENTING_SUSPEND (1U << 11)
42
42
43
+ #define TOO_MAY_LOCKS_WARNING "\n\ntoo many wakelocks!!!\n"
44
+
43
45
static DEFINE_SPINLOCK (list_lock );
44
46
static LIST_HEAD (inactive_locks );
45
47
static struct list_head active_wake_locks [WAKE_LOCK_TYPE_COUNT ];
@@ -81,13 +83,15 @@ int get_expired_time(struct wake_lock *lock, ktime_t *expire_time)
81
83
}
82
84
83
85
84
- static int print_lock_stat (char * buf , struct wake_lock * lock )
86
+ static int print_lock_stat (char * buf , int len , struct wake_lock * lock )
85
87
{
86
88
int lock_count = lock -> stat .count ;
87
89
int expire_count = lock -> stat .expire_count ;
88
90
ktime_t active_time = ktime_set (0 , 0 );
89
91
ktime_t total_time = lock -> stat .total_time ;
90
92
ktime_t max_time = lock -> stat .max_time ;
93
+ int n ;
94
+
91
95
ktime_t prevent_suspend_time = lock -> stat .prevent_suspend_time ;
92
96
if (lock -> flags & WAKE_LOCK_ACTIVE ) {
93
97
ktime_t now , add_time ;
@@ -108,12 +112,15 @@ static int print_lock_stat(char *buf, struct wake_lock *lock)
108
112
max_time = add_time ;
109
113
}
110
114
111
- return sprintf (buf , "\"%s\"\t%d\t%d\t%d\t%lld\t%lld\t%lld\t%lld\t"
112
- "%lld\n" , lock -> name , lock_count , expire_count ,
113
- lock -> stat .wakeup_count , ktime_to_ns (active_time ),
114
- ktime_to_ns (total_time ),
115
- ktime_to_ns (prevent_suspend_time ), ktime_to_ns (max_time ),
116
- ktime_to_ns (lock -> stat .last_time ));
115
+ n = snprintf (buf , len ,
116
+ "\"%s\"\t%d\t%d\t%d\t%lld\t%lld\t%lld\t%lld\t%lld\n" ,
117
+ lock -> name , lock_count , expire_count ,
118
+ lock -> stat .wakeup_count , ktime_to_ns (active_time ),
119
+ ktime_to_ns (total_time ),
120
+ ktime_to_ns (prevent_suspend_time ), ktime_to_ns (max_time ),
121
+ ktime_to_ns (lock -> stat .last_time ));
122
+
123
+ return n > len ? len : n ;
117
124
}
118
125
119
126
@@ -123,31 +130,30 @@ static int wakelocks_read_proc(char *page, char **start, off_t off,
123
130
unsigned long irqflags ;
124
131
struct wake_lock * lock ;
125
132
int len = 0 ;
126
- char * p = page ;
127
133
int type ;
128
134
129
135
spin_lock_irqsave (& list_lock , irqflags );
130
136
131
- p += sprintf (p , "name\tcount\texpire_count\twake_count\tactive_since"
132
- "\ttotal_time\tsleep_time\tmax_time\tlast_change\n" );
137
+ len += snprintf (page + len , count - len ,
138
+ "name\tcount\texpire_count\twake_count\tactive_since"
139
+ "\ttotal_time\tsleep_time\tmax_time\tlast_change\n" );
133
140
list_for_each_entry (lock , & inactive_locks , link ) {
134
- p += print_lock_stat (p , lock );
141
+ len += print_lock_stat (page + len , count - len , lock );
135
142
}
136
143
for (type = 0 ; type < WAKE_LOCK_TYPE_COUNT ; type ++ ) {
137
144
list_for_each_entry (lock , & active_wake_locks [type ], link )
138
- p += print_lock_stat (p , lock );
145
+ len += print_lock_stat (page + len , count - len , lock );
139
146
}
140
147
spin_unlock_irqrestore (& list_lock , irqflags );
141
148
142
- * start = page + off ;
149
+ if (len == count )
150
+ memcpy (page + len - strlen (TOO_MAY_LOCKS_WARNING ),
151
+ TOO_MAY_LOCKS_WARNING ,
152
+ strlen (TOO_MAY_LOCKS_WARNING ));
143
153
144
- len = p - page ;
145
- if (len > off )
146
- len -= off ;
147
- else
148
- len = 0 ;
154
+ * eof = 1 ;
149
155
150
- return len < count ? len : count ;
156
+ return len ;
151
157
}
152
158
153
159
static void wake_unlock_stat_locked (struct wake_lock * lock , int expired )
0 commit comments