staging: vhciq_core: replace snprintf with scnprintf

When the number of bytes to be printed exceeds the limit snprintf
returns the number of bytes that would have been printed (if there was
no truncation). This might cause issues, hence use scnprintf which
returns the actual number of bytes printed to buffer always

Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/20190911135112.GA5569@SARKAR
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Rohit Sarkar 2019-09-11 19:21:13 +05:30 committed by Greg Kroah-Hartman
parent 9a4c56be67
commit 63350bdb38
1 changed files with 19 additions and 19 deletions

View File

@ -3322,13 +3322,13 @@ vchiq_dump_shared_state(void *dump_context, struct vchiq_state *state,
char buf[80]; char buf[80];
int len; int len;
len = snprintf(buf, sizeof(buf), len = scnprintf(buf, sizeof(buf),
" %s: slots %d-%d tx_pos=%x recycle=%x", " %s: slots %d-%d tx_pos=%x recycle=%x",
label, shared->slot_first, shared->slot_last, label, shared->slot_first, shared->slot_last,
shared->tx_pos, shared->slot_queue_recycle); shared->tx_pos, shared->slot_queue_recycle);
vchiq_dump(dump_context, buf, len + 1); vchiq_dump(dump_context, buf, len + 1);
len = snprintf(buf, sizeof(buf), len = scnprintf(buf, sizeof(buf),
" Slots claimed:"); " Slots claimed:");
vchiq_dump(dump_context, buf, len + 1); vchiq_dump(dump_context, buf, len + 1);
@ -3336,7 +3336,7 @@ vchiq_dump_shared_state(void *dump_context, struct vchiq_state *state,
struct vchiq_slot_info slot_info = struct vchiq_slot_info slot_info =
*SLOT_INFO_FROM_INDEX(state, i); *SLOT_INFO_FROM_INDEX(state, i);
if (slot_info.use_count != slot_info.release_count) { if (slot_info.use_count != slot_info.release_count) {
len = snprintf(buf, sizeof(buf), len = scnprintf(buf, sizeof(buf),
" %d: %d/%d", i, slot_info.use_count, " %d: %d/%d", i, slot_info.use_count,
slot_info.release_count); slot_info.release_count);
vchiq_dump(dump_context, buf, len + 1); vchiq_dump(dump_context, buf, len + 1);
@ -3344,7 +3344,7 @@ vchiq_dump_shared_state(void *dump_context, struct vchiq_state *state,
} }
for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) { for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) {
len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)", len = scnprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)",
debug_names[i], shared->debug[i], shared->debug[i]); debug_names[i], shared->debug[i], shared->debug[i]);
vchiq_dump(dump_context, buf, len + 1); vchiq_dump(dump_context, buf, len + 1);
} }
@ -3357,11 +3357,11 @@ vchiq_dump_state(void *dump_context, struct vchiq_state *state)
int len; int len;
int i; int i;
len = snprintf(buf, sizeof(buf), "State %d: %s", state->id, len = scnprintf(buf, sizeof(buf), "State %d: %s", state->id,
conn_state_names[state->conn_state]); conn_state_names[state->conn_state]);
vchiq_dump(dump_context, buf, len + 1); vchiq_dump(dump_context, buf, len + 1);
len = snprintf(buf, sizeof(buf), len = scnprintf(buf, sizeof(buf),
" tx_pos=%x(@%pK), rx_pos=%x(@%pK)", " tx_pos=%x(@%pK), rx_pos=%x(@%pK)",
state->local->tx_pos, state->local->tx_pos,
state->tx_data + (state->local_tx_pos & VCHIQ_SLOT_MASK), state->tx_data + (state->local_tx_pos & VCHIQ_SLOT_MASK),
@ -3369,13 +3369,13 @@ vchiq_dump_state(void *dump_context, struct vchiq_state *state)
state->rx_data + (state->rx_pos & VCHIQ_SLOT_MASK)); state->rx_data + (state->rx_pos & VCHIQ_SLOT_MASK));
vchiq_dump(dump_context, buf, len + 1); vchiq_dump(dump_context, buf, len + 1);
len = snprintf(buf, sizeof(buf), len = scnprintf(buf, sizeof(buf),
" Version: %d (min %d)", " Version: %d (min %d)",
VCHIQ_VERSION, VCHIQ_VERSION_MIN); VCHIQ_VERSION, VCHIQ_VERSION_MIN);
vchiq_dump(dump_context, buf, len + 1); vchiq_dump(dump_context, buf, len + 1);
if (VCHIQ_ENABLE_STATS) { if (VCHIQ_ENABLE_STATS) {
len = snprintf(buf, sizeof(buf), len = scnprintf(buf, sizeof(buf),
" Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, " " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, "
"error_count=%d", "error_count=%d",
state->stats.ctrl_tx_count, state->stats.ctrl_rx_count, state->stats.ctrl_tx_count, state->stats.ctrl_rx_count,
@ -3383,7 +3383,7 @@ vchiq_dump_state(void *dump_context, struct vchiq_state *state)
vchiq_dump(dump_context, buf, len + 1); vchiq_dump(dump_context, buf, len + 1);
} }
len = snprintf(buf, sizeof(buf), len = scnprintf(buf, sizeof(buf),
" Slots: %d available (%d data), %d recyclable, %d stalls " " Slots: %d available (%d data), %d recyclable, %d stalls "
"(%d data)", "(%d data)",
((state->slot_queue_available * VCHIQ_SLOT_SIZE) - ((state->slot_queue_available * VCHIQ_SLOT_SIZE) -
@ -3416,7 +3416,7 @@ vchiq_dump_service_state(void *dump_context, struct vchiq_service *service)
char buf[80]; char buf[80];
int len; int len;
len = snprintf(buf, sizeof(buf), "Service %u: %s (ref %u)", len = scnprintf(buf, sizeof(buf), "Service %u: %s (ref %u)",
service->localport, srvstate_names[service->srvstate], service->localport, srvstate_names[service->srvstate],
service->ref_count - 1); /*Don't include the lock just taken*/ service->ref_count - 1); /*Don't include the lock just taken*/
@ -3428,17 +3428,17 @@ vchiq_dump_service_state(void *dump_context, struct vchiq_service *service)
int tx_pending, rx_pending; int tx_pending, rx_pending;
if (service->remoteport != VCHIQ_PORT_FREE) { if (service->remoteport != VCHIQ_PORT_FREE) {
int len2 = snprintf(remoteport, sizeof(remoteport), int len2 = scnprintf(remoteport, sizeof(remoteport),
"%u", service->remoteport); "%u", service->remoteport);
if (service->public_fourcc != VCHIQ_FOURCC_INVALID) if (service->public_fourcc != VCHIQ_FOURCC_INVALID)
snprintf(remoteport + len2, scnprintf(remoteport + len2,
sizeof(remoteport) - len2, sizeof(remoteport) - len2,
" (client %x)", service->client_id); " (client %x)", service->client_id);
} else } else
strcpy(remoteport, "n/a"); strcpy(remoteport, "n/a");
len += snprintf(buf + len, sizeof(buf) - len, len += scnprintf(buf + len, sizeof(buf) - len,
" '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)", " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)",
VCHIQ_FOURCC_AS_4CHARS(fourcc), VCHIQ_FOURCC_AS_4CHARS(fourcc),
remoteport, remoteport,
@ -3455,7 +3455,7 @@ vchiq_dump_service_state(void *dump_context, struct vchiq_service *service)
rx_pending = service->bulk_rx.local_insert - rx_pending = service->bulk_rx.local_insert -
service->bulk_rx.remote_insert; service->bulk_rx.remote_insert;
len = snprintf(buf, sizeof(buf), len = scnprintf(buf, sizeof(buf),
" Bulk: tx_pending=%d (size %d)," " Bulk: tx_pending=%d (size %d),"
" rx_pending=%d (size %d)", " rx_pending=%d (size %d)",
tx_pending, tx_pending,
@ -3468,7 +3468,7 @@ vchiq_dump_service_state(void *dump_context, struct vchiq_service *service)
if (VCHIQ_ENABLE_STATS) { if (VCHIQ_ENABLE_STATS) {
vchiq_dump(dump_context, buf, len + 1); vchiq_dump(dump_context, buf, len + 1);
len = snprintf(buf, sizeof(buf), len = scnprintf(buf, sizeof(buf),
" Ctrl: tx_count=%d, tx_bytes=%llu, " " Ctrl: tx_count=%d, tx_bytes=%llu, "
"rx_count=%d, rx_bytes=%llu", "rx_count=%d, rx_bytes=%llu",
service->stats.ctrl_tx_count, service->stats.ctrl_tx_count,
@ -3477,7 +3477,7 @@ vchiq_dump_service_state(void *dump_context, struct vchiq_service *service)
service->stats.ctrl_rx_bytes); service->stats.ctrl_rx_bytes);
vchiq_dump(dump_context, buf, len + 1); vchiq_dump(dump_context, buf, len + 1);
len = snprintf(buf, sizeof(buf), len = scnprintf(buf, sizeof(buf),
" Bulk: tx_count=%d, tx_bytes=%llu, " " Bulk: tx_count=%d, tx_bytes=%llu, "
"rx_count=%d, rx_bytes=%llu", "rx_count=%d, rx_bytes=%llu",
service->stats.bulk_tx_count, service->stats.bulk_tx_count,
@ -3486,7 +3486,7 @@ vchiq_dump_service_state(void *dump_context, struct vchiq_service *service)
service->stats.bulk_rx_bytes); service->stats.bulk_rx_bytes);
vchiq_dump(dump_context, buf, len + 1); vchiq_dump(dump_context, buf, len + 1);
len = snprintf(buf, sizeof(buf), len = scnprintf(buf, sizeof(buf),
" %d quota stalls, %d slot stalls, " " %d quota stalls, %d slot stalls, "
"%d bulk stalls, %d aborted, %d errors", "%d bulk stalls, %d aborted, %d errors",
service->stats.quota_stalls, service->stats.quota_stalls,
@ -3562,9 +3562,9 @@ void vchiq_log_dump_mem(const char *label, u32 addr, const void *void_mem,
for (offset = 0; offset < 16; offset++) { for (offset = 0; offset < 16; offset++) {
if (offset < num_bytes) if (offset < num_bytes)
s += snprintf(s, 4, "%02x ", mem[offset]); s += scnprintf(s, 4, "%02x ", mem[offset]);
else else
s += snprintf(s, 4, " "); s += scnprintf(s, 4, " ");
} }
for (offset = 0; offset < 16; offset++) { for (offset = 0; offset < 16; offset++) {