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.
Unified · Split
| @@ -164,7 +164,6 @@ struct dentry *get_monitors_root(void) · 163 unmodified lines | |||
| 164 | */ | 164 | */ |
| 165 | LIST_HEAD(rv_monitors_list); | 165 | LIST_HEAD(rv_monitors_list); |
| 166 | 166 | ||
| 167 | static int task_monitor_count; | ||
| 168 | static bool task_monitor_slots[CONFIG_RV_PER_TASK_MONITORS]; | 167 | static bool task_monitor_slots[CONFIG_RV_PER_TASK_MONITORS]; |
| 169 | 168 | ||
| 170 | int rv_get_task_monitor_slot(void) | 169 | int rv_get_task_monitor_slot(void) |
| @@ -173,21 +172,14 @@ int rv_get_task_monitor_slot(void) · 2 unmodified lines | |||
| 173 | 172 | ||
| 174 | lockdep_assert_held(&rv_interface_lock); | 173 | lockdep_assert_held(&rv_interface_lock); |
| 175 | 174 | ||
| 176 | if (task_monitor_count == CONFIG_RV_PER_TASK_MONITORS) | ||
| 177 | return -EBUSY; | ||
| 178 | |||
| 179 | task_monitor_count++; | ||
| 180 | |||
| 181 | for (i = 0; i < CONFIG_RV_PER_TASK_MONITORS; i++) { | 175 | for (i = 0; i < CONFIG_RV_PER_TASK_MONITORS; i++) { |
| 182 | if (task_monitor_slots[i] == false) { | 176 | if (!task_monitor_slots[i]) { |
| 183 | task_monitor_slots[i] = true; | 177 | task_monitor_slots[i] = true; |
| 184 | return i; | 178 | return i; |
| 185 | } | 179 | } |
| 186 | } | 180 | } |
| 187 | 181 | ||
| 188 | WARN_ONCE(1, "RV task_monitor_count and slots are out of sync\n"); | 182 | return -EBUSY; |
| 189 | |||
| 190 | return -EINVAL; | ||
| 191 | } | 183 | } |
| 192 | 184 | ||
| 193 | void rv_put_task_monitor_slot(int slot) | 185 | void rv_put_task_monitor_slot(int slot) |
| @@ -199,10 +191,10 @@ void rv_put_task_monitor_slot(int slot) · 5 unmodified lines | |||
| 199 | return; | 191 | return; |
| 200 | } | 192 | } |
| 201 | 193 | ||
| 202 | WARN_ONCE(!task_monitor_slots[slot], "RV releasing unused task_monitor_slots: %d\n", | 194 | if (WARN_ONCE(!task_monitor_slots[slot], |
| 203 | slot); | 195 | "RV releasing unused task monitor slot: %d\n", slot)) |
| 196 | return; | ||
| 204 | 197 | ||
| 205 | task_monitor_count--; | ||
| 206 | task_monitor_slots[slot] = false; | 198 | task_monitor_slots[slot] = false; |
| 207 | } | 199 | } |
| 208 | 200 | ||