We are used to handle "bad" states in the 'if's in the kernel. Refactor (invert the two conditions in) __tty_buffer_request_room(), so that the code returns from the fast paths immediately instead of postponing to the heavy end of the function.
Unified · Split
| @@ -266,28 +266,28 @@ static int __tty_buffer_request_room(struct tty_port *port, size_t size, · 265 unmodified lines | |||
| 266 | size_t left = (b->flags ? 1 : 2) * b->size - b->used; | 266 | size_t left = (b->flags ? 1 : 2) * b->size - b->used; |
| 267 | bool change = !b->flags && flags; | 267 | bool change = !b->flags && flags; |
| 268 | 268 | ||
| 269 | if (change || left < size) { | 269 | if (!change && left >= size) |
| 270 | /* This is the slow path - looking for new buffers to use */ | 270 | return size; |
| 271 | n = tty_buffer_alloc(port, size); | 271 | |
| 272 | if (n != NULL) { | 272 | /* This is the slow path - looking for new buffers to use */ |
| 273 | n->flags = flags; | 273 | n = tty_buffer_alloc(port, size); |
| 274 | buf->tail = n; | 274 | if (n == NULL) |
| 275 | /* | 275 | return change ? 0 : left; |
| 276 | * Paired w/ acquire in flush_to_ldisc() and lookahead_bufs() | 276 | |
| 277 | * ensures they see all buffer data. | 277 | n->flags = flags; |
| 278 | */ | 278 | buf->tail = n; |
| 279 | smp_store_release(&b->commit, b->used); | 279 | /* |
| 280 | /* | 280 | * Paired w/ acquire in flush_to_ldisc() and lookahead_bufs() |
| 281 | * Paired w/ acquire in flush_to_ldisc() and lookahead_bufs() | 281 | * ensures they see all buffer data. |
| 282 | * ensures the latest commit value can be read before the head | 282 | */ |
| 283 | * is advanced to the next buffer. | 283 | smp_store_release(&b->commit, b->used); |
| 284 | */ | 284 | /* |
| 285 | smp_store_release(&b->next, n); | 285 | * Paired w/ acquire in flush_to_ldisc() and lookahead_bufs() |
| 286 | } else if (change) | 286 | * ensures the latest commit value can be read before the head |
| 287 | size = 0; | 287 | * is advanced to the next buffer. |
| 288 | else | 288 | */ |
| 289 | size = left; | 289 | smp_store_release(&b->next, n); |
| 290 | } | 290 | |
| 291 | return size; | 291 | return size; |
| 292 | } | 292 | } |
| 293 | 293 | ||