From owner-p4-projects@FreeBSD.ORG Fri May 7 07:39:05 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id EB5E6106566C; Fri, 7 May 2010 07:39:04 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 9770C106564A for ; Fri, 7 May 2010 07:39:04 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 850AA8FC14 for ; Fri, 7 May 2010 07:39:04 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o477d41G058247 for ; Fri, 7 May 2010 07:39:04 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o477d4IE058245 for perforce@freebsd.org; Fri, 7 May 2010 07:39:04 GMT (envelope-from hselasky@FreeBSD.org) Date: Fri, 7 May 2010 07:39:04 GMT Message-Id: <201005070739.o477d4IE058245@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 177882 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 May 2010 07:39:05 -0000 http://p4web.freebsd.org/@@177882?ac=10 Change 177882 by hselasky@hselasky_laptop001 on 2010/05/07 07:38:42 USB CORE: - fix for getting signed and unsigned HID data - patch from: Alex Deiter - reviewed by: HPS @ PR: usb/146367 Affected files ... .. //depot/projects/usb/src/lib/libusbhid/data.c#5 edit .. //depot/projects/usb/src/sys/dev/usb/usb_hid.c#43 edit .. //depot/projects/usb/src/sys/dev/usb/usbhid.h#13 edit Differences ... ==== //depot/projects/usb/src/lib/libusbhid/data.c#5 (text+ko) ==== @@ -63,13 +63,17 @@ data = 0; for (i = 0; i <= end; i++) data |= buf[offs + i] << (i*8); + + /* Correctly shift down data */ data >>= hpos % 8; - data &= (1 << hsize) - 1; - if (h->logical_minimum < 0) { - /* Need to sign extend */ - hsize = sizeof data * 8 - hsize; - data = (data << hsize) >> hsize; - } + hsize = 32 - hsize; + + /* Mask and sign extend in one */ + if ((h->logical_minimum < 0) || (h->logical_maximum < 0)) + data = (int32_t)((int32_t)data << hsize) >> hsize; + else + data = (uint32_t)((uint32_t)data << hsize) >> hsize; + return (data); } ==== //depot/projects/usb/src/sys/dev/usb/usb_hid.c#43 (text+ko) ==== @@ -646,8 +646,9 @@ /*------------------------------------------------------------------------* * hid_get_data *------------------------------------------------------------------------*/ -uint32_t -hid_get_data(const uint8_t *buf, usb_size_t len, struct hid_location *loc) +static uint32_t +hid_get_data_sub(const uint8_t *buf, usb_size_t len, struct hid_location *loc, + uint8_t is_signed) { uint32_t hpos = loc->pos; uint32_t hsize = loc->size; @@ -676,16 +677,31 @@ /* Correctly shift down data */ data = (data >> (hpos % 8)); + n = 32 - hsize; /* Mask and sign extend in one */ - n = 32 - hsize; - data = ((int32_t)data << n) >> n; + if (is_signed != 0) + data = (int32_t)((int32_t)data << n) >> n; + else + data = (uint32_t)((uint32_t)data << n) >> n; DPRINTFN(11, "hid_get_data: loc %d/%d = %lu\n", loc->pos, loc->size, (long)data); return (data); } +int32_t +hid_get_data(const uint8_t *buf, usb_size_t len, struct hid_location *loc) +{ + return (hid_get_data_sub(buf, len, loc, 1)); +} + +uint32_t +hid_get_data_unsigned(const uint8_t *buf, usb_size_t len, struct hid_location *loc) +{ + return (hid_get_data_sub(buf, len, loc, 0)); +} + /*------------------------------------------------------------------------* * hid_is_collection *------------------------------------------------------------------------*/ ==== //depot/projects/usb/src/sys/dev/usb/usbhid.h#13 (text+ko) ==== @@ -229,7 +229,9 @@ int hid_locate(const void *desc, usb_size_t size, uint32_t usage, enum hid_kind kind, uint8_t index, struct hid_location *loc, uint32_t *flags, uint8_t *id); -uint32_t hid_get_data(const uint8_t *buf, usb_size_t len, +int32_t hid_get_data(const uint8_t *buf, usb_size_t len, + struct hid_location *loc); +uint32_t hid_get_data_unsigned(const uint8_t *buf, usb_size_t len, struct hid_location *loc); int hid_is_collection(const void *desc, usb_size_t size, uint32_t usage); struct usb_hid_descriptor *hid_get_descriptor_from_usb(