Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4502339ybx; Mon, 4 Nov 2019 14:27:57 -0800 (PST) X-Google-Smtp-Source: APXvYqwihaiOT5RMtQr0fwf8FEkVGQTzvlA8ohifO1Lwd+d3E+gIn1Xuzqdyu53OLMChqb6sF1bg X-Received: by 2002:a17:906:3946:: with SMTP id g6mr26215082eje.49.1572906476912; Mon, 04 Nov 2019 14:27:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572906476; cv=none; d=google.com; s=arc-20160816; b=gCo5T8KZIeKutxX5LEYZHdsYvGioaHf90geaxdUZYNPDEB5WWKtBZBlzG0r26p6uYs h+Q959tLflBnI64ZH1LjXRH2MtbRKk3V8nAccGhUCyZPBvybK6cCD0EK1+WKflJdsd1h wJz3Hg9YdE9aKkZnLIvQUmfs9ge+JSULY2IPRtamNU485X8pVf1zTBD/s+dhb2VBfBOz tuB6abmLpe/KUPB+pWQlz0JA1RGwEujSKvQV2qcwusbj+InPEoCXiue39FC1Y5GyTJOE hN1ZKHvHlVj8T2xw8k10dT1hRhNDaY9uXyAzI9X/CWOd1LJx1cpsfXW6UYrnJ1EoDiKq tPPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AWEMzMnrjV4hF5epp09cL4uYOEvWlY58J2FAkoiDt6A=; b=mXYVP2NbKGdsT96gdEnWbgmYKOez/atvC1o26r5EV0TP3nvF3SsvhE5M8M8HlRildi kLi4IWaubR59hOoNL/gl+STNfl6L1rwYbSQXQV7QWf027IDQRrMZ2frqF4PTz7FmIpVk J7i9KX3DVgH6FhB9GEqV909w8+HL3TocD9rcpb+876s8eymg4FZuctuaQl0ILH/nua22 Ia04JPndQyxnJrJwCVgFYhYAJGWip63OIGxMLo6orVaHVxg6OerYqqrsMbuTCHcmhgNt 4PgMCawqWb4S+xs1RIQslccSxbgTwT4RldYZ4yD/UHBx/6iNOHVEPvBvD0SyTT1ZO2Tu Q6VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tbRaoD5N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay3si101417ejb.408.2019.11.04.14.27.33; Mon, 04 Nov 2019 14:27:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tbRaoD5N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730489AbfKDW0g (ORCPT + 99 others); Mon, 4 Nov 2019 17:26:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:44032 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730440AbfKDVvM (ORCPT ); Mon, 4 Nov 2019 16:51:12 -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 6B5AC2184C; Mon, 4 Nov 2019 21:51:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904271; bh=mOzjGy2Q9cTEq/lLvfPWhDSPbJebbl1LtvQpkbyCVFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tbRaoD5NSlReEzvmf1iulYThryTdMmKh3hJlEtZiyo/EWCahvVfGQ5jG7hwNIA3s+ AcOoPeb3kOiL5pq+OPJkILukwjxyKfLCLU7Zt9lJCyt0OzPXB0AgAcKzH3vPxrIID7 g4TUh+1gQIb/W/Fc8+JD8RN0ZXJ3qBcH8Qa6Bc4A= 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.9 46/62] HID: fix error message in hid_open_report() Date: Mon, 4 Nov 2019 22:45:08 +0100 Message-Id: <20191104211948.980134951@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104211901.387893698@linuxfoundation.org> References: <20191104211901.387893698@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 @@ -959,6 +959,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) = { @@ -1012,7 +1013,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"); @@ -1041,7 +1043,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: vfree(parser); hid_close_report(device);