aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2014-10-31 05:14:39 -0400
committerJiri Kosina <jkosina@suse.cz>2014-11-03 08:26:50 -0500
commit3e7830ceb94cd06c05832a0d53cf324db3792418 (patch)
treef0b6d6d002e8e61ae4f351369abff9e6bf4f15c0
parent3a61e97563d78a2ca10752902449570d8433ce76 (diff)
HID: logitech-hidpp: leaks and NULL dereferences
Shift the allocation down a few lines to avoid a memory leak and also add a check for allocation failure. Fixes: 2f31c5252910 ('HID: Introduce hidpp, a module to handle Logitech hid++ devices') Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/hid-logitech-hidpp.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 361e97da1169..8d2d54b527b0 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -200,13 +200,15 @@ static int hidpp_send_fap_command_sync(struct hidpp_device *hidpp,
200 u8 feat_index, u8 funcindex_clientid, u8 *params, int param_count, 200 u8 feat_index, u8 funcindex_clientid, u8 *params, int param_count,
201 struct hidpp_report *response) 201 struct hidpp_report *response)
202{ 202{
203 struct hidpp_report *message = kzalloc(sizeof(struct hidpp_report), 203 struct hidpp_report *message;
204 GFP_KERNEL);
205 int ret; 204 int ret;
206 205
207 if (param_count > sizeof(message->fap.params)) 206 if (param_count > sizeof(message->fap.params))
208 return -EINVAL; 207 return -EINVAL;
209 208
209 message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
210 if (!message)
211 return -ENOMEM;
210 message->report_id = REPORT_ID_HIDPP_LONG; 212 message->report_id = REPORT_ID_HIDPP_LONG;
211 message->fap.feature_index = feat_index; 213 message->fap.feature_index = feat_index;
212 message->fap.funcindex_clientid = funcindex_clientid; 214 message->fap.funcindex_clientid = funcindex_clientid;
@@ -221,8 +223,7 @@ static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev,
221 u8 report_id, u8 sub_id, u8 reg_address, u8 *params, int param_count, 223 u8 report_id, u8 sub_id, u8 reg_address, u8 *params, int param_count,
222 struct hidpp_report *response) 224 struct hidpp_report *response)
223{ 225{
224 struct hidpp_report *message = kzalloc(sizeof(struct hidpp_report), 226 struct hidpp_report *message;
225 GFP_KERNEL);
226 int ret; 227 int ret;
227 228
228 if ((report_id != REPORT_ID_HIDPP_SHORT) && 229 if ((report_id != REPORT_ID_HIDPP_SHORT) &&
@@ -232,6 +233,9 @@ static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev,
232 if (param_count > sizeof(message->rap.params)) 233 if (param_count > sizeof(message->rap.params))
233 return -EINVAL; 234 return -EINVAL;
234 235
236 message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
237 if (!message)
238 return -ENOMEM;
235 message->report_id = report_id; 239 message->report_id = report_id;
236 message->rap.sub_id = sub_id; 240 message->rap.sub_id = sub_id;
237 message->rap.reg_address = reg_address; 241 message->rap.reg_address = reg_address;