From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC01FCA9ED3 for ; Mon, 4 Nov 2019 22:02:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 81BD8217F4 for ; Mon, 4 Nov 2019 22:02:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904961; bh=7CsHA9B5hURGTItzScFRdEZtOT/srucqQJMFJXGiboQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Zuu82M3KHacDDQ2UxpvPvGWjznKrPIcQwvBhdwAr0pD593Jli1/vhKdrDUYO5rQgJ i/FcPLLJNeoOuRVwZEFCY/5rZZEhQnpIeC+FkryijCmM1Sa+dlJEwU91jxY5N2xvra H6EwT+JoxVQ6A2vHR68mykRvnv4idbGb/6ei4on4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389370AbfKDWCj (ORCPT ); Mon, 4 Nov 2019 17:02:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:60880 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388532AbfKDWCb (ORCPT ); Mon, 4 Nov 2019 17:02:31 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6AD8B217F4; Mon, 4 Nov 2019 22:02:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904950; bh=7CsHA9B5hURGTItzScFRdEZtOT/srucqQJMFJXGiboQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qFVHyA7dPa/8BXfxEw+ZK+4c2ybntsM0Qd3o3CP0vrr4axvYT9OgllRt4z875gXxv kJddE88mO4xq+i4N6pmiTb3W2ioGTXBtR/l4KA8qMXYgqdgdDlLlinIqqmH81+OauG jkAQpb9UaYobzIfZ/0IPsaZnTx9IEEG6AvEMa04c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Jiri Kosina Subject: [PATCH 4.19 125/149] HID: fix error message in hid_open_report() Date: Mon, 4 Nov 2019 22:45:18 +0100 Message-Id: <20191104212145.016448337@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212126.090054740@linuxfoundation.org> References: <20191104212126.090054740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michał Mirosław commit b3a81c777dcb093020680490ab970d85e2f6f04f upstream. On HID report descriptor parsing error the code displays bogus pointer instead of error offset (subtracts start=NULL from end). Make the message more useful by displaying correct error offset and include total buffer size for reference. This was carried over from ancient times - "Fixed" commit just promoted the message from DEBUG to ERROR. Cc: stable@vger.kernel.org Fixes: 8c3d52fc393b ("HID: make parser more verbose about parsing errors by default") Signed-off-by: Michał Mirosław Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -975,6 +975,7 @@ int hid_open_report(struct hid_device *d __u8 *start; __u8 *buf; __u8 *end; + __u8 *next; int ret; static int (*dispatch_type[])(struct hid_parser *parser, struct hid_item *item) = { @@ -1028,7 +1029,8 @@ int hid_open_report(struct hid_device *d device->collection_size = HID_DEFAULT_NUM_COLLECTIONS; ret = -EINVAL; - while ((start = fetch_item(start, end, &item)) != NULL) { + while ((next = fetch_item(start, end, &item)) != NULL) { + start = next; if (item.format != HID_ITEM_FORMAT_SHORT) { hid_err(device, "unexpected long global item\n"); @@ -1058,7 +1060,8 @@ int hid_open_report(struct hid_device *d } } - hid_err(device, "item fetching failed at offset %d\n", (int)(end - start)); + hid_err(device, "item fetching failed at offset %u/%u\n", + size - (unsigned int)(end - start), size); err: kfree(parser->collection_stack); alloc_err: