|
14 | 14 | * |
15 | 15 | * Data Structure |
16 | 16 | * -------------- |
17 | | - * The printk_ringbuffer is made up of 3 internal ringbuffers: |
| 17 | + * The printk_ringbuffer is made up of 2 internal ringbuffers: |
18 | 18 | * |
19 | 19 | * desc_ring |
20 | 20 | * A ring of descriptors and their meta data (such as sequence number, |
|
224 | 224 | * |
225 | 225 | * prb_rec_init_rd(&r, &info, &text_buf[0], sizeof(text_buf)); |
226 | 226 | * |
227 | | - * prb_for_each_record(0, &test_rb, &seq, &r) { |
| 227 | + * prb_for_each_record(0, &test_rb, seq, &r) { |
228 | 228 | * if (info.seq != seq) |
229 | 229 | * pr_warn("lost %llu records\n", info.seq - seq); |
230 | 230 | * |
@@ -1302,23 +1302,26 @@ static const char *get_data(struct prb_data_ring *data_ring, |
1302 | 1302 | return NULL; |
1303 | 1303 | } |
1304 | 1304 |
|
1305 | | - /* Sanity check. Data-less blocks were handled earlier. */ |
1306 | | - if (WARN_ON_ONCE(!data_check_size(data_ring, *data_size) || !*data_size)) |
1307 | | - return NULL; |
1308 | | - |
1309 | 1305 | /* A valid data block will always be aligned to the ID size. */ |
1310 | 1306 | if (WARN_ON_ONCE(blk_lpos->begin != ALIGN(blk_lpos->begin, sizeof(db->id))) || |
1311 | 1307 | WARN_ON_ONCE(blk_lpos->next != ALIGN(blk_lpos->next, sizeof(db->id)))) { |
1312 | 1308 | return NULL; |
1313 | 1309 | } |
1314 | 1310 |
|
1315 | | - /* A valid data block will always have at least an ID. */ |
1316 | | - if (WARN_ON_ONCE(*data_size < sizeof(db->id))) |
| 1311 | + /* |
| 1312 | + * A regular data block will always have an ID and at least |
| 1313 | + * 1 byte of data. Data-less blocks were handled earlier. |
| 1314 | + */ |
| 1315 | + if (WARN_ON_ONCE(*data_size <= sizeof(db->id))) |
1317 | 1316 | return NULL; |
1318 | 1317 |
|
1319 | 1318 | /* Subtract block ID space from size to reflect data size. */ |
1320 | 1319 | *data_size -= sizeof(db->id); |
1321 | 1320 |
|
| 1321 | + /* Sanity check the max size of the regular data block. */ |
| 1322 | + if (WARN_ON_ONCE(!data_check_size(data_ring, *data_size))) |
| 1323 | + return NULL; |
| 1324 | + |
1322 | 1325 | return &db->data[0]; |
1323 | 1326 | } |
1324 | 1327 |
|
@@ -1365,7 +1368,7 @@ static struct prb_desc *desc_reopen_last(struct prb_desc_ring *desc_ring, |
1365 | 1368 | * |
1366 | 1369 | * WMB from _prb_commit:A to _prb_commit:B |
1367 | 1370 | * matching |
1368 | | - * MB If desc_reopen_last:A to prb_reserve_in_last:A |
| 1371 | + * MB from desc_reopen_last:A to prb_reserve_in_last:A |
1369 | 1372 | */ |
1370 | 1373 | if (!atomic_long_try_cmpxchg(&d->state_var, &prev_state_val, |
1371 | 1374 | DESC_SV(id, desc_reserved))) { /* LMM(desc_reopen_last:A) */ |
@@ -1770,9 +1773,9 @@ static void _prb_commit(struct prb_reserved_entry *e, unsigned long state_val) |
1770 | 1773 | * |
1771 | 1774 | * Relies on: |
1772 | 1775 | * |
1773 | | - * MB _prb_commit:B to prb_commit:A |
| 1776 | + * MB from _prb_commit:B to prb_commit:A |
1774 | 1777 | * matching |
1775 | | - * MB desc_reserve:D to desc_make_final:A |
| 1778 | + * MB from desc_reserve:D to desc_make_final:A |
1776 | 1779 | */ |
1777 | 1780 | if (!atomic_long_try_cmpxchg(&d->state_var, &prev_state_val, |
1778 | 1781 | DESC_SV(e->id, state_val))) { /* LMM(_prb_commit:B) */ |
@@ -2035,7 +2038,7 @@ u64 prb_first_seq(struct printk_ringbuffer *rb) |
2035 | 2038 | * |
2036 | 2039 | * MB from desc_push_tail:B to desc_reserve:F |
2037 | 2040 | * matching |
2038 | | - * RMB prb_first_seq:B to prb_first_seq:A |
| 2041 | + * RMB from prb_first_seq:B to prb_first_seq:A |
2039 | 2042 | */ |
2040 | 2043 | smp_rmb(); /* LMM(prb_first_seq:C) */ |
2041 | 2044 | } |
|
0 commit comments