Commit 5772f63613ce0a6777e82a7e8fb553e49da27719

Authored by Stefan Achatz
Committed by Jiri Kosina
1 parent a28764ef80

HID: roccat: Introduce module hid-roccat-common

Module hid-roccat-common contains functions used by roccat device driver
modules to reduce code duplication.
At the moment it contains just two wrapper methods for usb_control_msg
that ensure that the buffer used for transfer is dma capable which wasn't
the case before.
The kconfig option is not visible to the user but will be selected by the
device specific drivers.

Signed-off-by: Stefan Achatz <erazor_de@users.sourceforge.net>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>

Showing 8 changed files with 254 additions and 426 deletions Side-by-side Diff

... ... @@ -417,10 +417,14 @@
417 417 Say Y here if you have a Roccat mouse or keyboard and want OSD or
418 418 macro execution support.
419 419  
  420 +config HID_ROCCAT_COMMON
  421 + tristate
  422 +
420 423 config HID_ROCCAT_ARVO
421 424 tristate "Roccat Arvo keyboard support"
422 425 depends on USB_HID
423 426 select HID_ROCCAT
  427 + select HID_ROCCAT_COMMON
424 428 ---help---
425 429 Support for Roccat Arvo keyboard.
426 430  
... ... @@ -428,6 +432,7 @@
428 432 tristate "Roccat Kone Mouse support"
429 433 depends on USB_HID
430 434 select HID_ROCCAT
  435 + select HID_ROCCAT_COMMON
431 436 ---help---
432 437 Support for Roccat Kone mouse.
433 438  
... ... @@ -435,6 +440,7 @@
435 440 tristate "Roccat Kone[+] mouse support"
436 441 depends on USB_HID
437 442 select HID_ROCCAT
  443 + select HID_ROCCAT_COMMON
438 444 ---help---
439 445 Support for Roccat Kone[+] mouse.
440 446  
... ... @@ -442,6 +448,7 @@
442 448 tristate "Roccat Pyra mouse support"
443 449 depends on USB_HID
444 450 select HID_ROCCAT
  451 + select HID_ROCCAT_COMMON
445 452 ---help---
446 453 Support for Roccat Pyra mouse.
447 454  
drivers/hid/Makefile
... ... @@ -56,6 +56,7 @@
56 56 obj-$(CONFIG_HID_PETALYNX) += hid-petalynx.o
57 57 obj-$(CONFIG_HID_PICOLCD) += hid-picolcd.o
58 58 obj-$(CONFIG_HID_ROCCAT) += hid-roccat.o
  59 +obj-$(CONFIG_HID_ROCCAT_COMMON) += hid-roccat-common.o
59 60 obj-$(CONFIG_HID_ROCCAT_ARVO) += hid-roccat-arvo.o
60 61 obj-$(CONFIG_HID_ROCCAT_KONE) += hid-roccat-kone.o
61 62 obj-$(CONFIG_HID_ROCCAT_KONEPLUS) += hid-roccat-koneplus.o
drivers/hid/hid-roccat-arvo.c
... ... @@ -19,41 +19,15 @@
19 19 #include <linux/device.h>
20 20 #include <linux/input.h>
21 21 #include <linux/hid.h>
22   -#include <linux/usb.h>
23 22 #include <linux/module.h>
24 23 #include <linux/slab.h>
25 24 #include "hid-ids.h"
26 25 #include "hid-roccat.h"
  26 +#include "hid-roccat-common.h"
27 27 #include "hid-roccat-arvo.h"
28 28  
29 29 static struct class *arvo_class;
30 30  
31   -static int arvo_receive(struct usb_device *usb_dev, uint usb_command,
32   - void *buf, uint size)
33   -{
34   - int len;
35   -
36   - len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
37   - USB_REQ_CLEAR_FEATURE,
38   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
39   - usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
40   -
41   - return (len != size) ? -EIO : 0;
42   -}
43   -
44   -static int arvo_send(struct usb_device *usb_dev, uint usb_command,
45   - void const *buf, uint size)
46   -{
47   - int len;
48   -
49   - len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
50   - USB_REQ_SET_CONFIGURATION,
51   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
52   - usb_command, 0, (void *)buf, size, USB_CTRL_SET_TIMEOUT);
53   -
54   - return (len != size) ? -EIO : 0;
55   -}
56   -
57 31 static ssize_t arvo_sysfs_show_mode_key(struct device *dev,
58 32 struct device_attribute *attr, char *buf)
59 33 {
60 34  
61 35  
62 36  
63 37  
... ... @@ -61,24 +35,17 @@
61 35 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
62 36 struct usb_device *usb_dev =
63 37 interface_to_usbdev(to_usb_interface(dev->parent->parent));
64   - struct arvo_mode_key *temp_buf;
  38 + struct arvo_mode_key temp_buf;
65 39 int retval;
66 40  
67   - temp_buf = kmalloc(sizeof(struct arvo_mode_key), GFP_KERNEL);
68   - if (!temp_buf)
69   - return -ENOMEM;
70   -
71 41 mutex_lock(&arvo->arvo_lock);
72   - retval = arvo_receive(usb_dev, ARVO_USB_COMMAND_MODE_KEY,
73   - temp_buf, sizeof(struct arvo_mode_key));
  42 + retval = roccat_common_receive(usb_dev, ARVO_USB_COMMAND_MODE_KEY,
  43 + &temp_buf, sizeof(struct arvo_mode_key));
74 44 mutex_unlock(&arvo->arvo_lock);
75 45 if (retval)
76   - goto out;
  46 + return retval;
77 47  
78   - retval = snprintf(buf, PAGE_SIZE, "%d\n", temp_buf->state);
79   -out:
80   - kfree(temp_buf);
81   - return retval;
  48 + return snprintf(buf, PAGE_SIZE, "%d\n", temp_buf.state);
82 49 }
83 50  
84 51 static ssize_t arvo_sysfs_set_mode_key(struct device *dev,
85 52  
86 53  
87 54  
88 55  
89 56  
90 57  
... ... @@ -88,32 +55,25 @@
88 55 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
89 56 struct usb_device *usb_dev =
90 57 interface_to_usbdev(to_usb_interface(dev->parent->parent));
91   - struct arvo_mode_key *temp_buf;
  58 + struct arvo_mode_key temp_buf;
92 59 unsigned long state;
93 60 int retval;
94 61  
95   - temp_buf = kmalloc(sizeof(struct arvo_mode_key), GFP_KERNEL);
96   - if (!temp_buf)
97   - return -ENOMEM;
98   -
99 62 retval = strict_strtoul(buf, 10, &state);
100 63 if (retval)
101   - goto out;
  64 + return retval;
102 65  
103   - temp_buf->command = ARVO_COMMAND_MODE_KEY;
104   - temp_buf->state = state;
  66 + temp_buf.command = ARVO_COMMAND_MODE_KEY;
  67 + temp_buf.state = state;
105 68  
106 69 mutex_lock(&arvo->arvo_lock);
107   - retval = arvo_send(usb_dev, ARVO_USB_COMMAND_MODE_KEY,
108   - temp_buf, sizeof(struct arvo_mode_key));
  70 + retval = roccat_common_send(usb_dev, ARVO_USB_COMMAND_MODE_KEY,
  71 + &temp_buf, sizeof(struct arvo_mode_key));
109 72 mutex_unlock(&arvo->arvo_lock);
110 73 if (retval)
111   - goto out;
  74 + return retval;
112 75  
113   - retval = size;
114   -out:
115   - kfree(temp_buf);
116   - return retval;
  76 + return size;
117 77 }
118 78  
119 79 static ssize_t arvo_sysfs_show_key_mask(struct device *dev,
120 80  
121 81  
122 82  
123 83  
... ... @@ -123,24 +83,17 @@
123 83 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
124 84 struct usb_device *usb_dev =
125 85 interface_to_usbdev(to_usb_interface(dev->parent->parent));
126   - struct arvo_key_mask *temp_buf;
  86 + struct arvo_key_mask temp_buf;
127 87 int retval;
128 88  
129   - temp_buf = kmalloc(sizeof(struct arvo_key_mask), GFP_KERNEL);
130   - if (!temp_buf)
131   - return -ENOMEM;
132   -
133 89 mutex_lock(&arvo->arvo_lock);
134   - retval = arvo_receive(usb_dev, ARVO_USB_COMMAND_KEY_MASK,
135   - temp_buf, sizeof(struct arvo_key_mask));
  90 + retval = roccat_common_receive(usb_dev, ARVO_USB_COMMAND_KEY_MASK,
  91 + &temp_buf, sizeof(struct arvo_key_mask));
136 92 mutex_unlock(&arvo->arvo_lock);
137 93 if (retval)
138   - goto out;
  94 + return retval;
139 95  
140   - retval = snprintf(buf, PAGE_SIZE, "%d\n", temp_buf->key_mask);
141   -out:
142   - kfree(temp_buf);
143   - return retval;
  96 + return snprintf(buf, PAGE_SIZE, "%d\n", temp_buf.key_mask);
144 97 }
145 98  
146 99 static ssize_t arvo_sysfs_set_key_mask(struct device *dev,
147 100  
148 101  
149 102  
150 103  
151 104  
152 105  
153 106  
154 107  
155 108  
156 109  
... ... @@ -150,52 +103,40 @@
150 103 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
151 104 struct usb_device *usb_dev =
152 105 interface_to_usbdev(to_usb_interface(dev->parent->parent));
153   - struct arvo_key_mask *temp_buf;
  106 + struct arvo_key_mask temp_buf;
154 107 unsigned long key_mask;
155 108 int retval;
156 109  
157   - temp_buf = kmalloc(sizeof(struct arvo_key_mask), GFP_KERNEL);
158   - if (!temp_buf)
159   - return -ENOMEM;
160   -
161 110 retval = strict_strtoul(buf, 10, &key_mask);
162 111 if (retval)
163   - goto out;
  112 + return retval;
164 113  
165   - temp_buf->command = ARVO_COMMAND_KEY_MASK;
166   - temp_buf->key_mask = key_mask;
  114 + temp_buf.command = ARVO_COMMAND_KEY_MASK;
  115 + temp_buf.key_mask = key_mask;
167 116  
168 117 mutex_lock(&arvo->arvo_lock);
169   - retval = arvo_send(usb_dev, ARVO_USB_COMMAND_KEY_MASK,
170   - temp_buf, sizeof(struct arvo_key_mask));
  118 + retval = roccat_common_send(usb_dev, ARVO_USB_COMMAND_KEY_MASK,
  119 + &temp_buf, sizeof(struct arvo_key_mask));
171 120 mutex_unlock(&arvo->arvo_lock);
172 121 if (retval)
173   - goto out;
  122 + return retval;
174 123  
175   - retval = size;
176   -out:
177   - kfree(temp_buf);
178   - return retval;
  124 + return size;
179 125 }
180 126  
181 127 /* retval is 1-5 on success, < 0 on error */
182 128 static int arvo_get_actual_profile(struct usb_device *usb_dev)
183 129 {
184   - struct arvo_actual_profile *temp_buf;
  130 + struct arvo_actual_profile temp_buf;
185 131 int retval;
186 132  
187   - temp_buf = kmalloc(sizeof(struct arvo_actual_profile), GFP_KERNEL);
188   - if (!temp_buf)
189   - return -ENOMEM;
  133 + retval = roccat_common_receive(usb_dev, ARVO_USB_COMMAND_ACTUAL_PROFILE,
  134 + &temp_buf, sizeof(struct arvo_actual_profile));
190 135  
191   - retval = arvo_receive(usb_dev, ARVO_USB_COMMAND_ACTUAL_PROFILE,
192   - temp_buf, sizeof(struct arvo_actual_profile));
  136 + if (retval)
  137 + return retval;
193 138  
194   - if (!retval)
195   - retval = temp_buf->actual_profile;
196   -
197   - kfree(temp_buf);
198   - return retval;
  139 + return temp_buf.actual_profile;
199 140 }
200 141  
201 142 static ssize_t arvo_sysfs_show_actual_profile(struct device *dev,
202 143  
203 144  
204 145  
205 146  
206 147  
... ... @@ -214,32 +155,25 @@
214 155 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
215 156 struct usb_device *usb_dev =
216 157 interface_to_usbdev(to_usb_interface(dev->parent->parent));
217   - struct arvo_actual_profile *temp_buf;
  158 + struct arvo_actual_profile temp_buf;
218 159 unsigned long profile;
219 160 int retval;
220 161  
221   - temp_buf = kmalloc(sizeof(struct arvo_actual_profile), GFP_KERNEL);
222   - if (!temp_buf)
223   - return -ENOMEM;
224   -
225 162 retval = strict_strtoul(buf, 10, &profile);
226 163 if (retval)
227   - goto out;
  164 + return retval;
228 165  
229   - temp_buf->command = ARVO_COMMAND_ACTUAL_PROFILE;
230   - temp_buf->actual_profile = profile;
  166 + temp_buf.command = ARVO_COMMAND_ACTUAL_PROFILE;
  167 + temp_buf.actual_profile = profile;
231 168  
232 169 mutex_lock(&arvo->arvo_lock);
233   - retval = arvo_send(usb_dev, ARVO_USB_COMMAND_ACTUAL_PROFILE,
234   - temp_buf, sizeof(struct arvo_actual_profile));
  170 + retval = roccat_common_send(usb_dev, ARVO_USB_COMMAND_ACTUAL_PROFILE,
  171 + &temp_buf, sizeof(struct arvo_actual_profile));
235 172 if (!retval) {
236 173 arvo->actual_profile = profile;
237 174 retval = size;
238 175 }
239 176 mutex_unlock(&arvo->arvo_lock);
240   -
241   -out:
242   - kfree(temp_buf);
243 177 return retval;
244 178 }
245 179  
... ... @@ -257,7 +191,7 @@
257 191 return -EINVAL;
258 192  
259 193 mutex_lock(&arvo->arvo_lock);
260   - retval = arvo_send(usb_dev, command, buf, real_size);
  194 + retval = roccat_common_send(usb_dev, command, buf, real_size);
261 195 mutex_unlock(&arvo->arvo_lock);
262 196  
263 197 return (retval ? retval : real_size);
... ... @@ -280,7 +214,7 @@
280 214 return -EINVAL;
281 215  
282 216 mutex_lock(&arvo->arvo_lock);
283   - retval = arvo_receive(usb_dev, command, buf, real_size);
  217 + retval = roccat_common_receive(usb_dev, command, buf, real_size);
284 218 mutex_unlock(&arvo->arvo_lock);
285 219  
286 220 return (retval ? retval : real_size);
drivers/hid/hid-roccat-common.c
  1 +/*
  2 + * Roccat common functions for device specific drivers
  3 + *
  4 + * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net>
  5 + */
  6 +
  7 +/*
  8 + * This program is free software; you can redistribute it and/or modify it
  9 + * under the terms of the GNU General Public License as published by the Free
  10 + * Software Foundation; either version 2 of the License, or (at your option)
  11 + * any later version.
  12 + */
  13 +
  14 +#include <linux/slab.h>
  15 +#include "hid-roccat-common.h"
  16 +
  17 +int roccat_common_receive(struct usb_device *usb_dev, uint usb_command,
  18 + void *data, uint size)
  19 +{
  20 + char *buf;
  21 + int len;
  22 +
  23 + buf = kmalloc(size, GFP_KERNEL);
  24 + if (buf == NULL)
  25 + return -ENOMEM;
  26 +
  27 + len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
  28 + USB_REQ_CLEAR_FEATURE,
  29 + USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
  30 + usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
  31 +
  32 + memcpy(data, buf, size);
  33 + kfree(buf);
  34 + return ((len < 0) ? len : ((len != size) ? -EIO : 0));
  35 +}
  36 +EXPORT_SYMBOL_GPL(roccat_common_receive);
  37 +
  38 +int roccat_common_send(struct usb_device *usb_dev, uint usb_command,
  39 + void const *data, uint size)
  40 +{
  41 + char *buf;
  42 + int len;
  43 +
  44 + buf = kmalloc(size, GFP_KERNEL);
  45 + if (buf == NULL)
  46 + return -ENOMEM;
  47 +
  48 + memcpy(buf, data, size);
  49 +
  50 + len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
  51 + USB_REQ_SET_CONFIGURATION,
  52 + USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
  53 + usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
  54 +
  55 + kfree(buf);
  56 + return ((len < 0) ? len : ((len != size) ? -EIO : 0));
  57 +}
  58 +EXPORT_SYMBOL_GPL(roccat_common_send);
  59 +
  60 +MODULE_AUTHOR("Stefan Achatz");
  61 +MODULE_DESCRIPTION("USB Roccat common driver");
  62 +MODULE_LICENSE("GPL v2");
drivers/hid/hid-roccat-common.h
  1 +#ifndef __HID_ROCCAT_COMMON_H
  2 +#define __HID_ROCCAT_COMMON_H
  3 +
  4 +/*
  5 + * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net>
  6 + */
  7 +
  8 +/*
  9 + * This program is free software; you can redistribute it and/or modify it
  10 + * under the terms of the GNU General Public License as published by the Free
  11 + * Software Foundation; either version 2 of the License, or (at your option)
  12 + * any later version.
  13 + */
  14 +
  15 +#include <linux/usb.h>
  16 +#include <linux/types.h>
  17 +
  18 +int roccat_common_receive(struct usb_device *usb_dev, uint usb_command,
  19 + void *data, uint size);
  20 +int roccat_common_send(struct usb_device *usb_dev, uint usb_command,
  21 + void const *data, uint size);
  22 +
  23 +#endif
drivers/hid/hid-roccat-kone.c
... ... @@ -28,11 +28,11 @@
28 28 #include <linux/device.h>
29 29 #include <linux/input.h>
30 30 #include <linux/hid.h>
31   -#include <linux/usb.h>
32 31 #include <linux/module.h>
33 32 #include <linux/slab.h>
34 33 #include "hid-ids.h"
35 34 #include "hid-roccat.h"
  35 +#include "hid-roccat-common.h"
36 36 #include "hid-roccat-kone.h"
37 37  
38 38 static uint profile_numbers[5] = {0, 1, 2, 3, 4};
39 39  
... ... @@ -58,13 +58,9 @@
58 58 */
59 59 static int kone_check_write(struct usb_device *usb_dev)
60 60 {
61   - int len;
62   - unsigned char *data;
  61 + int retval;
  62 + uint8_t data;
63 63  
64   - data = kmalloc(1, GFP_KERNEL);
65   - if (!data)
66   - return -ENOMEM;
67   -
68 64 do {
69 65 /*
70 66 * Mouse needs 50 msecs until it says ok, but there are
71 67  
72 68  
73 69  
74 70  
75 71  
76 72  
... ... @@ -72,56 +68,36 @@
72 68 */
73 69 msleep(80);
74 70  
75   - len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
76   - USB_REQ_CLEAR_FEATURE,
77   - USB_TYPE_CLASS | USB_RECIP_INTERFACE |
78   - USB_DIR_IN,
79   - kone_command_confirm_write, 0, data, 1,
80   - USB_CTRL_SET_TIMEOUT);
  71 + retval = roccat_common_receive(usb_dev,
  72 + kone_command_confirm_write, &data, 1);
  73 + if (retval)
  74 + return retval;
81 75  
82   - if (len != 1) {
83   - kfree(data);
84   - return -EIO;
85   - }
86   -
87 76 /*
88 77 * value of 3 seems to mean something like
89 78 * "not finished yet, but it looks good"
90 79 * So check again after a moment.
91 80 */
92   - } while (*data == 3);
  81 + } while (data == 3);
93 82  
94   - if (*data == 1) { /* everything alright */
95   - kfree(data);
  83 + if (data == 1) /* everything alright */
96 84 return 0;
97   - } else { /* unknown answer */
98   - hid_err(usb_dev, "got retval %d when checking write\n", *data);
99   - kfree(data);
100   - return -EIO;
101   - }
  85 +
  86 + /* unknown answer */
  87 + hid_err(usb_dev, "got retval %d when checking write\n", data);
  88 + return -EIO;
102 89 }
103 90  
104 91 /*
105 92 * Reads settings from mouse and stores it in @buf
106   - * @buf has to be alloced with GFP_KERNEL
107 93 * On success returns 0
108 94 * On failure returns errno
109 95 */
110 96 static int kone_get_settings(struct usb_device *usb_dev,
111 97 struct kone_settings *buf)
112 98 {
113   - int len;
114   -
115   - len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
116   - USB_REQ_CLEAR_FEATURE,
117   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
118   - kone_command_settings, 0, buf,
119   - sizeof(struct kone_settings), USB_CTRL_SET_TIMEOUT);
120   -
121   - if (len != sizeof(struct kone_settings))
122   - return -EIO;
123   -
124   - return 0;
  99 + return roccat_common_receive(usb_dev, kone_command_settings, buf,
  100 + sizeof(struct kone_settings));
125 101 }
126 102  
127 103 /*
... ... @@ -132,22 +108,12 @@
132 108 static int kone_set_settings(struct usb_device *usb_dev,
133 109 struct kone_settings const *settings)
134 110 {
135   - int len;
136   -
137   - len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
138   - USB_REQ_SET_CONFIGURATION,
139   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
140   - kone_command_settings, 0, (char *)settings,
141   - sizeof(struct kone_settings),
142   - USB_CTRL_SET_TIMEOUT);
143   -
144   - if (len != sizeof(struct kone_settings))
145   - return -EIO;
146   -
147   - if (kone_check_write(usb_dev))
148   - return -EIO;
149   -
150   - return 0;
  111 + int retval;
  112 + retval = roccat_common_send(usb_dev, kone_command_settings,
  113 + settings, sizeof(struct kone_settings));
  114 + if (retval)
  115 + return retval;
  116 + return kone_check_write(usb_dev);
151 117 }
152 118  
153 119 /*
... ... @@ -193,7 +159,7 @@
193 159 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
194 160 USB_REQ_SET_CONFIGURATION,
195 161 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
196   - kone_command_profile, number, (char *)profile,
  162 + kone_command_profile, number, (void *)profile,
197 163 sizeof(struct kone_profile),
198 164 USB_CTRL_SET_TIMEOUT);
199 165  
200 166  
201 167  
202 168  
... ... @@ -213,24 +179,15 @@
213 179 */
214 180 static int kone_get_weight(struct usb_device *usb_dev, int *result)
215 181 {
216   - int len;
217   - uint8_t *data;
  182 + int retval;
  183 + uint8_t data;
218 184  
219   - data = kmalloc(1, GFP_KERNEL);
220   - if (!data)
221   - return -ENOMEM;
  185 + retval = roccat_common_receive(usb_dev, kone_command_weight, &data, 1);
222 186  
223   - len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
224   - USB_REQ_CLEAR_FEATURE,
225   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
226   - kone_command_weight, 0, data, 1, USB_CTRL_SET_TIMEOUT);
  187 + if (retval)
  188 + return retval;
227 189  
228   - if (len != 1) {
229   - kfree(data);
230   - return -EIO;
231   - }
232   - *result = (int)*data;
233   - kfree(data);
  190 + *result = (int)data;
234 191 return 0;
235 192 }
236 193  
237 194  
238 195  
... ... @@ -241,25 +198,15 @@
241 198 */
242 199 static int kone_get_firmware_version(struct usb_device *usb_dev, int *result)
243 200 {
244   - int len;
245   - unsigned char *data;
  201 + int retval;
  202 + uint16_t data;
246 203  
247   - data = kmalloc(2, GFP_KERNEL);
248   - if (!data)
249   - return -ENOMEM;
  204 + retval = roccat_common_receive(usb_dev, kone_command_firmware_version,
  205 + &data, 2);
  206 + if (retval)
  207 + return retval;
250 208  
251   - len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
252   - USB_REQ_CLEAR_FEATURE,
253   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
254   - kone_command_firmware_version, 0, data, 2,
255   - USB_CTRL_SET_TIMEOUT);
256   -
257   - if (len != 2) {
258   - kfree(data);
259   - return -EIO;
260   - }
261   - *result = le16_to_cpu(*data);
262   - kfree(data);
  209 + *result = le16_to_cpu(data);
263 210 return 0;
264 211 }
265 212  
... ... @@ -435,23 +382,9 @@
435 382  
436 383 static int kone_tcu_command(struct usb_device *usb_dev, int number)
437 384 {
438   - int len;
439   - char *value;
440   -
441   - value = kmalloc(1, GFP_KERNEL);
442   - if (!value)
443   - return -ENOMEM;
444   -
445   - *value = number;
446   -
447   - len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
448   - USB_REQ_SET_CONFIGURATION,
449   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
450   - kone_command_calibrate, 0, value, 1,
451   - USB_CTRL_SET_TIMEOUT);
452   -
453   - kfree(value);
454   - return ((len != 1) ? -EIO : 0);
  385 + unsigned char value;
  386 + value = number;
  387 + return roccat_common_send(usb_dev, kone_command_calibrate, &value, 1);
455 388 }
456 389  
457 390 /*
drivers/hid/hid-roccat-koneplus.c
... ... @@ -19,11 +19,11 @@
19 19 #include <linux/device.h>
20 20 #include <linux/input.h>
21 21 #include <linux/hid.h>
22   -#include <linux/usb.h>
23 22 #include <linux/module.h>
24 23 #include <linux/slab.h>
25 24 #include "hid-ids.h"
26 25 #include "hid-roccat.h"
  26 +#include "hid-roccat-common.h"
27 27 #include "hid-roccat-koneplus.h"
28 28  
29 29 static uint profile_numbers[5] = {0, 1, 2, 3, 4};
30 30  
31 31  
32 32  
33 33  
34 34  
35 35  
36 36  
37 37  
38 38  
39 39  
40 40  
41 41  
42 42  
43 43  
44 44  
... ... @@ -39,110 +39,63 @@
39 39 static int koneplus_send_control(struct usb_device *usb_dev, uint value,
40 40 enum koneplus_control_requests request)
41 41 {
42   - int len;
43   - struct koneplus_control *control;
  42 + struct koneplus_control control;
44 43  
45 44 if ((request == KONEPLUS_CONTROL_REQUEST_PROFILE_SETTINGS ||
46 45 request == KONEPLUS_CONTROL_REQUEST_PROFILE_BUTTONS) &&
47 46 value > 4)
48 47 return -EINVAL;
49 48  
50   - control = kmalloc(sizeof(struct koneplus_control), GFP_KERNEL);
51   - if (!control)
52   - return -ENOMEM;
  49 + control.command = KONEPLUS_COMMAND_CONTROL;
  50 + control.value = value;
  51 + control.request = request;
53 52  
54   - control->command = KONEPLUS_COMMAND_CONTROL;
55   - control->value = value;
56   - control->request = request;
57   -
58   - len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
59   - USB_REQ_SET_CONFIGURATION,
60   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
61   - KONEPLUS_USB_COMMAND_CONTROL, 0, control,
62   - sizeof(struct koneplus_control),
63   - USB_CTRL_SET_TIMEOUT);
64   -
65   - kfree(control);
66   -
67   - if (len != sizeof(struct koneplus_control))
68   - return len;
69   -
70   - return 0;
  53 + return roccat_common_send(usb_dev, KONEPLUS_USB_COMMAND_CONTROL,
  54 + &control, sizeof(struct koneplus_control));
71 55 }
72 56  
73   -static int koneplus_receive(struct usb_device *usb_dev, uint usb_command,
74   - void *buf, uint size) {
75   - int len;
76   -
77   - len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
78   - USB_REQ_CLEAR_FEATURE,
79   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
80   - usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
81   -
82   - return (len != size) ? -EIO : 0;
83   -}
84   -
85 57 static int koneplus_receive_control_status(struct usb_device *usb_dev)
86 58 {
87 59 int retval;
88   - struct koneplus_control *control;
  60 + struct koneplus_control control;
89 61  
90   - control = kmalloc(sizeof(struct koneplus_control), GFP_KERNEL);
91   - if (!control)
92   - return -ENOMEM;
93   -
94 62 do {
95   - retval = koneplus_receive(usb_dev, KONEPLUS_USB_COMMAND_CONTROL,
96   - control, sizeof(struct koneplus_control));
  63 + retval = roccat_common_receive(usb_dev, KONEPLUS_USB_COMMAND_CONTROL,
  64 + &control, sizeof(struct koneplus_control));
97 65  
98 66 /* check if we get a completely wrong answer */
99 67 if (retval)
100   - goto out;
  68 + return retval;
101 69  
102   - if (control->value == KONEPLUS_CONTROL_REQUEST_STATUS_OK) {
103   - retval = 0;
104   - goto out;
105   - }
  70 + if (control.value == KONEPLUS_CONTROL_REQUEST_STATUS_OK)
  71 + return 0;
106 72  
107 73 /* indicates that hardware needs some more time to complete action */
108   - if (control->value == KONEPLUS_CONTROL_REQUEST_STATUS_WAIT) {
  74 + if (control.value == KONEPLUS_CONTROL_REQUEST_STATUS_WAIT) {
109 75 msleep(500); /* windows driver uses 1000 */
110 76 continue;
111 77 }
112 78  
113 79 /* seems to be critical - replug necessary */
114   - if (control->value == KONEPLUS_CONTROL_REQUEST_STATUS_OVERLOAD) {
115   - retval = -EINVAL;
116   - goto out;
117   - }
  80 + if (control.value == KONEPLUS_CONTROL_REQUEST_STATUS_OVERLOAD)
  81 + return -EINVAL;
118 82  
119 83 hid_err(usb_dev, "koneplus_receive_control_status: "
120   - "unknown response value 0x%x\n", control->value);
121   - retval = -EINVAL;
122   - goto out;
123   -
  84 + "unknown response value 0x%x\n", control.value);
  85 + return -EINVAL;
124 86 } while (1);
125   -out:
126   - kfree(control);
127   - return retval;
128 87 }
129 88  
130 89 static int koneplus_send(struct usb_device *usb_dev, uint command,
131   - void *buf, uint size) {
132   - int len;
  90 + void const *buf, uint size)
  91 +{
  92 + int retval;
133 93  
134   - len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
135   - USB_REQ_SET_CONFIGURATION,
136   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
137   - command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
  94 + retval = roccat_common_send(usb_dev, command, buf, size);
  95 + if (retval)
  96 + return retval;
138 97  
139   - if (len != size)
140   - return -EIO;
141   -
142   - if (koneplus_receive_control_status(usb_dev))
143   - return -EIO;
144   -
145   - return 0;
  98 + return koneplus_receive_control_status(usb_dev);
146 99 }
147 100  
148 101 static int koneplus_select_profile(struct usb_device *usb_dev, uint number,
... ... @@ -167,7 +120,7 @@
167 120 static int koneplus_get_info(struct usb_device *usb_dev,
168 121 struct koneplus_info *buf)
169 122 {
170   - return koneplus_receive(usb_dev, KONEPLUS_USB_COMMAND_INFO,
  123 + return roccat_common_receive(usb_dev, KONEPLUS_USB_COMMAND_INFO,
171 124 buf, sizeof(struct koneplus_info));
172 125 }
173 126  
... ... @@ -181,7 +134,7 @@
181 134 if (retval)
182 135 return retval;
183 136  
184   - return koneplus_receive(usb_dev, KONEPLUS_USB_COMMAND_PROFILE_SETTINGS,
  137 + return roccat_common_receive(usb_dev, KONEPLUS_USB_COMMAND_PROFILE_SETTINGS,
185 138 buf, sizeof(struct koneplus_profile_settings));
186 139 }
187 140  
... ... @@ -189,7 +142,7 @@
189 142 struct koneplus_profile_settings const *settings)
190 143 {
191 144 return koneplus_send(usb_dev, KONEPLUS_USB_COMMAND_PROFILE_SETTINGS,
192   - (void *)settings, sizeof(struct koneplus_profile_settings));
  145 + settings, sizeof(struct koneplus_profile_settings));
193 146 }
194 147  
195 148 static int koneplus_get_profile_buttons(struct usb_device *usb_dev,
... ... @@ -202,7 +155,7 @@
202 155 if (retval)
203 156 return retval;
204 157  
205   - return koneplus_receive(usb_dev, KONEPLUS_USB_COMMAND_PROFILE_BUTTONS,
  158 + return roccat_common_receive(usb_dev, KONEPLUS_USB_COMMAND_PROFILE_BUTTONS,
206 159 buf, sizeof(struct koneplus_profile_buttons));
207 160 }
208 161  
209 162  
210 163  
211 164  
... ... @@ -210,29 +163,19 @@
210 163 struct koneplus_profile_buttons const *buttons)
211 164 {
212 165 return koneplus_send(usb_dev, KONEPLUS_USB_COMMAND_PROFILE_BUTTONS,
213   - (void *)buttons, sizeof(struct koneplus_profile_buttons));
  166 + buttons, sizeof(struct koneplus_profile_buttons));
214 167 }
215 168  
216 169 /* retval is 0-4 on success, < 0 on error */
217 170 static int koneplus_get_startup_profile(struct usb_device *usb_dev)
218 171 {
219   - struct koneplus_startup_profile *buf;
  172 + struct koneplus_startup_profile buf;
220 173 int retval;
221 174  
222   - buf = kmalloc(sizeof(struct koneplus_startup_profile), GFP_KERNEL);
223   - if (buf == NULL)
224   - return -ENOMEM;
  175 + retval = roccat_common_receive(usb_dev, KONEPLUS_USB_COMMAND_STARTUP_PROFILE,
  176 + &buf, sizeof(struct koneplus_startup_profile));
225 177  
226   - retval = koneplus_receive(usb_dev, KONEPLUS_USB_COMMAND_STARTUP_PROFILE,
227   - buf, sizeof(struct koneplus_startup_profile));
228   -
229   - if (retval)
230   - goto out;
231   -
232   - retval = buf->startup_profile;
233   -out:
234   - kfree(buf);
235   - return retval;
  178 + return retval ? retval : buf.startup_profile;
236 179 }
237 180  
238 181 static int koneplus_set_startup_profile(struct usb_device *usb_dev,
... ... @@ -245,7 +188,7 @@
245 188 buf.startup_profile = startup_profile;
246 189  
247 190 return koneplus_send(usb_dev, KONEPLUS_USB_COMMAND_STARTUP_PROFILE,
248   - (char *)&buf, sizeof(struct koneplus_profile_buttons));
  191 + &buf, sizeof(struct koneplus_profile_buttons));
249 192 }
250 193  
251 194 static ssize_t koneplus_sysfs_read(struct file *fp, struct kobject *kobj,
... ... @@ -265,7 +208,7 @@
265 208 return -EINVAL;
266 209  
267 210 mutex_lock(&koneplus->koneplus_lock);
268   - retval = koneplus_receive(usb_dev, command, buf, real_size);
  211 + retval = roccat_common_receive(usb_dev, command, buf, real_size);
269 212 mutex_unlock(&koneplus->koneplus_lock);
270 213  
271 214 if (retval)
... ... @@ -288,7 +231,7 @@
288 231 return -EINVAL;
289 232  
290 233 mutex_lock(&koneplus->koneplus_lock);
291   - retval = koneplus_send(usb_dev, command, (void *)buf, real_size);
  234 + retval = koneplus_send(usb_dev, command, buf, real_size);
292 235 mutex_unlock(&koneplus->koneplus_lock);
293 236  
294 237 if (retval)
... ... @@ -352,7 +295,7 @@
352 295 count = sizeof(struct koneplus_profile_settings) - off;
353 296  
354 297 mutex_lock(&koneplus->koneplus_lock);
355   - memcpy(buf, ((void const *)&koneplus->profile_settings[*(uint *)(attr->private)]) + off,
  298 + memcpy(buf, ((char const *)&koneplus->profile_settings[*(uint *)(attr->private)]) + off,
356 299 count);
357 300 mutex_unlock(&koneplus->koneplus_lock);
358 301  
... ... @@ -411,7 +354,7 @@
411 354 count = sizeof(struct koneplus_profile_buttons) - off;
412 355  
413 356 mutex_lock(&koneplus->koneplus_lock);
414   - memcpy(buf, ((void const *)&koneplus->profile_buttons[*(uint *)(attr->private)]) + off,
  357 + memcpy(buf, ((char const *)&koneplus->profile_buttons[*(uint *)(attr->private)]) + off,
415 358 count);
416 359 mutex_unlock(&koneplus->koneplus_lock);
417 360  
drivers/hid/hid-roccat-pyra.c
... ... @@ -20,11 +20,11 @@
20 20 #include <linux/device.h>
21 21 #include <linux/input.h>
22 22 #include <linux/hid.h>
23   -#include <linux/usb.h>
24 23 #include <linux/module.h>
25 24 #include <linux/slab.h>
26 25 #include "hid-ids.h"
27 26 #include "hid-roccat.h"
  27 +#include "hid-roccat-common.h"
28 28 #include "hid-roccat-pyra.h"
29 29  
30 30 static uint profile_numbers[5] = {0, 1, 2, 3, 4};
... ... @@ -42,7 +42,6 @@
42 42 static int pyra_send_control(struct usb_device *usb_dev, int value,
43 43 enum pyra_control_requests request)
44 44 {
45   - int len;
46 45 struct pyra_control control;
47 46  
48 47 if ((request == PYRA_CONTROL_REQUEST_PROFILE_SETTINGS ||
49 48  
50 49  
51 50  
52 51  
53 52  
54 53  
55 54  
... ... @@ -54,47 +53,31 @@
54 53 control.value = value;
55 54 control.request = request;
56 55  
57   - len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
58   - USB_REQ_SET_CONFIGURATION,
59   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
60   - PYRA_USB_COMMAND_CONTROL, 0, (char *)&control,
61   - sizeof(struct pyra_control),
62   - USB_CTRL_SET_TIMEOUT);
63   -
64   - if (len != sizeof(struct pyra_control))
65   - return len;
66   -
67   - return 0;
  56 + return roccat_common_send(usb_dev, PYRA_USB_COMMAND_CONTROL,
  57 + &control, sizeof(struct pyra_control));
68 58 }
69 59  
70 60 static int pyra_receive_control_status(struct usb_device *usb_dev)
71 61 {
72   - int len;
  62 + int retval;
73 63 struct pyra_control control;
74 64  
75 65 do {
76 66 msleep(10);
  67 + retval = roccat_common_receive(usb_dev, PYRA_USB_COMMAND_CONTROL,
  68 + &control, sizeof(struct pyra_control));
77 69  
78   - len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
79   - USB_REQ_CLEAR_FEATURE,
80   - USB_TYPE_CLASS | USB_RECIP_INTERFACE |
81   - USB_DIR_IN,
82   - PYRA_USB_COMMAND_CONTROL, 0, (char *)&control,
83   - sizeof(struct pyra_control),
84   - USB_CTRL_SET_TIMEOUT);
85   -
86 70 /* requested too early, try again */
87   - } while (len == -EPROTO);
  71 + } while (retval == -EPROTO);
88 72  
89   - if (len == sizeof(struct pyra_control) &&
90   - control.command == PYRA_COMMAND_CONTROL &&
  73 + if (!retval && control.command == PYRA_COMMAND_CONTROL &&
91 74 control.request == PYRA_CONTROL_REQUEST_STATUS &&
92 75 control.value == 1)
93   - return 0;
  76 + return 0;
94 77 else {
95 78 hid_err(usb_dev, "receive control status: unknown response 0x%x 0x%x\n",
96 79 control.request, control.value);
97   - return -EINVAL;
  80 + return retval ? retval : -EINVAL;
98 81 }
99 82 }
100 83  
101 84  
102 85  
103 86  
104 87  
105 88  
106 89  
107 90  
108 91  
109 92  
110 93  
111 94  
... ... @@ -102,125 +85,72 @@
102 85 struct pyra_profile_settings *buf, int number)
103 86 {
104 87 int retval;
105   -
106 88 retval = pyra_send_control(usb_dev, number,
107 89 PYRA_CONTROL_REQUEST_PROFILE_SETTINGS);
108   -
109 90 if (retval)
110 91 return retval;
111   -
112   - retval = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
113   - USB_REQ_CLEAR_FEATURE,
114   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
115   - PYRA_USB_COMMAND_PROFILE_SETTINGS, 0, (char *)buf,
116   - sizeof(struct pyra_profile_settings),
117   - USB_CTRL_SET_TIMEOUT);
118   -
119   - if (retval != sizeof(struct pyra_profile_settings))
120   - return retval;
121   -
122   - return 0;
  92 + return roccat_common_receive(usb_dev, PYRA_USB_COMMAND_PROFILE_SETTINGS,
  93 + buf, sizeof(struct pyra_profile_settings));
123 94 }
124 95  
125 96 static int pyra_get_profile_buttons(struct usb_device *usb_dev,
126 97 struct pyra_profile_buttons *buf, int number)
127 98 {
128 99 int retval;
129   -
130 100 retval = pyra_send_control(usb_dev, number,
131 101 PYRA_CONTROL_REQUEST_PROFILE_BUTTONS);
132   -
133 102 if (retval)
134 103 return retval;
135   -
136   - retval = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
137   - USB_REQ_CLEAR_FEATURE,
138   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
139   - PYRA_USB_COMMAND_PROFILE_BUTTONS, 0, (char *)buf,
140   - sizeof(struct pyra_profile_buttons),
141   - USB_CTRL_SET_TIMEOUT);
142   -
143   - if (retval != sizeof(struct pyra_profile_buttons))
144   - return retval;
145   -
146   - return 0;
  104 + return roccat_common_receive(usb_dev, PYRA_USB_COMMAND_PROFILE_BUTTONS,
  105 + buf, sizeof(struct pyra_profile_buttons));
147 106 }
148 107  
149 108 static int pyra_get_settings(struct usb_device *usb_dev,
150 109 struct pyra_settings *buf)
151 110 {
152   - int len;
153   - len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
154   - USB_REQ_CLEAR_FEATURE,
155   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
156   - PYRA_USB_COMMAND_SETTINGS, 0, buf,
157   - sizeof(struct pyra_settings), USB_CTRL_SET_TIMEOUT);
158   - if (len != sizeof(struct pyra_settings))
159   - return -EIO;
160   - return 0;
  111 + return roccat_common_receive(usb_dev, PYRA_USB_COMMAND_SETTINGS,
  112 + buf, sizeof(struct pyra_settings));
161 113 }
162 114  
163 115 static int pyra_get_info(struct usb_device *usb_dev, struct pyra_info *buf)
164 116 {
165   - int len;
166   - len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
167   - USB_REQ_CLEAR_FEATURE,
168   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
169   - PYRA_USB_COMMAND_INFO, 0, buf,
170   - sizeof(struct pyra_info), USB_CTRL_SET_TIMEOUT);
171   - if (len != sizeof(struct pyra_info))
172   - return -EIO;
173   - return 0;
  117 + return roccat_common_receive(usb_dev, PYRA_USB_COMMAND_INFO,
  118 + buf, sizeof(struct pyra_info));
174 119 }
175 120  
  121 +static int pyra_send(struct usb_device *usb_dev, uint command,
  122 + void const *buf, uint size)
  123 +{
  124 + int retval;
  125 + retval = roccat_common_send(usb_dev, command, buf, size);
  126 + if (retval)
  127 + return retval;
  128 + return pyra_receive_control_status(usb_dev);
  129 +}
  130 +
176 131 static int pyra_set_profile_settings(struct usb_device *usb_dev,
177 132 struct pyra_profile_settings const *settings)
178 133 {
179   - int len;
180   - len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
181   - USB_REQ_SET_CONFIGURATION,
182   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
183   - PYRA_USB_COMMAND_PROFILE_SETTINGS, 0, (char *)settings,
184   - sizeof(struct pyra_profile_settings),
185   - USB_CTRL_SET_TIMEOUT);
186   - if (len != sizeof(struct pyra_profile_settings))
187   - return -EIO;
188   - if (pyra_receive_control_status(usb_dev))
189   - return -EIO;
190   - return 0;
  134 + return pyra_send(usb_dev, PYRA_USB_COMMAND_PROFILE_SETTINGS, settings,
  135 + sizeof(struct pyra_profile_settings));
191 136 }
192 137  
193 138 static int pyra_set_profile_buttons(struct usb_device *usb_dev,
194 139 struct pyra_profile_buttons const *buttons)
195 140 {
196   - int len;
197   - len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
198   - USB_REQ_SET_CONFIGURATION,
199   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
200   - PYRA_USB_COMMAND_PROFILE_BUTTONS, 0, (char *)buttons,
201   - sizeof(struct pyra_profile_buttons),
202   - USB_CTRL_SET_TIMEOUT);
203   - if (len != sizeof(struct pyra_profile_buttons))
204   - return -EIO;
205   - if (pyra_receive_control_status(usb_dev))
206   - return -EIO;
207   - return 0;
  141 + return pyra_send(usb_dev, PYRA_USB_COMMAND_PROFILE_BUTTONS, buttons,
  142 + sizeof(struct pyra_profile_buttons));
208 143 }
209 144  
210 145 static int pyra_set_settings(struct usb_device *usb_dev,
211 146 struct pyra_settings const *settings)
212 147 {
213   - int len;
214   - len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
215   - USB_REQ_SET_CONFIGURATION,
216   - USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
217   - PYRA_USB_COMMAND_SETTINGS, 0, (char *)settings,
218   - sizeof(struct pyra_settings), USB_CTRL_SET_TIMEOUT);
219   - if (len != sizeof(struct pyra_settings))
220   - return -EIO;
221   - if (pyra_receive_control_status(usb_dev))
222   - return -EIO;
223   - return 0;
  148 + int retval;
  149 + retval = roccat_common_send(usb_dev, PYRA_USB_COMMAND_SETTINGS, settings,
  150 + sizeof(struct pyra_settings));
  151 + if (retval)
  152 + return retval;
  153 + return pyra_receive_control_status(usb_dev);
224 154 }
225 155  
226 156 static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp,
227 157  
228 158  
... ... @@ -521,21 +451,16 @@
521 451 static int pyra_init_pyra_device_struct(struct usb_device *usb_dev,
522 452 struct pyra_device *pyra)
523 453 {
524   - struct pyra_info *info;
  454 + struct pyra_info info;
525 455 int retval, i;
526 456  
527 457 mutex_init(&pyra->pyra_lock);
528 458  
529   - info = kmalloc(sizeof(struct pyra_info), GFP_KERNEL);
530   - if (!info)
531   - return -ENOMEM;
532   - retval = pyra_get_info(usb_dev, info);
533   - if (retval) {
534   - kfree(info);
  459 + retval = pyra_get_info(usb_dev, &info);
  460 + if (retval)
535 461 return retval;
536   - }
537   - pyra->firmware_version = info->firmware_version;
538   - kfree(info);
  462 +
  463 + pyra->firmware_version = info.firmware_version;
539 464  
540 465 retval = pyra_get_settings(usb_dev, &pyra->settings);
541 466 if (retval)