Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1687263ybc; Wed, 13 Nov 2019 02:48:27 -0800 (PST) X-Google-Smtp-Source: APXvYqxu06WmNjDnfPnMO68VoFZEmc7yc/eZ68WngyBVKugw/dVO6Q1dpNmfeQnp0G6e6u8wZo/8 X-Received: by 2002:a17:906:351b:: with SMTP id r27mr2067112eja.120.1573642107678; Wed, 13 Nov 2019 02:48:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573642107; cv=none; d=google.com; s=arc-20160816; b=zzOhtzeAQOofVC6viH1GCS2hsoIytJ8y01LQ1RW+LI+3UMFdnh4Ep//BU8uCzD88BN xArPExm5CvBOaMG/M4B8lBbKfeyIvJ6JtKC9fMJd7UvzPjglASZB1STXi0DDt/881EvY Cj6awfvbZQbLj4bT1OtjDtA2EgMaUDvHw0jfSmSZv4g603ra+UvM5o7WDP3l9FkWk3Kt CVfVebKxX4gHmRoBHbHrBOWgH70GoSs1PtkerAKm0HdKqNODweaN7rl1bvvN91PPefwv 6nVgeM18FAlX4QfIOXzBCE30wX/IrB9FfhH2ghklYvV4nZXXcWL450924VFM8JySEEcp sdWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=o64qYnNgTu7oyr/3NecIRor615SU8V9Mo64ro/2ZxpU=; b=P22/8EY3AfuJHgy4tvv8G1E0x+zbk63mJIQh9UrqpHp01KZ8d2aPyGHkdbrZS0t7mx F/P68PIUnG6l2HfMoBvK5B+CpeNuWae8hBItvTrJGP0njqi37L8wIZFMpDXpXa+vrw0y ry2Bn+7qkAdDmvS7T8vPj9JSLm80aTHlvHyb9K1X07RdrMK+GLRVjOJwrZyreHJlXlDt HqjvTF5ZbPfQjmckNnygpsOnPSFSujASe0DWdHH4GTOlg0e0XE3HSqAws4dnqNxrvqH2 ssDKk8oKms2nrliH/4NR5ahO4UhIcpta3l7CQ/ufd2kTu1myW74ixY23Hchf5G7QzJ8f 3lCg== ARC-Authentication-Results: i=1; mx.google.com; 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 c23si881721ejk.143.2019.11.13.02.48.02; Wed, 13 Nov 2019 02:48:27 -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; 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 S1727323AbfKMKr0 (ORCPT + 99 others); Wed, 13 Nov 2019 05:47:26 -0500 Received: from jabberwock.ucw.cz ([46.255.230.98]:50828 "EHLO jabberwock.ucw.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726138AbfKMKr0 (ORCPT ); Wed, 13 Nov 2019 05:47:26 -0500 Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id A1F421C122C; Wed, 13 Nov 2019 11:47:24 +0100 (CET) Date: Wed, 13 Nov 2019 11:47:24 +0100 From: Pavel Machek To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Jason Gerecke , Aaron Armstrong Skomra , Jiri Kosina Subject: Re: [PATCH 4.19 027/125] HID: wacom: generic: Treat serial number and related fields as unsigned Message-ID: <20191113104724.GD32553@amd> References: <20191111181438.945353076@linuxfoundation.org> <20191111181444.186103315@linuxfoundation.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="bajzpZikUji1w+G9" Content-Disposition: inline In-Reply-To: <20191111181444.186103315@linuxfoundation.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --bajzpZikUji1w+G9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! > From: Jason Gerecke >=20 > commit ff479731c3859609530416a18ddb3db5db019b66 upstream. >=20 > The HID descriptors for most Wacom devices oddly declare the serial > number and other related fields as signed integers. When these numbers > are ingested by the HID subsystem, they are automatically sign-extended > into 32-bit integers. We treat the fields as unsigned elsewhere in the > kernel and userspace, however, so this sign-extension causes problems. > In particular, the sign-extended tool ID sent to userspace as ABS_MISC > does not properly match unsigned IDs used by xf86-input-wacom and libwaco= m. >=20 > We introduce a function 'wacom_s32tou' that can undo the automatic sign > extension performed by 'hid_snto32'. We call this function when processing > the serial number and related fields to ensure that we are dealing with > and reporting the unsigned form. We opt to use this method rather than > adding a descriptor fixup in 'wacom_hid_usage_quirk' since it should be > more robust in the face of future devices. > +++ b/drivers/hid/wacom.h > @@ -205,6 +205,21 @@ static inline void wacom_schedule_work(s > } > } > =20 > +/* > + * Convert a signed 32-bit integer to an unsigned n-bit integer. Undoes > + * the normally-helpful work of 'hid_snto32' for fields that use signed > + * ranges for questionable reasons. > + */ > +static inline __u32 wacom_s32tou(s32 value, __u8 n) > +{ > + switch (n) { > + case 8: return ((__u8)value); > + case 16: return ((__u16)value); > + case 32: return ((__u32)value); > + } > + return value & (1 << (n - 1)) ? value & (~(~0U << n)) : value; > +} Can we do something like: BUG_ON(n>32); if (n=3D=3D32) return ((__u32)value); return value & ((1 << n) - 1); instead? Best regards, Pavel --=20 DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany --bajzpZikUji1w+G9 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAl3L3zsACgkQMOfwapXb+vL8/QCgiIe5oadhm4mIYIdDv4aDxKpc 7xAAoKcXIlCR+wWD6Y3I/GPxZDGSo9KG =sUjw -----END PGP SIGNATURE----- --bajzpZikUji1w+G9--