diff options
author | Ville Syrjala <syrjala@sci.fi> | 2009-01-30 02:42:16 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2009-01-30 02:43:42 -0500 |
commit | 8a49cfa9de4ef47eb9238d625b900d4cdddccf30 (patch) | |
tree | 0999b2678f3df879d82449600bb331837d185aa5 /drivers | |
parent | d329e33c7c2bdcd955a00c84a9363cb309cad352 (diff) |
Input: ati_remote2 - check module params
Validate that the values of the module parameters are within the
supported range. Also print the values in hex since that seems like
a better match for bitmasks than decimal.
Signed-off-by: Ville Syrjala <syrjala@sci.fi>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/input/misc/ati_remote2.c | 64 |
1 files changed, 60 insertions, 4 deletions
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c index 0871d7b2df43..922c05141585 100644 --- a/drivers/input/misc/ati_remote2.c +++ b/drivers/input/misc/ati_remote2.c | |||
@@ -36,12 +36,68 @@ enum { | |||
36 | ATI_REMOTE2_MAX_MODE_MASK = 0x1F, | 36 | ATI_REMOTE2_MAX_MODE_MASK = 0x1F, |
37 | }; | 37 | }; |
38 | 38 | ||
39 | static int ati_remote2_set_mask(const char *val, | ||
40 | struct kernel_param *kp, unsigned int max) | ||
41 | { | ||
42 | unsigned long mask; | ||
43 | int ret; | ||
44 | |||
45 | if (!val) | ||
46 | return -EINVAL; | ||
47 | |||
48 | ret = strict_strtoul(val, 0, &mask); | ||
49 | if (ret) | ||
50 | return ret; | ||
51 | |||
52 | if (mask & ~max) | ||
53 | return -EINVAL; | ||
54 | |||
55 | *(unsigned int *)kp->arg = mask; | ||
56 | |||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | static int ati_remote2_set_channel_mask(const char *val, | ||
61 | struct kernel_param *kp) | ||
62 | { | ||
63 | pr_debug("%s()\n", __func__); | ||
64 | |||
65 | return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK); | ||
66 | } | ||
67 | |||
68 | static int ati_remote2_get_channel_mask(char *buffer, struct kernel_param *kp) | ||
69 | { | ||
70 | pr_debug("%s()\n", __func__); | ||
71 | |||
72 | return sprintf(buffer, "0x%04x", *(unsigned int *)kp->arg); | ||
73 | } | ||
74 | |||
75 | static int ati_remote2_set_mode_mask(const char *val, struct kernel_param *kp) | ||
76 | { | ||
77 | pr_debug("%s()\n", __func__); | ||
78 | |||
79 | return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK); | ||
80 | } | ||
81 | |||
82 | static int ati_remote2_get_mode_mask(char *buffer, struct kernel_param *kp) | ||
83 | { | ||
84 | pr_debug("%s()\n", __func__); | ||
85 | |||
86 | return sprintf(buffer, "0x%02x", *(unsigned int *)kp->arg); | ||
87 | } | ||
88 | |||
39 | static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK; | 89 | static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK; |
40 | module_param(channel_mask, uint, 0644); | 90 | #define param_check_channel_mask(name, p) __param_check(name, p, unsigned int) |
91 | #define param_set_channel_mask ati_remote2_set_channel_mask | ||
92 | #define param_get_channel_mask ati_remote2_get_channel_mask | ||
93 | module_param(channel_mask, channel_mask, 0644); | ||
41 | MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>"); | 94 | MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>"); |
42 | 95 | ||
43 | static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK; | 96 | static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK; |
44 | module_param(mode_mask, uint, 0644); | 97 | #define param_check_mode_mask(name, p) __param_check(name, p, unsigned int) |
98 | #define param_set_mode_mask ati_remote2_set_mode_mask | ||
99 | #define param_get_mode_mask ati_remote2_get_mode_mask | ||
100 | module_param(mode_mask, mode_mask, 0644); | ||
45 | MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>"); | 101 | MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>"); |
46 | 102 | ||
47 | static struct usb_device_id ati_remote2_id_table[] = { | 103 | static struct usb_device_id ati_remote2_id_table[] = { |
@@ -722,8 +778,8 @@ static int ati_remote2_probe(struct usb_interface *interface, const struct usb_d | |||
722 | if (r) | 778 | if (r) |
723 | goto fail2; | 779 | goto fail2; |
724 | 780 | ||
725 | ar2->channel_mask = channel_mask & ATI_REMOTE2_MAX_CHANNEL_MASK; | 781 | ar2->channel_mask = channel_mask; |
726 | ar2->mode_mask = mode_mask & ATI_REMOTE2_MAX_MODE_MASK; | 782 | ar2->mode_mask = mode_mask; |
727 | 783 | ||
728 | r = ati_remote2_setup(ar2, ar2->channel_mask); | 784 | r = ati_remote2_setup(ar2, ar2->channel_mask); |
729 | if (r) | 785 | if (r) |