static struct class_attribute hcsr04_class_attrs[] = {
__ATTR(value, S_IRUGO | S_IWUSR, hcsr04_value_read, hcsr04_value_write),
__ATTR_NULL,
};
`__ATTR` 宏展開為 `struct attribute` 初始化,**第三/四參數需為 `ssize_t (*show)(struct class *, struct class_attribute *, char *)` 和 `ssize_t (*store)(struct class *, struct class_attribute *, const char *, size_t)` 類型**。若你的 `hcsr04_value_read/write` 簽名不匹配 (如參數順序錯、缺少 `size_t`、返回類型錯),即報此錯。
static ssize_t hcsr04_value_show(struct class *c, struct class_attribute *attr, char *buf) {
return sprintf(buf, "%d\n", current_value);
}
static ssize_t hcsr04_value_store(struct class *c, struct class_attribute *attr, const char *buf, size_t count) {
kstrtoint(buf, 10, ¤t_value);
return count;
}