diff options
author | Yunfan Zhang <yunfanz@nvidia.com> | 2013-12-02 16:22:43 +0800 |
---|---|---|
committer | Yunfan Zhang <yunfanz@nvidia.com> | 2013-12-11 01:14:30 -0800 |
commit | 4d1e623c60d5b41abe6deaf4d86a8953dc1f918c (patch) | |
tree | 882f615a4e31754d5ada43d2ac5cc947d6184429 /drivers/usb | |
parent | 514e9fccb83280e3c6a32f0339bbb09c81f024b6 (diff) |
usb: gadget: android: fix ethaddr override issue
ethaddr is one byte per segment, if pass the casted char pointer to
sscanf with %02x, the upper mem/bytes will be override unexpectedly.
For 32 bits alignment, the first byte of vendorID will be override
by sscanf(..., "...:%02x", ..., (int *)&rndis->ethaddr[5]).
struct rndis_function_config {
u8 ethaddr[6];
u32 vendorID;
...
};
Change-Id: I6553036f6d110e77298cfcf8a4e35f348921851d
Signed-off-by: Yunfan Zhang <yunfanz@nvidia.com>
Reviewed-on: http://git-master/r/337184
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Venkat Moganty <vmoganty@nvidia.com>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/gadget/android.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/drivers/usb/gadget/android.c b/drivers/usb/gadget/android.c index 88c6ac86ac91..11903c3266ef 100644 --- a/drivers/usb/gadget/android.c +++ b/drivers/usb/gadget/android.c @@ -4,6 +4,7 @@ * Copyright (C) 2008 Google, Inc. * Author: Mike Lockwood <lockwood@android.com> * Benoit Goby <benoit@android.com> + * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -698,12 +699,15 @@ static ssize_t rndis_ethaddr_store(struct device *dev, { struct android_usb_function *f = dev_get_drvdata(dev); struct rndis_function_config *rndis = f->config; + int i, ethaddr[6]; if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n", - (int *)&rndis->ethaddr[0], (int *)&rndis->ethaddr[1], - (int *)&rndis->ethaddr[2], (int *)&rndis->ethaddr[3], - (int *)&rndis->ethaddr[4], (int *)&rndis->ethaddr[5]) == 6) - return size; + ðaddr[0], ðaddr[1], ðaddr[2], + ðaddr[3], ðaddr[4], ðaddr[5]) == 6) { + for (i = 0; i < 6; i++) + rndis->ethaddr[i] = ethaddr[i] & 0xFF; + return size; + } return -EINVAL; } |