return pcpu_stats;
}
-#define spi_pcpu_stats_totalize(ret, in, field) \
-do { \
- int i; \
- ret = 0; \
- for_each_possible_cpu(i) { \
- const struct spi_statistics *pcpu_stats; \
- u64 inc; \
- unsigned int start; \
- pcpu_stats = per_cpu_ptr(in, i); \
- do { \
- start = u64_stats_fetch_begin( \
- &pcpu_stats->syncp); \
- inc = u64_stats_read(&pcpu_stats->field); \
- } while (u64_stats_fetch_retry( \
- &pcpu_stats->syncp, start)); \
- ret += inc; \
- } \
-} while (0)
+static ssize_t spi_emit_pcpu_stats(struct spi_statistics __percpu *stat,
+ char *buf, size_t offset)
+{
+ u64 val = 0;
+ int i;
+
+ for_each_possible_cpu(i) {
+ const struct spi_statistics *pcpu_stats;
+ u64_stats_t *field;
+ unsigned int start;
+ u64 inc;
+
+ pcpu_stats = per_cpu_ptr(stat, i);
+ field = (void *)pcpu_stats + offset;
+ do {
+ start = u64_stats_fetch_begin(&pcpu_stats->syncp);
+ inc = u64_stats_read(field);
+ } while (u64_stats_fetch_retry(&pcpu_stats->syncp, start));
+ val += inc;
+ }
+ return sysfs_emit(buf, "%llu\n", val);
+}
#define SPI_STATISTICS_ATTRS(field, file) \
static ssize_t spi_controller_##field##_show(struct device *dev, \
static ssize_t spi_statistics_##name##_show(struct spi_statistics __percpu *stat, \
char *buf) \
{ \
- ssize_t len; \
- u64 val; \
- spi_pcpu_stats_totalize(val, stat, field); \
- len = sysfs_emit(buf, "%llu\n", val); \
- return len; \
+ return spi_emit_pcpu_stats(stat, buf, \
+ offsetof(struct spi_statistics, field)); \
} \
SPI_STATISTICS_ATTRS(name, file)