lkml.org 
[lkml]   [2021]   [Nov]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [RFC Patch Resend 1/2] i2c debug counters as sysfs attributes
From
Date
On Tue, 2021-11-09 at 14:53 -0800, Sui Chen wrote:
> This change adds a few example I2C debug counters as sysfs attributes:
> - ber_cnt (bus error count)
> - nack_cnt (NACK count)
> - rec_fail_cnt, rec_succ_cnt (recovery failure/success count)
> - timeout_cnt (timeout count)
> - i2c_speed (bus frequency)
>
> The function i2c_adapter_create_stats_folder creates a stats directory
> in the device's sysfs directory to hold the debug counters. The platform
> drivers will instantiate the counters in the stats directory if
> available.
[]
> diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
[]
> +static ssize_t ber_cnt_show(struct device* pdev,
> + struct device_attribute* attr, char* buf) {
> + u64* ber_cnt = kobj_to_adapter(pdev)->stats->ber_cnt;
> + if (ber_cnt == NULL) return 0;
> + ssize_t ret = sprintf(buf, "%llu\n", *ber_cnt);

Please do not declare after code.

And this should instead use:

return sysfs_emit(buf, "%llu\n", *ber_cnt);

> + return ret;
> +}
> +DEVICE_ATTR_RO(ber_cnt);
> +
> +ssize_t nack_cnt_show(struct device* pdev,
> + struct device_attribute* attr, char* buf) {
> + u64* nack_cnt = kobj_to_adapter(pdev)->stats->nack_cnt;
> + if (nack_cnt == NULL) return 0;
> + ssize_t ret = sprintf(buf, "%llu\n", *nack_cnt);

etc...


\
 
 \ /
  Last update: 2021-11-10 00:13    [W:0.376 / U:0.744 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site