History

rv: Simplify task monitor slot management

The slot array already tracks allocation and task_monitor_count duplicates that state. On an invalid second release, the old code warns but still decrements the counter, corrupting later allocations. Use the slot array as the sole source of truth. Return after warning about an unused slot, and return -EBUSY when no slot is free.

Li Qiang committed 4 months ago

Commit b255fc51 parent 2a8cd681 file · +5 −13Browse files

Unified · Split

kernel/trace/rv/rv.c+5−13
@@ -164,7 +164,6 @@ struct dentry *get_monitors_root(void) · 163 unmodified lines
164164 */
165165 LIST_HEAD(rv_monitors_list);
166166
167−static int task_monitor_count;
168167 static bool task_monitor_slots[CONFIG_RV_PER_TASK_MONITORS];
169168
170169 int rv_get_task_monitor_slot(void)
@@ -173,21 +172,14 @@ int rv_get_task_monitor_slot(void) · 2 unmodified lines
173172
174173 lockdep_assert_held(&rv_interface_lock);
175174
176− if (task_monitor_count == CONFIG_RV_PER_TASK_MONITORS)
177− return -EBUSY;
178−
179− task_monitor_count++;
180−
181175 for (i = 0; i < CONFIG_RV_PER_TASK_MONITORS; i++) {
182− if (task_monitor_slots[i] == false) {
176+ if (!task_monitor_slots[i]) {
183177 task_monitor_slots[i] = true;
184178 return i;
185179 }
186180 }
187181
188− WARN_ONCE(1, "RV task_monitor_count and slots are out of sync\n");
189−
190− return -EINVAL;
182+ return -EBUSY;
191183 }
192184
193185 void rv_put_task_monitor_slot(int slot)
@@ -199,10 +191,10 @@ void rv_put_task_monitor_slot(int slot) · 5 unmodified lines
199191 return;
200192 }
201193
202− WARN_ONCE(!task_monitor_slots[slot], "RV releasing unused task_monitor_slots: %d\n",
203− slot);
194+ if (WARN_ONCE(!task_monitor_slots[slot],
195+ "RV releasing unused task monitor slot: %d\n", slot))
196+ return;
204197
205− task_monitor_count--;
206198 task_monitor_slots[slot] = false;
207199 }
208200