* [PATCH] perf cs-etm: Use swap() instead of open coding it
@ 2022-05-06 9:17 Jiapeng Chong
2022-06-20 17:24 ` Mathieu Poirier
0 siblings, 1 reply; 2+ messages in thread
From: Jiapeng Chong @ 2022-05-06 9:17 UTC (permalink / raw)
To: john.garry
Cc: will, mathieu.poirier, leo.yan, suzuki.poulose, mike.leach,
peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
namhyung, linux-arm-kernel, coresight, linux-perf-users,
linux-kernel, Jiapeng Chong, Abaci Robot
Clean the following coccicheck warning:
./tools/perf/util/cs-etm.c:418:34-35: WARNING opportunity for swap().
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
tools/perf/util/cs-etm.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 8b95fb3c4d7b..0cb555cc766f 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -406,18 +406,13 @@ struct cs_etm_packet_queue
static void cs_etm__packet_swap(struct cs_etm_auxtrace *etm,
struct cs_etm_traceid_queue *tidq)
{
- struct cs_etm_packet *tmp;
-
if (etm->synth_opts.branches || etm->synth_opts.last_branch ||
- etm->synth_opts.instructions) {
+ etm->synth_opts.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;
- }
+ swap(tidq->packet, tidq->prev_packet);
}
static void cs_etm__packet_dump(const char *pkt_string)
--
2.20.1.7.g153144c
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] perf cs-etm: Use swap() instead of open coding it
2022-05-06 9:17 [PATCH] perf cs-etm: Use swap() instead of open coding it Jiapeng Chong
@ 2022-06-20 17:24 ` Mathieu Poirier
0 siblings, 0 replies; 2+ messages in thread
From: Mathieu Poirier @ 2022-06-20 17:24 UTC (permalink / raw)
To: Jiapeng Chong
Cc: john.garry, will, leo.yan, suzuki.poulose, mike.leach, peterz,
mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung,
linux-arm-kernel, coresight, linux-perf-users, linux-kernel,
Abaci Robot, james.clark
[Adding James]
Hi Jiapeng,
On Fri, May 06, 2022 at 05:17:18PM +0800, Jiapeng Chong wrote:
> Clean the following coccicheck warning:
>
> ./tools/perf/util/cs-etm.c:418:34-35: WARNING opportunity for swap().
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
> tools/perf/util/cs-etm.c | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index 8b95fb3c4d7b..0cb555cc766f 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
> @@ -406,18 +406,13 @@ struct cs_etm_packet_queue
> static void cs_etm__packet_swap(struct cs_etm_auxtrace *etm,
> struct cs_etm_traceid_queue *tidq)
> {
> - struct cs_etm_packet *tmp;
> -
> if (etm->synth_opts.branches || etm->synth_opts.last_branch ||
> - etm->synth_opts.instructions) {
> + etm->synth_opts.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;
Those 3 lines have burned a lot of eyes... As far as I can remember the idea is
simply to make sure that after that point, ->prev_packet is now set to ->packet
in preparation for the next iteration. There is no point in setting ->packet to
->prev_packet. As such the following would work just fine:
tidq->prev_packet = tidq->packet;
... but I will let James and Leo have a final say on that.
> - }
> + swap(tidq->packet, tidq->prev_packet);
If we absolutely need to keep swapping the packets please add the header file
where swap() is found.
Thanks,
Mathieu
> }
>
> static void cs_etm__packet_dump(const char *pkt_string)
> --
> 2.20.1.7.g153144c
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-06-20 17:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06 9:17 [PATCH] perf cs-etm: Use swap() instead of open coding it Jiapeng Chong
2022-06-20 17:24 ` Mathieu Poirier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).