···1414 *1515 * Data Structure1616 * --------------1717- * The printk_ringbuffer is made up of 3 internal ringbuffers:1717+ * The printk_ringbuffer is made up of 2 internal ringbuffers:1818 *1919 * desc_ring2020 * A ring of descriptors and their meta data (such as sequence number,···224224 *225225 * prb_rec_init_rd(&r, &info, &text_buf[0], sizeof(text_buf));226226 *227227- * prb_for_each_record(0, &test_rb, &seq, &r) {227227+ * prb_for_each_record(0, &test_rb, seq, &r) {228228 * if (info.seq != seq)229229 * pr_warn("lost %llu records\n", info.seq - seq);230230 *···13021302 return NULL;13031303 }1304130413051305- /* Sanity check. Data-less blocks were handled earlier. */13061306- if (WARN_ON_ONCE(!data_check_size(data_ring, *data_size) || !*data_size))13071307- return NULL;13081308-13091305 /* A valid data block will always be aligned to the ID size. */13101306 if (WARN_ON_ONCE(blk_lpos->begin != ALIGN(blk_lpos->begin, sizeof(db->id))) ||13111307 WARN_ON_ONCE(blk_lpos->next != ALIGN(blk_lpos->next, sizeof(db->id)))) {13121308 return NULL;13131309 }1314131013151315- /* A valid data block will always have at least an ID. */13161316- if (WARN_ON_ONCE(*data_size < sizeof(db->id)))13111311+ /*13121312+ * A regular data block will always have an ID and at least13131313+ * 1 byte of data. Data-less blocks were handled earlier.13141314+ */13151315+ if (WARN_ON_ONCE(*data_size <= sizeof(db->id)))13171316 return NULL;1318131713191318 /* Subtract block ID space from size to reflect data size. */13201319 *data_size -= sizeof(db->id);13201320+13211321+ /* Sanity check the max size of the regular data block. */13221322+ if (WARN_ON_ONCE(!data_check_size(data_ring, *data_size)))13231323+ return NULL;1321132413221325 return &db->data[0];13231326}···13681365 *13691366 * WMB from _prb_commit:A to _prb_commit:B13701367 * matching13711371- * MB If desc_reopen_last:A to prb_reserve_in_last:A13681368+ * MB from desc_reopen_last:A to prb_reserve_in_last:A13721369 */13731370 if (!atomic_long_try_cmpxchg(&d->state_var, &prev_state_val,13741371 DESC_SV(id, desc_reserved))) { /* LMM(desc_reopen_last:A) */···17731770 *17741771 * Relies on:17751772 *17761776- * MB _prb_commit:B to prb_commit:A17731773+ * MB from _prb_commit:B to prb_commit:A17771774 * matching17781778- * MB desc_reserve:D to desc_make_final:A17751775+ * MB from desc_reserve:D to desc_make_final:A17791776 */17801777 if (!atomic_long_try_cmpxchg(&d->state_var, &prev_state_val,17811778 DESC_SV(e->id, state_val))) { /* LMM(_prb_commit:B) */···20382035 *20392036 * MB from desc_push_tail:B to desc_reserve:F20402037 * matching20412041- * RMB prb_first_seq:B to prb_first_seq:A20382038+ * RMB from prb_first_seq:B to prb_first_seq:A20422039 */20432040 smp_rmb(); /* LMM(prb_first_seq:C) */20442041 }
+2-2
kernel/printk/printk_ringbuffer.h
···127127};128128129129#define _DATA_SIZE(sz_bits) (1UL << (sz_bits))130130-#define _DESCS_COUNT(ct_bits) (1U << (ct_bits))130130+#define _DESCS_COUNT(ct_bits) (1UL << (ct_bits))131131#define DESC_SV_BITS BITS_PER_LONG132132#define DESC_FLAGS_SHIFT (DESC_SV_BITS - 2)133133#define DESC_FLAGS_MASK (3UL << DESC_FLAGS_SHIFT)···388388 *389389 * This is a macro for conveniently iterating over a ringbuffer.390390 * Note that @s may not be the sequence number of the record on each391391- * iteration. For the sequence number, @r->info->seq should be checked.391391+ * iteration. For the sequence number, @i->seq should be checked.392392 *393393 * Context: Any context.394394 */