return NULL;
 }
 
+static void cs_etm__packet_swap(struct cs_etm_auxtrace *etm,
+                               struct cs_etm_traceid_queue *tidq)
+{
+       struct cs_etm_packet *tmp;
+
+       if (etm->sample_branches || etm->synth_opts.last_branch ||
+           etm->sample_instructions) {
+               /*
+                * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for
+                * the next incoming packet.
+                */
+               tmp = tidq->packet;
+               tidq->packet = tidq->prev_packet;
+               tidq->prev_packet = tmp;
+       }
+}
+
 static void cs_etm__packet_dump(const char *pkt_string)
 {
        const char *color = PERF_COLOR_BLUE;
                          struct cs_etm_traceid_queue *tidq)
 {
        struct cs_etm_auxtrace *etm = etmq->etm;
-       struct cs_etm_packet *tmp;
        int ret;
        u8 trace_chan_id = tidq->trace_chan_id;
        u64 instrs_executed = tidq->packet->instr_count;
                }
        }
 
-       if (etm->sample_branches || etm->synth_opts.last_branch) {
-               /*
-                * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for
-                * the next incoming packet.
-                */
-               tmp = tidq->packet;
-               tidq->packet = tidq->prev_packet;
-               tidq->prev_packet = tmp;
-       }
+       cs_etm__packet_swap(etm, tidq);
 
        return 0;
 }
 {
        int err = 0;
        struct cs_etm_auxtrace *etm = etmq->etm;
-       struct cs_etm_packet *tmp;
 
        /* Handle start tracing packet */
        if (tidq->prev_packet->sample_type == CS_ETM_EMPTY)
        }
 
 swap_packet:
-       if (etm->sample_branches || etm->synth_opts.last_branch) {
-               /*
-                * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for
-                * the next incoming packet.
-                */
-               tmp = tidq->packet;
-               tidq->packet = tidq->prev_packet;
-               tidq->prev_packet = tmp;
-       }
+       cs_etm__packet_swap(etm, tidq);
 
        return err;
 }