Skip to content

Commit bbc77aa

Browse files
author
Kent Overstreet
committed
bcache: fix a spurious gcc complaint, use scnprintf
An old version of gcc was complaining about using a const int as the size of a stack allocated array. Which should be fine - but using ARRAY_SIZE() is better, anyways. Also, refactor the code to use scnprintf(). Signed-off-by: Kent Overstreet <koverstreet@google.com>
1 parent 5c69412 commit bbc77aa

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

‎drivers/md/bcache/sysfs.c‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -665,12 +665,10 @@ SHOW(__bch_cache)
665665
int cmp(const void *l, const void *r)
666666
{ return *((uint16_t *) r) - *((uint16_t *) l); }
667667

668-
/* Number of quantiles we compute */
669-
const unsigned nq = 31;
670-
671668
size_t n = ca->sb.nbuckets, i, unused, btree;
672669
uint64_t sum = 0;
673-
uint16_t q[nq], *p, *cached;
670+
/* Compute 31 quantiles */
671+
uint16_t q[31], *p, *cached;
674672
ssize_t ret;
675673

676674
cached = p = vmalloc(ca->sb.nbuckets * sizeof(uint16_t));
@@ -703,26 +701,29 @@ SHOW(__bch_cache)
703701
if (n)
704702
do_div(sum, n);
705703

706-
for (i = 0; i < nq; i++)
707-
q[i] = INITIAL_PRIO - cached[n * (i + 1) / (nq + 1)];
704+
for (i = 0; i < ARRAY_SIZE(q); i++)
705+
q[i] = INITIAL_PRIO - cached[n * (i + 1) /
706+
(ARRAY_SIZE(q) + 1)];
708707

709708
vfree(p);
710709

711-
ret = snprintf(buf, PAGE_SIZE,
712-
"Unused: %zu%%\n"
713-
"Metadata: %zu%%\n"
714-
"Average: %llu\n"
715-
"Sectors per Q: %zu\n"
716-
"Quantiles: [",
717-
unused * 100 / (size_t) ca->sb.nbuckets,
718-
btree * 100 / (size_t) ca->sb.nbuckets, sum,
719-
n * ca->sb.bucket_size / (nq + 1));
720-
721-
for (i = 0; i < nq && ret < (ssize_t) PAGE_SIZE; i++)
722-
ret += snprintf(buf + ret, PAGE_SIZE - ret,
723-
i < nq - 1 ? "%u " : "%u]\n", q[i]);
724-
725-
buf[PAGE_SIZE - 1] = '\0';
710+
ret = scnprintf(buf, PAGE_SIZE,
711+
"Unused: %zu%%\n"
712+
"Metadata: %zu%%\n"
713+
"Average: %llu\n"
714+
"Sectors per Q: %zu\n"
715+
"Quantiles: [",
716+
unused * 100 / (size_t) ca->sb.nbuckets,
717+
btree * 100 / (size_t) ca->sb.nbuckets, sum,
718+
n * ca->sb.bucket_size / (ARRAY_SIZE(q) + 1));
719+
720+
for (i = 0; i < ARRAY_SIZE(q); i++)
721+
ret += scnprintf(buf + ret, PAGE_SIZE - ret,
722+
"%u ", q[i]);
723+
ret--;
724+
725+
ret += scnprintf(buf + ret, PAGE_SIZE - ret, "]\n");
726+
726727
return ret;
727728
}
728729

0 commit comments

Comments
 (0)