summaryrefslogtreecommitdiffstats
path: root/hw/net
diff options
context:
space:
mode:
authorRichard Henderson2022-04-17 20:29:49 +0200
committerRichard Henderson2022-04-20 19:51:11 +0200
commit78b548583e0725bb7054162a31dac552b01c02a8 (patch)
treee8e56b975713665391fddd1534e8642ed000c29f /hw/net
parenthw/xen: Split out xen_pv_output_msg (diff)
downloadqemu-78b548583e0725bb7054162a31dac552b01c02a8.tar.gz
qemu-78b548583e0725bb7054162a31dac552b01c02a8.tar.xz
qemu-78b548583e0725bb7054162a31dac552b01c02a8.zip
*: Use fprintf between qemu_log_trylock/unlock
Inside qemu_log, we perform qemu_log_trylock/unlock, which need not be done if we have already performed the lock beforehand. Always check the result of qemu_log_trylock -- only checking qemu_loglevel_mask races with the acquisition of the lock on the logfile. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20220417183019.755276-10-richard.henderson@linaro.org>
Diffstat (limited to 'hw/net')
-rw-r--r--hw/net/can/can_sja1000.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/hw/net/can/can_sja1000.c b/hw/net/can/can_sja1000.c
index 300313dfb8..23d634af6f 100644
--- a/hw/net/can/can_sja1000.c
+++ b/hw/net/can/can_sja1000.c
@@ -249,19 +249,21 @@ static void can_display_msg(const char *prefix, const qemu_can_frame *msg)
int i;
FILE *logfile = qemu_log_trylock();
- qemu_log("%s%03X [%01d] %s %s",
- prefix,
- msg->can_id & QEMU_CAN_EFF_MASK,
- msg->can_dlc,
- msg->can_id & QEMU_CAN_EFF_FLAG ? "EFF" : "SFF",
- msg->can_id & QEMU_CAN_RTR_FLAG ? "RTR" : "DAT");
-
- for (i = 0; i < msg->can_dlc; i++) {
- qemu_log(" %02X", msg->data[i]);
- }
- qemu_log("\n");
- qemu_log_flush();
- qemu_log_unlock(logfile);
+ if (logfile) {
+ fprintf(logfile, "%s%03X [%01d] %s %s",
+ prefix,
+ msg->can_id & QEMU_CAN_EFF_MASK,
+ msg->can_dlc,
+ msg->can_id & QEMU_CAN_EFF_FLAG ? "EFF" : "SFF",
+ msg->can_id & QEMU_CAN_RTR_FLAG ? "RTR" : "DAT");
+
+ for (i = 0; i < msg->can_dlc; i++) {
+ fprintf(logfile, " %02X", msg->data[i]);
+ }
+ fprintf(logfile, "\n");
+ qemu_log_flush();
+ qemu_log_unlock(logfile);
+ }
}
static void buff2frame_pel(const uint8_t *buff, qemu_can_frame *frame)