Skip to content

Commit 8c1723c

Browse files
author
Fox Snowpatch
committed
1 parent 182544a commit 8c1723c

1 file changed

Lines changed: 47 additions & 9 deletions

File tree

arch/powerpc/perf/hv-gpci.c

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <linux/init.h>
1313
#include <linux/perf_event.h>
14+
#include <linux/sysfs.h>
1415
#include <asm/firmware.h>
1516
#include <asm/hvcall.h>
1617
#include <asm/io.h>
@@ -134,6 +135,7 @@ static unsigned long systeminfo_gpci_request(u32 req, u32 starting_index,
134135
size_t *n, struct hv_gpci_request_buffer *arg)
135136
{
136137
unsigned long ret;
138+
int len;
137139
size_t i, j;
138140

139141
arg->params.counter_request = cpu_to_be32(req);
@@ -176,9 +178,17 @@ static unsigned long systeminfo_gpci_request(u32 req, u32 starting_index,
176178
for (i = 0; i < be16_to_cpu(arg->params.returned_values); i++) {
177179
j = i * be16_to_cpu(arg->params.cv_element_size);
178180

179-
for (; j < (i + 1) * be16_to_cpu(arg->params.cv_element_size); j++)
180-
*n += sprintf(buf + *n, "%02x", (u8)arg->bytes[j]);
181-
*n += sprintf(buf + *n, "\n");
181+
for (; j < (i + 1) * be16_to_cpu(arg->params.cv_element_size);
182+
j++) {
183+
len = sysfs_emit_at(buf, *n, "%02x", (u8)arg->bytes[j]);
184+
if (!len)
185+
return -EFBIG;
186+
*n += len;
187+
}
188+
len = sysfs_emit_at(buf, *n, "\n");
189+
if (!len)
190+
return -EFBIG;
191+
*n += len;
182192
}
183193

184194
if (*n >= PAGE_SIZE) {
@@ -465,6 +475,7 @@ static void affinity_domain_via_partition_result_parse(int returned_values,
465475
int element_size, char *buf, size_t *last_element,
466476
size_t *n, struct hv_gpci_request_buffer *arg)
467477
{
478+
int len;
468479
size_t i = 0, j = 0;
469480
size_t k, l, m;
470481
uint16_t total_affinity_domain_ele, size_of_each_affinity_domain_ele;
@@ -483,22 +494,49 @@ static void affinity_domain_via_partition_result_parse(int returned_values,
483494
*/
484495
while (i < returned_values) {
485496
k = j;
486-
for (; k < j + element_size; k++)
487-
*n += sprintf(buf + *n, "%02x", (u8)arg->bytes[k]);
488-
*n += sprintf(buf + *n, "\n");
497+
for (; k < j + element_size; k++) {
498+
len = sysfs_emit_at(buf, *n, "%02x", (u8)arg->bytes[k]);
499+
if (!len) {
500+
*n = PAGE_SIZE;
501+
return;
502+
}
503+
*n += len;
504+
}
505+
len = sysfs_emit_at(buf, *n, "\n");
506+
if (!len) {
507+
*n = PAGE_SIZE;
508+
return;
509+
}
510+
*n += len;
489511

490512
total_affinity_domain_ele = (u8)arg->bytes[k - 2] << 8 | (u8)arg->bytes[k - 3];
491513
size_of_each_affinity_domain_ele = (u8)arg->bytes[k] << 8 | (u8)arg->bytes[k - 1];
492514

493515
for (l = 0; l < total_affinity_domain_ele; l++) {
494516
for (m = 0; m < size_of_each_affinity_domain_ele; m++) {
495-
*n += sprintf(buf + *n, "%02x", (u8)arg->bytes[k]);
517+
len = sysfs_emit_at(buf, *n, "%02x",
518+
(u8)arg->bytes[k]);
519+
if (!len) {
520+
*n = PAGE_SIZE;
521+
return;
522+
}
523+
*n += len;
496524
k++;
497525
}
498-
*n += sprintf(buf + *n, "\n");
526+
len = sysfs_emit_at(buf, *n, "\n");
527+
if (!len) {
528+
*n = PAGE_SIZE;
529+
return;
530+
}
531+
*n += len;
499532
}
500533

501-
*n += sprintf(buf + *n, "\n");
534+
len = sysfs_emit_at(buf, *n, "\n");
535+
if (!len) {
536+
*n = PAGE_SIZE;
537+
return;
538+
}
539+
*n += len;
502540
i++;
503541
j = k;
504542
}

0 commit comments

Comments
 (0)