On Jun 13 2008, at 19:00, Chris Ball was caught saying: > This uses the OLPC EC 0x35/0x25 interface. > > Question: is simple_strtoul() safe here?
I think the preffered way to do this is via sscanf() of the incoming buffer as you can catch errors such as non-integer input. simple_stroul() will just return 0 which is not what we want. I'd also change the mode to 0400 as this is a write-only bit. My preffered option is to make it r/w, call it wlan_enabled and than we could check the state via the file too by storing the current setting. ~Deepak > > Signed-off-by: Chris Ball <[EMAIL PROTECTED]> > --- > arch/x86/kernel/olpc-pm.c | 19 +++++++++++++++++++ > 1 files changed, 19 insertions(+), 0 deletions(-) > > diff --git a/arch/x86/kernel/olpc-pm.c b/arch/x86/kernel/olpc-pm.c > index e99a464..9f0a565 100644 > --- a/arch/x86/kernel/olpc-pm.c > +++ b/arch/x86/kernel/olpc-pm.c > @@ -43,6 +43,8 @@ > /* These, and the battery EC commands, should be in an olpc.h. */ > #define EC_WRITE_SCI_MASK 0x1b > #define EC_READ_SCI_MASK 0x1c > +#define EC_WLAN_ENTER_RESET 0x35 > +#define EC_WLAN_LEAVE_RESET 0x25 > > extern void do_olpc_suspend_lowlevel(void); > > @@ -661,6 +663,19 @@ static ssize_t wackup_show(struct kobject *s, struct > kobj_attribute *attr, > return sprintf(buf, "%s\n", wackup_source ? wackup_source : "none"); > } > > +static ssize_t wlanreset_execute(struct kobject *s, struct kobj_attribute > *attr, > + const char *buf, size_t n) > +{ > + unsigned int val = simple_strtoul(buf, NULL, 0); > + if (val == 1) { > + olpc_ec_cmd(EC_WLAN_ENTER_RESET, NULL, 0, NULL, 0); > + } > + else if (val == 0) { > + olpc_ec_cmd(EC_WLAN_LEAVE_RESET, NULL, 0, NULL, 0); > + } > + return n; > +} > + > static struct kobj_attribute control_attr = > __ATTR(olpc-pm, 0644, control_show, control_store); > > @@ -670,10 +685,14 @@ static struct kobj_attribute test_attr = > static struct kobj_attribute wackup_attr = > __ATTR(wakeup-source, 0400, wackup_show, NULL); > > +static struct kobj_attribute wlanreset_attr = > + __ATTR(wlan-reset, 0644, NULL, wlanreset_execute); > + > static struct attribute * olpc_attributes[] = { > &control_attr.attr, > &test_attr.attr, > &wackup_attr.attr, > + &wlanreset_attr.attr, > NULL > }; > > -- > 1.5.4.3 -- Deepak Saxena <[EMAIL PROTECTED]> _______________________________________________ Devel mailing list Devel@lists.laptop.org http://lists.laptop.org/listinfo/devel