Skip to content

Commit

Permalink
HID: battery: don't do DMA from stack
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jiri Kosina committed Sep 2, 2013
1 parent a4be0ed commit 6c2794a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions drivers/hid/hid-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static int hidinput_get_battery_property(struct power_supply *psy,
{
struct hid_device *dev = container_of(psy, struct hid_device, battery);
int ret = 0;
__u8 buf[2] = {};
__u8 *buf;

switch (prop) {
case POWER_SUPPLY_PROP_PRESENT:
Expand All @@ -349,12 +349,19 @@ static int hidinput_get_battery_property(struct power_supply *psy,
break;

case POWER_SUPPLY_PROP_CAPACITY:

buf = kmalloc(2 * sizeof(__u8), GFP_KERNEL);
if (!buf) {
ret = -ENOMEM;
break;
}
ret = dev->hid_get_raw_report(dev, dev->battery_report_id,
buf, sizeof(buf),
buf, 2,
dev->battery_report_type);

if (ret != 2) {
ret = -ENODATA;
kfree(buf);
break;
}
ret = 0;
Expand All @@ -364,6 +371,7 @@ static int hidinput_get_battery_property(struct power_supply *psy,
buf[1] <= dev->battery_max)
val->intval = (100 * (buf[1] - dev->battery_min)) /
(dev->battery_max - dev->battery_min);
kfree(buf);
break;

case POWER_SUPPLY_PROP_MODEL_NAME:
Expand Down

0 comments on commit 6c2794a

Please sign in to comment.