printk: ringbuffer: add BLK_DATALESS() macro
authorJohn Ogness <john.ogness@linutronix.de>
Mon, 14 Sep 2020 12:33:50 +0000 (14:39 +0206)
committerPetr Mladek <pmladek@suse.com>
Tue, 15 Sep 2020 13:44:49 +0000 (15:44 +0200)
Rather than continually needing to explicitly check @begin and @next
to identify a dataless block, introduce and use a BLK_DATALESS()
macro.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20200914123354.832-3-john.ogness@linutronix.de
kernel/printk/printk_ringbuffer.c

index 664552cb931c3d0a981ba4f6dfa5a420a710c18b..195e6f4d4df665f1dfa4a646b92e14df7f66760b 100644 (file)
 
 /* Determine if a logical position refers to a data-less block. */
 #define LPOS_DATALESS(lpos)            ((lpos) & 1UL)
+#define BLK_DATALESS(blk)              (LPOS_DATALESS((blk)->begin) && \
+                                        LPOS_DATALESS((blk)->next))
 
 /* Get the logical position at index 0 of the current wrap. */
 #define DATA_THIS_WRAP_START_LPOS(data_ring, lpos) \
@@ -1038,7 +1040,7 @@ static unsigned int space_used(struct prb_data_ring *data_ring,
                               struct prb_data_blk_lpos *blk_lpos)
 {
        /* Data-less blocks take no space. */
-       if (LPOS_DATALESS(blk_lpos->begin))
+       if (BLK_DATALESS(blk_lpos))
                return 0;
 
        if (DATA_WRAPS(data_ring, blk_lpos->begin) == DATA_WRAPS(data_ring, blk_lpos->next)) {
@@ -1071,7 +1073,7 @@ static const char *get_data(struct prb_data_ring *data_ring,
        struct prb_data_block *db;
 
        /* Data-less data block description. */
-       if (LPOS_DATALESS(blk_lpos->begin) && LPOS_DATALESS(blk_lpos->next)) {
+       if (BLK_DATALESS(blk_lpos)) {
                if (blk_lpos->begin == NO_LPOS && blk_lpos->next == NO_LPOS) {
                        *data_size = 0;
                        return "";