Commit 735b7d0c authored by Jiri Kosina's avatar Jiri Kosina Committed by Greg Kroah-Hartman

HID: battery: don't do DMA from stack

commit 6c2794a2984f4c17a58117a68703cc7640f01c5a upstream.

Instead of using data from stack for DMA in hidinput_get_battery_property(),
allocate the buffer dynamically.
Reported-by: default avatarRichard Ryniker <ryniker@alum.mit.edu>
Reported-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2dbe9ce6
......@@ -314,7 +314,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:
......@@ -323,13 +323,20 @@ 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) {
if (ret >= 0)
ret = -EINVAL;
kfree(buf);
break;
}
......@@ -338,6 +345,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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment