| 84 | } |
| 85 | |
| 86 | void flashconsole_tx_flush(void) |
| 87 | { |
| 88 | size_t len = line_offset; |
| 89 | size_t region_size; |
| 90 | |
| 91 | /* Prevent any recursive loops in case the spi flash driver |
| 92 | * calls printk (in case of transaction timeout or |
| 93 | * any other error while writing) */ |
| 94 | static bool busy; |
| 95 | |
| 96 | /* In addition to being an obvious runtime optimization, checking for |
| 97 | * len = 0 also prevents false disabling of the driver, as rdev_writeat |
| 98 | * seems to return -1 if len is zero even though this should be a |
| 99 | * recoverable condition. */ |
| 100 | if (busy || !rdev_ptr || len == 0) |
| 101 | return; |
| 102 | |
| 103 | busy = true; |
| 104 | region_size = region_device_sz(rdev_ptr); |
| 105 | if (offset + len >= region_size) |
| 106 | len = region_size - offset; |
| 107 | |
| 108 | if (rdev_writeat(&rdev, line_buffer, offset, len) != len) |
| 109 | return; |
| 110 | |
| 111 | // If the region is full, stop future write attempts |
| 112 | if (offset + len >= region_size) |
| 113 | return; |
| 114 | |
| 115 | offset += len; |
| 116 | line_offset = 0; |
| 117 | |
| 118 | busy = false; |
| 119 | } |
no test coverage detected