procfs: use length from snprintf instead of recomputing

Change-Id: I75ba4cf5c2e94798d183728c11bb34032cdddf5a
This commit is contained in:
Dominique Martinet
2018-08-30 15:05:11 +09:00
committed by Masamichi Takagi
parent 201fa7fb55
commit a032dc3d1b

View File

@ -313,8 +313,8 @@ int process_procfs_request(struct ikc_scd_packet *rpacket)
int cpu; int cpu;
for (cpu = 0; cpu < num_processors; ++cpu) { for (cpu = 0; cpu < num_processors; ++cpu) {
snprintf(buf, count, "cpu%d\n", cpu); ans = snprintf(buf, count, "cpu%d\n", cpu);
if (buf_add(&buf_top, &buf_cur, buf, strlen(buf)) < 0) if (buf_add(&buf_top, &buf_cur, buf, ans) < 0)
goto err; goto err;
} }
ans = 0; ans = 0;
@ -325,7 +325,7 @@ int process_procfs_request(struct ikc_scd_packet *rpacket)
ans = ihk_mc_show_cpuinfo(buf, count, 0, &eof); ans = ihk_mc_show_cpuinfo(buf, count, 0, &eof);
if (ans < 0) if (ans < 0)
goto err; goto err;
if (buf_add(&buf_top, &buf_cur, buf, strlen(buf)) < 0) if (buf_add(&buf_top, &buf_cur, buf, ans) < 0)
goto err; goto err;
ans = 0; ans = 0;
goto end; goto end;
@ -416,7 +416,7 @@ int process_procfs_request(struct ikc_scd_packet *rpacket)
* address perms offset dev inode pathname * address perms offset dev inode pathname
* 08048000-08056000 r-xp 00000000 03:0c 64593 /usr/sbin/gpm * 08048000-08056000 r-xp 00000000 03:0c 64593 /usr/sbin/gpm
*/ */
snprintf(buf, count, ans = snprintf(buf, count,
"%012lx-%012lx %s%s%s%s %lx %lx:%lx %d\t\t\t%s\n", "%012lx-%012lx %s%s%s%s %lx %lx:%lx %d\t\t\t%s\n",
range->start, range->end, range->start, range->end,
range->flag & VR_PROT_READ ? "r" : "-", range->flag & VR_PROT_READ ? "r" : "-",
@ -442,7 +442,7 @@ int process_procfs_request(struct ikc_scd_packet *rpacket)
"" ""
); );
if (buf_add(&buf_top, &buf_cur, buf, strlen(buf)) < 0) { if (buf_add(&buf_top, &buf_cur, buf, ans) < 0) {
ihk_mc_spinlock_unlock_noirq(&vm->memory_range_lock); ihk_mc_spinlock_unlock_noirq(&vm->memory_range_lock);
goto err; goto err;
} }
@ -552,7 +552,7 @@ int process_procfs_request(struct ikc_scd_packet *rpacket)
state = "T (tracing stop)"; state = "T (tracing stop)";
else if (proc->status == PS_EXITED) else if (proc->status == PS_EXITED)
state = "Z (zombie)"; state = "Z (zombie)";
sprintf(buf, ans = snprintf(buf, count,
"Pid:\t%d\n" "Pid:\t%d\n"
"Uid:\t%d\t%d\t%d\t%d\n" "Uid:\t%d\t%d\t%d\t%d\n"
"Gid:\t%d\t%d\t%d\t%d\n" "Gid:\t%d\t%d\t%d\t%d\n"
@ -563,27 +563,30 @@ int process_procfs_request(struct ikc_scd_packet *rpacket)
proc->rgid, proc->egid, proc->sgid, proc->fsgid, proc->rgid, proc->egid, proc->sgid, proc->fsgid,
state, state,
(lockedsize + 1023) >> 10); (lockedsize + 1023) >> 10);
if (buf_add(&buf_top, &buf_cur, buf, strlen(buf)) < 0) { if (buf_add(&buf_top, &buf_cur, buf, ans) < 0) {
goto err; goto err;
} }
sprintf(buf, "Cpus_allowed:\t%s\n", cpu_bitmask); ans = snprintf(buf, count, "Cpus_allowed:\t%s\n", cpu_bitmask);
if (buf_add(&buf_top, &buf_cur, buf, strlen(buf)) < 0) { if (buf_add(&buf_top, &buf_cur, buf, ans) < 0) {
kfree(bitmasks); kfree(bitmasks);
goto err; goto err;
} }
sprintf(buf, "Cpus_allowed_list:\t%s\n", cpu_list); ans = snprintf(buf, count, "Cpus_allowed_list:\t%s\n",
if (buf_add(&buf_top, &buf_cur, buf, strlen(buf)) < 0) { cpu_list);
if (buf_add(&buf_top, &buf_cur, buf, ans) < 0) {
kfree(bitmasks); kfree(bitmasks);
goto err; goto err;
} }
sprintf(buf, "Mems_allowed:\t%s\n", numa_bitmask); ans = snprintf(buf, count, "Mems_allowed:\t%s\n",
if (buf_add(&buf_top, &buf_cur, buf, strlen(buf)) < 0) { numa_bitmask);
if (buf_add(&buf_top, &buf_cur, buf, ans) < 0) {
kfree(bitmasks); kfree(bitmasks);
goto err; goto err;
} }
sprintf(buf, "Mems_allowed_list:\t%s\n", numa_list); ans = snprintf(buf, count, "Mems_allowed_list:\t%s\n",
if (buf_add(&buf_top, &buf_cur, buf, strlen(buf)) < 0) { numa_list);
if (buf_add(&buf_top, &buf_cur, buf, ans) < 0) {
kfree(bitmasks); kfree(bitmasks);
goto err; goto err;
} }
@ -680,7 +683,7 @@ int process_procfs_request(struct ikc_scd_packet *rpacket)
* cnswap exit_signal processor rt_priority * cnswap exit_signal processor rt_priority
* policy delayacct_blkio_ticks guest_time cguest_time * policy delayacct_blkio_ticks guest_time cguest_time
*/ */
ans = sprintf(buf, ans = snprintf(buf, count,
"%d (%s) %c %d " // pid... "%d (%s) %c %d " // pid...
"%d %d %d %d " // pgrp... "%d %d %d %d " // pgrp...
"%u %lu %lu %lu " // flags... "%u %lu %lu %lu " // flags...
@ -705,7 +708,7 @@ int process_procfs_request(struct ikc_scd_packet *rpacket)
0, 0LL, 0L, 0L // policy... 0, 0LL, 0L, 0L // policy...
); );
if (buf_add(&buf_top, &buf_cur, buf, strlen(buf)) < 0) if (buf_add(&buf_top, &buf_cur, buf, ans) < 0)
goto err; goto err;
ans = 0; ans = 0;
goto end; goto end;