Re: [RFC PATCH v2 3/3] i2c: show and change bus frequency via sysfs
From: Guenter Roeck <linux@roeck-us.net>
Date: 2014-10-15 13:46:37
Also in:
linux-i2c, lkml
On 10/15/2014 06:32 AM, Octavian Purdila wrote:
On Wed, Oct 15, 2014 at 4:13 PM, Guenter Roeck [off-list ref] wrote:quoted
On 10/15/2014 04:49 AM, Octavian Purdila wrote:quoted
On Tue, Oct 14, 2014 at 6:41 PM, Guenter Roeck [off-list ref] wrote:quoted
On Tue, Oct 14, 2014 at 05:48:14PM +0300, Octavian Purdila wrote:quoted
This patch adds three new sysfs files: bus_frequency, bus_min_frequency and bus_max_frequency which allows the user to view or change the bus frequency on a per bus level.<snip>quoted
quoted
+ +static DEVICE_ATTR(bus_frequency, S_IRUGO, i2c_sysfs_freq_show, + i2c_sysfs_freq_store);Consider using DEVICE_ATTR_RO here. Also, extra empty line.Unfortunately that won't work because we must transform bus_frequency to a RW entry (via is_visible) if the bus can change the frequency. WeAh yes, you are right.quoted
can't use DEVIE_ATTR_RW either, because transforming a RW entry to a RO entry with is visible is not possible:Why not ? is_visible returns the desired mode. Just like you can return mode | S_IWUSR, you can return mode & ~S_IWUSR. Am I missing something ?Here is how sysfs uses is_visible: static int create_files(struct kernfs_node *parent, struct kobject *kobj, ... if (grp->is_visible) { mode = grp->is_visible(kobj, *attr, i); if (!mode) continue; } error = sysfs_add_file_mode_ns(parent, *attr, false, (*attr)->mode | mode, NULL); so basically is the mode set is the original mode from the attributed "or-ed" with the mode return by is_visible.
Ah, you are right. That's a new one for me. Thanks, I didn't notice earlier. Good to know ;-). Guenter