diff options
author | Jiri Kosina <jkosina@suse.cz> | 2013-09-02 07:43:00 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2013-09-02 07:43:00 -0400 |
commit | 6c2794a2984f4c17a58117a68703cc7640f01c5a (patch) | |
tree | a7bb9e4bf20f644dfb4e28d96b9bcad4b6fbf372 /drivers/hid | |
parent | a4be0ed39f2b1ea990804ea54e39bc42d17ed5a5 (diff) |
HID: battery: don't do DMA from stack
Instead of using data from stack for DMA in hidinput_get_battery_property(),
allocate the buffer dynamically.
Cc: stable@kernel.org
Reported-by: Richard Ryniker <ryniker@alum.mit.edu>
Reported-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r-- | drivers/hid/hid-input.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 7480799e535c..3fc4034a4367 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c | |||
@@ -340,7 +340,7 @@ static int hidinput_get_battery_property(struct power_supply *psy, | |||
340 | { | 340 | { |
341 | struct hid_device *dev = container_of(psy, struct hid_device, battery); | 341 | struct hid_device *dev = container_of(psy, struct hid_device, battery); |
342 | int ret = 0; | 342 | int ret = 0; |
343 | __u8 buf[2] = {}; | 343 | __u8 *buf; |
344 | 344 | ||
345 | switch (prop) { | 345 | switch (prop) { |
346 | case POWER_SUPPLY_PROP_PRESENT: | 346 | case POWER_SUPPLY_PROP_PRESENT: |
@@ -349,12 +349,19 @@ static int hidinput_get_battery_property(struct power_supply *psy, | |||
349 | break; | 349 | break; |
350 | 350 | ||
351 | case POWER_SUPPLY_PROP_CAPACITY: | 351 | case POWER_SUPPLY_PROP_CAPACITY: |
352 | |||
353 | buf = kmalloc(2 * sizeof(__u8), GFP_KERNEL); | ||
354 | if (!buf) { | ||
355 | ret = -ENOMEM; | ||
356 | break; | ||
357 | } | ||
352 | ret = dev->hid_get_raw_report(dev, dev->battery_report_id, | 358 | ret = dev->hid_get_raw_report(dev, dev->battery_report_id, |
353 | buf, sizeof(buf), | 359 | buf, 2, |
354 | dev->battery_report_type); | 360 | dev->battery_report_type); |
355 | 361 | ||
356 | if (ret != 2) { | 362 | if (ret != 2) { |
357 | ret = -ENODATA; | 363 | ret = -ENODATA; |
364 | kfree(buf); | ||
358 | break; | 365 | break; |
359 | } | 366 | } |
360 | ret = 0; | 367 | ret = 0; |
@@ -364,6 +371,7 @@ static int hidinput_get_battery_property(struct power_supply *psy, | |||
364 | buf[1] <= dev->battery_max) | 371 | buf[1] <= dev->battery_max) |
365 | val->intval = (100 * (buf[1] - dev->battery_min)) / | 372 | val->intval = (100 * (buf[1] - dev->battery_min)) / |
366 | (dev->battery_max - dev->battery_min); | 373 | (dev->battery_max - dev->battery_min); |
374 | kfree(buf); | ||
367 | break; | 375 | break; |
368 | 376 | ||
369 | case POWER_SUPPLY_PROP_MODEL_NAME: | 377 | case POWER_SUPPLY_PROP_MODEL_NAME: |