Skip to content

Commit 5113cf5

Browse files
jognesspmladek
authored andcommitted
printk: ringbuffer: Clarify special lpos values
For empty line records, no data blocks are created. Instead, these valid records are identified by special logical position values (in fields of @prb_desc.text_blk_lpos). Currently the macro NO_LPOS is used for empty line records. This name is confusing because it does not imply _why_ there is no data block. Rename NO_LPOS to EMPTY_LINE_LPOS so that it is clear why there is no data block. Also add comments explaining the use of EMPTY_LINE_LPOS as well as clarification to the values used to represent data-less blocks. Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
1 parent 5f72e52 commit 5113cf5

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

kernel/printk/printk_ringbuffer.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,13 @@ static char *data_alloc(struct printk_ringbuffer *rb, unsigned int size,
10341034
unsigned long next_lpos;
10351035

10361036
if (size == 0) {
1037-
/* Specify a data-less block. */
1038-
blk_lpos->begin = NO_LPOS;
1039-
blk_lpos->next = NO_LPOS;
1037+
/*
1038+
* Data blocks are not created for empty lines. Instead, the
1039+
* reader will recognize these special lpos values and handle
1040+
* it appropriately.
1041+
*/
1042+
blk_lpos->begin = EMPTY_LINE_LPOS;
1043+
blk_lpos->next = EMPTY_LINE_LPOS;
10401044
return NULL;
10411045
}
10421046

@@ -1214,10 +1218,18 @@ static const char *get_data(struct prb_data_ring *data_ring,
12141218

12151219
/* Data-less data block description. */
12161220
if (BLK_DATALESS(blk_lpos)) {
1217-
if (blk_lpos->begin == NO_LPOS && blk_lpos->next == NO_LPOS) {
1221+
/*
1222+
* Records that are just empty lines are also valid, even
1223+
* though they do not have a data block. For such records
1224+
* explicitly return empty string data to signify success.
1225+
*/
1226+
if (blk_lpos->begin == EMPTY_LINE_LPOS &&
1227+
blk_lpos->next == EMPTY_LINE_LPOS) {
12181228
*data_size = 0;
12191229
return "";
12201230
}
1231+
1232+
/* Data lost, invalid, or otherwise unavailable. */
12211233
return NULL;
12221234
}
12231235

kernel/printk/printk_ringbuffer.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,22 @@ enum desc_state {
127127
#define DESC_SV(id, state) (((unsigned long)state << DESC_FLAGS_SHIFT) | id)
128128
#define DESC_ID_MASK (~DESC_FLAGS_MASK)
129129
#define DESC_ID(sv) ((sv) & DESC_ID_MASK)
130+
131+
/*
132+
* Special data block logical position values (for fields of
133+
* @prb_desc.text_blk_lpos).
134+
*
135+
* - Bit0 is used to identify if the record has no data block. (Implemented in
136+
* the LPOS_DATALESS() macro.)
137+
*
138+
* - Bit1 specifies the reason for not having a data block.
139+
*
140+
* These special values could never be real lpos values because of the
141+
* meta data and alignment padding of data blocks. (See to_blk_size() for
142+
* details.)
143+
*/
130144
#define FAILED_LPOS 0x1
131-
#define NO_LPOS 0x3
145+
#define EMPTY_LINE_LPOS 0x3
132146

133147
#define FAILED_BLK_LPOS \
134148
{ \

0 commit comments

Comments
 (0)