diff options
-rw-r--r-- | drivers/hid/hid-input.c | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 0887b52f804b..97c08c5d0973 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c | |||
@@ -1154,6 +1154,38 @@ static void report_features(struct hid_device *hid) | |||
1154 | } | 1154 | } |
1155 | } | 1155 | } |
1156 | 1156 | ||
1157 | static struct hid_input *hidinput_allocate(struct hid_device *hid) | ||
1158 | { | ||
1159 | struct hid_input *hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL); | ||
1160 | struct input_dev *input_dev = input_allocate_device(); | ||
1161 | if (!hidinput || !input_dev) { | ||
1162 | kfree(hidinput); | ||
1163 | input_free_device(input_dev); | ||
1164 | hid_err(hid, "Out of memory during hid input probe\n"); | ||
1165 | return NULL; | ||
1166 | } | ||
1167 | |||
1168 | input_set_drvdata(input_dev, hid); | ||
1169 | input_dev->event = hid->ll_driver->hidinput_input_event; | ||
1170 | input_dev->open = hidinput_open; | ||
1171 | input_dev->close = hidinput_close; | ||
1172 | input_dev->setkeycode = hidinput_setkeycode; | ||
1173 | input_dev->getkeycode = hidinput_getkeycode; | ||
1174 | |||
1175 | input_dev->name = hid->name; | ||
1176 | input_dev->phys = hid->phys; | ||
1177 | input_dev->uniq = hid->uniq; | ||
1178 | input_dev->id.bustype = hid->bus; | ||
1179 | input_dev->id.vendor = hid->vendor; | ||
1180 | input_dev->id.product = hid->product; | ||
1181 | input_dev->id.version = hid->version; | ||
1182 | input_dev->dev.parent = hid->dev.parent; | ||
1183 | hidinput->input = input_dev; | ||
1184 | list_add_tail(&hidinput->list, &hid->inputs); | ||
1185 | |||
1186 | return hidinput; | ||
1187 | } | ||
1188 | |||
1157 | /* | 1189 | /* |
1158 | * Register the input device; print a message. | 1190 | * Register the input device; print a message. |
1159 | * Configure the input layer interface | 1191 | * Configure the input layer interface |
@@ -1165,7 +1197,6 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) | |||
1165 | struct hid_driver *drv = hid->driver; | 1197 | struct hid_driver *drv = hid->driver; |
1166 | struct hid_report *report; | 1198 | struct hid_report *report; |
1167 | struct hid_input *hidinput = NULL; | 1199 | struct hid_input *hidinput = NULL; |
1168 | struct input_dev *input_dev; | ||
1169 | int i, j, k; | 1200 | int i, j, k; |
1170 | 1201 | ||
1171 | INIT_LIST_HEAD(&hid->inputs); | 1202 | INIT_LIST_HEAD(&hid->inputs); |
@@ -1196,33 +1227,9 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) | |||
1196 | continue; | 1227 | continue; |
1197 | 1228 | ||
1198 | if (!hidinput) { | 1229 | if (!hidinput) { |
1199 | hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL); | 1230 | hidinput = hidinput_allocate(hid); |
1200 | input_dev = input_allocate_device(); | 1231 | if (!hidinput) |
1201 | if (!hidinput || !input_dev) { | ||
1202 | kfree(hidinput); | ||
1203 | input_free_device(input_dev); | ||
1204 | hid_err(hid, "Out of memory during hid input probe\n"); | ||
1205 | goto out_unwind; | 1232 | goto out_unwind; |
1206 | } | ||
1207 | |||
1208 | input_set_drvdata(input_dev, hid); | ||
1209 | input_dev->event = | ||
1210 | hid->ll_driver->hidinput_input_event; | ||
1211 | input_dev->open = hidinput_open; | ||
1212 | input_dev->close = hidinput_close; | ||
1213 | input_dev->setkeycode = hidinput_setkeycode; | ||
1214 | input_dev->getkeycode = hidinput_getkeycode; | ||
1215 | |||
1216 | input_dev->name = hid->name; | ||
1217 | input_dev->phys = hid->phys; | ||
1218 | input_dev->uniq = hid->uniq; | ||
1219 | input_dev->id.bustype = hid->bus; | ||
1220 | input_dev->id.vendor = hid->vendor; | ||
1221 | input_dev->id.product = hid->product; | ||
1222 | input_dev->id.version = hid->version; | ||
1223 | input_dev->dev.parent = hid->dev.parent; | ||
1224 | hidinput->input = input_dev; | ||
1225 | list_add_tail(&hidinput->list, &hid->inputs); | ||
1226 | } | 1233 | } |
1227 | 1234 | ||
1228 | for (i = 0; i < report->maxfield; i++) | 1235 | for (i = 0; i < report->maxfield; i++) |