usb: gadget: hid: add configfs support
Quoted 55 lines · Linux Kernel Mailing List
Gitweb: http://git.kernel.org/linus/;a=commit;h=21a9476a7ba847e413bf1c144d7c614532aed6dd Commit: 21a9476a7ba847e413bf1c144d7c614532aed6dd Parent: 5ca8d3ec9970f4798e68bd21a9d44db3d0ff4da7 Refname: refs/heads/master Author: Andrzej Pietrasiewicz <[email protected]> AuthorDate: Thu Nov 6 11:12:03 2014 +0100 Committer: Felipe Balbi <[email protected]> CommitDate: Thu Nov 6 16:18:19 2014 -0600usb: gadget: hid: add configfs support
Make the hid function available for gadgets composed with configfs.
drivers/usb/gadget/function/f_hid.c +38
-0+ +#define F_HID_OPT (name, prec, limit) \ +static ssize_t f_hid_opts_##name##_show(struct f_hid_opts *opts, char *page)\ +{ \ + int result; \ + \ + mutex_lock(&opts->lock); \ + result = sprintf(page, "%d\n", opts->name); \ + mutex_unlock(&opts->lock); \ + \ + return result; \ +} \ + \ +static ssize_t f_hid_opts_##name##_store(struct f_hid_opts *opts, \ + const char *page, size_t len) \ +{ \ + int ret; \ + u##prec num; \ + \ + mutex_lock(&opts->lock); \ + if (opts->refcnt) { \ + ret = -EBUSY; \ + goto end; \ + } \ + \ + ret = kstrtou##prec(page, 0, &num); \ + if (ret) \ + goto end; \ + \ + if (num > limit) { \ + ret = -EINVAL; \ + goto end; \ + } \ + opts->name = num; \ + ret = len; \ + \ +end: \ + mutex_unlock(&opts->lock); \
drivers/usb/gadget/function/f_hid.c
Quoted 10 lines
drivers/usb/gadget/function/f_hid.c +10
-0+return ret; \ +} \ + \ +static struct f_hid_opts_attribute f_hid_opts_##name = \ + __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, f_hid_opts_##name##_show,\ + f_hid_opts_##name##_store) + +F_HID_OPT (subclass,8 ,255 ); +F_HID_OPT (protocol,8 ,255 ); +F_HID_OPT (report_length,16 ,65536 );
While all three of the above lines trigger a (false positive) compiler warning:
warning: comparison is always false due to limited range of data type
it's a bit sloppy to use "2^8-1" for the first two limits, and "2^16" (without -1) for
the third limit.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds