From patchwork Thu Mar 4 21:33:49 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pete Zaitcev X-Patchwork-Id: 83681 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o24LXnhv018910 for ; Thu, 4 Mar 2010 21:33:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752999Ab0CDVds (ORCPT ); Thu, 4 Mar 2010 16:33:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:30455 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752525Ab0CDVds (ORCPT ); Thu, 4 Mar 2010 16:33:48 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o24LXjDa016590 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 4 Mar 2010 16:33:46 -0500 Received: from ns3.rdu.redhat.com ([10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o24LXjgx010787; Thu, 4 Mar 2010 16:33:45 -0500 Received: from localhost (vpn-234-71.phx2.redhat.com [10.3.234.71]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o24LXhwu002260; Thu, 4 Mar 2010 16:33:44 -0500 Date: Thu, 4 Mar 2010 14:33:49 -0700 From: Pete Zaitcev To: linux-input@vger.kernel.org Cc: , zaitcev@redhat.com Subject: Zeroing the report before setting fields Message-ID: <20100304143349.2d861ec6@redhat.com> Organization: Red Hat, Inc. Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 04 Mar 2010 21:33:49 +0000 (UTC) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index eabe5f8..14b45b1 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -929,6 +929,15 @@ exit: kfree(value); } +static unsigned int hid_field_length(struct hid_field *field) +{ + unsigned count = field->report_count; + unsigned offset = field->report_offset; + unsigned size = field->report_size; + + return offset + count * size; +} + /* * Output the field into the report. */ @@ -938,13 +947,8 @@ static void hid_output_field(struct hid_field *field, __u8 *data) unsigned count = field->report_count; unsigned offset = field->report_offset; unsigned size = field->report_size; - unsigned bitsused = offset + count * size; unsigned n; - /* make sure the unused bits in the last byte are zeros */ - if (count > 0 && size > 0 && (bitsused % 8) != 0) - data[(bitsused-1)/8] &= (1 << (bitsused % 8)) - 1; - for (n = 0; n < count; n++) { if (field->logical_minimum < 0) /* signed values */ implement(data, offset + n * size, size, s32ton(field->value[n], size)); @@ -960,10 +964,19 @@ static void hid_output_field(struct hid_field *field, __u8 *data) void hid_output_report(struct hid_report *report, __u8 *data) { unsigned n; + unsigned length, bitsused; if (report->id > 0) *data++ = report->id; + length = 0; + for (n = 0; n < report->maxfield; n++) { + bitsused = hid_field_length(report->field[n]); + if (bitsused > length) + length = bitsused; + } + memset(data, 0, (length + 7) / 8); + for (n = 0; n < report->maxfield; n++) hid_output_field(report->field[n], data); }