lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening PHC | |
Open Source and information security mailing list archives
| ||
|
Date: Wed, 15 Oct 2014 14:49:39 +0300 From: Octavian Purdila <octavian.purdila@...el.com> To: Guenter Roeck <linux@...ck-us.net> Cc: Wolfram Sang <wsa@...-dreams.de>, Johan Hovold <johan@...nel.org>, linux-i2c <linux-i2c@...r.kernel.org>, linux-api@...r.kernel.org, lkml <linux-kernel@...r.kernel.org> Subject: Re: [RFC PATCH v2 3/3] i2c: show and change bus frequency via sysfs On Tue, Oct 14, 2014 at 6:41 PM, Guenter Roeck <linux@...ck-us.net> wrote: > > On Tue, Oct 14, 2014 at 05:48:14PM +0300, Octavian Purdila wrote: > > 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> > > + > > +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. We can't use DEVIE_ATTR_RW either, because transforming a RW entry to a RO entry with is visible is not possible: fs/sysfs/group.c: 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); Of course if we only allow a RW frequency entry as you suggest below, then we can use DEVICE_ATTR_RW. > > + > > + > > +static ssize_t > > +i2c_sysfs_min_freq_show(struct device *dev, struct device_attribute *attr, > > + char *buf) > > +{ > > + struct i2c_adapter *adap = to_i2c_adapter(dev); > > + > > + return snprintf(buf, PAGE_SIZE, "%d\n", adap->min_freq); > > +} > > + > > +static DEVICE_ATTR(bus_min_frequency, S_IRUGO, i2c_sysfs_min_freq_show, NULL); > > + > > Consider using DEVICE_ATTR_RO. > OK. > > +static ssize_t > > +i2c_sysfs_max_freq_show(struct device *dev, struct device_attribute *attr, > > + char *buf) > > +{ > > + struct i2c_adapter *adap = to_i2c_adapter(dev); > > + > > + return snprintf(buf, PAGE_SIZE, "%d\n", adap->max_freq); > > +} > > + > > +static DEVICE_ATTR(bus_max_frequency, S_IRUGO, i2c_sysfs_max_freq_show, NULL); > > + > Consider using DEVICE_ATTR_RO. > OK. > Overall, it seems to me that the bus_ in front of the attrribute names > is really not necessary. The attributes are attached to the adapter, so it > should be obvious that the attributes describe the adapter (=bus) frequency and > not some other frequency. > > > +umode_t i2c_adapter_visible_attr(struct kobject *kobj, > > + struct attribute *attr, int idx) > > static umode_t > Oops :) > > +{ > > + struct device *dev = container_of(kobj, struct device, kobj); > > + struct i2c_adapter *adap = to_i2c_adapter(dev); > > + umode_t mode = attr->mode; > > + > > + if (attr == &dev_attr_bus_min_frequency.attr) > > + return adap->min_freq ? mode : 0; > > + > > + if (attr == &dev_attr_bus_max_frequency.attr) > > + return adap->max_freq ? mode : 0; > > + > > + if (attr == &dev_attr_bus_frequency.attr) { > > + if (adap->set_freq) > > + mode |= S_IWUSR; > > + return adap->freq ? mode : 0; > > Personally, I would make all those attributes only visible if the adapter > supports setting the frquency, and not bother with other conditions, > to keep things simple. Not a strong call, though. > I don't have a strong opinion either. I think a RO frequency entry would help with debugging, but I am not sure how useful it is in practice. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@...r.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists