From patchwork Tue Jul 30 21:35:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 815469 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8B6E145FEF; Tue, 30 Jul 2024 21:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722375375; cv=none; b=ioeMqkbEs4heRhcNsjm/dHmGuL2g/ASTxXyZMeX1yk24Mrt9js7B7Ra4Bi2pNqkidseRfc0bMnybUZjNZZjoWPUg1+EgsXJ5gCpaFMuj753f6xFzukD+99bAK5HA96NTmA6z8uvU6G/Bw9FwTcKXQlGrBn6L/TtCvMi3g1AcQrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722375375; c=relaxed/simple; bh=CuCPxz/YYLzA4evHClClTWRKVOvvMIx6m6M1HhhjvJw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bnCTya0KaOV9WwBclluqdw1k4XOyuwDtNSRyxkQQliNfUswt0apNm733y6cN8qr/43WlnbsXTHgJOWDTPLKlqXnVRH/XE3GFXuRswqRPxAFddDVaLuU6l8VGSLL+iiAlOosEZqw8PufUgmi8ScykT7weKaZ0iqWBVAtjyeaeaq0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=Gy6zEL6m; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="Gy6zEL6m" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1722375361; bh=CuCPxz/YYLzA4evHClClTWRKVOvvMIx6m6M1HhhjvJw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Gy6zEL6mvS8A/NgRcnVeeOoVl948AKfpjeRrf1UXxIUGAu3axFwTrOT8xLUbL8Cpy gITObj2lOL6F4VItRNZzjyavnGFHJpybFDoeRkpZcthyRW0C7mzVWmKkmVY3A0I7Ki ZQl8w0+uZnwrO0p5+sB0sO1vvEpfDyldYVEUlFXc= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 30 Jul 2024 23:35:57 +0200 Subject: [PATCH RFC 1/4] HID: treat fixed up report as const Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240730-hid-const-fixup-v1-1-f667f9a653ba@weissschuh.net> References: <20240730-hid-const-fixup-v1-0-f667f9a653ba@weissschuh.net> In-Reply-To: <20240730-hid-const-fixup-v1-0-f667f9a653ba@weissschuh.net> To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Tho?= =?utf-8?q?mas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722375361; l=1162; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=CuCPxz/YYLzA4evHClClTWRKVOvvMIx6m6M1HhhjvJw=; b=2X4hlJon375StyoXGzTN+k5j8d3rhRDdjk6ApotaD5JDflxLk7VNkWqCo9JtsdXGpFvFnPZm9 ouBk3GCMVD9B7S2CLuOBh1fxgDAg4dTlpf9WtcA4fqns5CEtKQtLc// X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Prepare the HID core for the ->report_fixup() callback to return const data. This will then allow the HID drivers to store their static reports in read-only memory. Signed-off-by: Thomas Weißschuh --- drivers/hid/hid-core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 988d0acbdf04..dc233599ae56 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1203,6 +1203,7 @@ int hid_open_report(struct hid_device *device) { struct hid_parser *parser; struct hid_item item; + const __u8 *fixed_up; unsigned int size; __u8 *start; __u8 *buf; @@ -1232,11 +1233,11 @@ int hid_open_report(struct hid_device *device) return -ENOMEM; if (device->driver->report_fixup) - start = device->driver->report_fixup(device, buf, &size); + fixed_up = device->driver->report_fixup(device, buf, &size); else - start = buf; + fixed_up = buf; - start = kmemdup(start, size, GFP_KERNEL); + start = kmemdup(fixed_up, size, GFP_KERNEL); kfree(buf); if (start == NULL) return -ENOMEM; From patchwork Tue Jul 30 21:35:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 815471 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8C4F18DF81; Tue, 30 Jul 2024 21:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722375373; cv=none; b=FdrjYkXI7z5lV663L1sy6rb++swUPvKL7zn0/YMTKMeHHH4+h8AawZ4sdfXmfz0mQtLw2Afiv8oeDeRG0oyVxhDWlQFqi8mfN0+WD1wu5jS35inx4Jz5ee+h4aAp8HvWyJ8p+1StVFttPRyJwj6EeoUOWVGY3y1Ugz1HsMIjWgA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722375373; c=relaxed/simple; bh=HqF2jZdEKGHsJTB8RCtb6VbOiiZngzSQrgnKBN4QiNQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IV3KzcsIj5BWeHCA0sNJreqZhp5WmioXHlMdgVtp56iydBtUdSFU3nhwuz3W49CA93HM4A0DeM3VwlylTo+m4zS5wgrXgy1Lob4VhZB2EM9NeRY67pXV7f4jnKwK5ni8+c8hG8See4U8/e5Ol8/1MPXLBdlWgKqcrIklKOubqms= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=UcR1fYmh; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="UcR1fYmh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1722375361; bh=HqF2jZdEKGHsJTB8RCtb6VbOiiZngzSQrgnKBN4QiNQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=UcR1fYmhIPiLf7jSNGgsbQD5YJgGX21t74ttJmAZoGihKCoHCG1tgdoJYjB1xtmDi 6sDIQhLCymNmJbdazxZKXU8L0bT5bXe4VEvAZ9t6rJkt2uvFc2uRbX4Shmf6cmOvzx WCUW7hT6KyFrjZzqVWZ/ueDUIWJuXPm27cLPjIUE= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 30 Jul 2024 23:35:58 +0200 Subject: [PATCH RFC 2/4] HID: cmedia: directly return fixed up rdesc Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240730-hid-const-fixup-v1-2-f667f9a653ba@weissschuh.net> References: <20240730-hid-const-fixup-v1-0-f667f9a653ba@weissschuh.net> In-Reply-To: <20240730-hid-const-fixup-v1-0-f667f9a653ba@weissschuh.net> To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Tho?= =?utf-8?q?mas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722375361; l=899; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=HqF2jZdEKGHsJTB8RCtb6VbOiiZngzSQrgnKBN4QiNQ=; b=gtPWFFwLa6VlvpwpvXzX9Y5A3YmU7yMB1ZFLFRqndnTDY02vBB5z4jQMMGm5xZMY3RgUQXWJR uSycQzj0cEMCUqiLNxX8nRSuaHRcKLcoDYMoftPMWEn3tdfADcBpoF/ X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= In a future patch the return type of the _report_fixup() callback will change to "const", but the "rdesc" parameter will stay non-const. Avoid constness errors in that case by not assigning to rdesc but returning directly. Signed-off-by: Thomas Weißschuh --- drivers/hid/hid-cmedia.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/hid-cmedia.c b/drivers/hid/hid-cmedia.c index cab42047bc99..0681d8882ac8 100644 --- a/drivers/hid/hid-cmedia.c +++ b/drivers/hid/hid-cmedia.c @@ -204,8 +204,8 @@ static __u8 *cmhid_hs100b_report_fixup(struct hid_device *hid, __u8 *rdesc, { if (*rsize == HS100B_RDESC_ORIG_SIZE) { hid_info(hid, "Fixing CMedia HS-100B report descriptor\n"); - rdesc = hs100b_rdesc_fixed; *rsize = sizeof(hs100b_rdesc_fixed); + return hs100b_rdesc_fixed; } return rdesc; } From patchwork Tue Jul 30 21:36:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 815470 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8BBF18B46A; Tue, 30 Jul 2024 21:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722375373; cv=none; b=Fpm1o9O05KbmJhEPtzvMqYBqlGrC2Rn7dk5YNnhXWmAKyMQzVAYl6yGFSiM8MEUAU6x1/7roy26M7p0ny10oJMBwgNPDv0GscVDZEgWXm4GBcGuqx3BqTAc91LjEckLRX3euBV95xpLyTUqWAIGeq9ejwoYCSjKjoFShiw370tI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722375373; c=relaxed/simple; bh=LHZUnDmwFmh2fmeCMgokisCrnfbDNiATUFJWQDX71ZM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T3yCnCoR6VMyyUXL/+isenuVzs5T/V+rH+t1iv0J7FgMFslkKexHoB1O17FhYiNFfRTo9FrXPaVIxndMLSGWbfHsmPFEPye3ZKEZZpoOB8SKGlk1KIGcr/MtBWe8CK2NG78w/acOm/8bviTSgDGNHVB2M4pF4SMyFkVhuMQGQ4E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=Cjk/ur9K; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="Cjk/ur9K" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1722375361; bh=LHZUnDmwFmh2fmeCMgokisCrnfbDNiATUFJWQDX71ZM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Cjk/ur9KK6sYkMPTj+0ll6/g30Z/l4RHmEuFOYose44C7XvGGUChPwiLbsptgR3Je CtIliOepImKqNCXtxVexQFPylqDznA09sdUMo+Hhwzn+K8wmomO1D9bSKkmGsLpfRI DF14UJ90gt1GFelAYX6RoI0Dbt54lDSTaQnHN2Hs= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 30 Jul 2024 23:36:00 +0200 Subject: [PATCH RFC 4/4] HID: cmedia: constify fixed up report descriptor Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240730-hid-const-fixup-v1-4-f667f9a653ba@weissschuh.net> References: <20240730-hid-const-fixup-v1-0-f667f9a653ba@weissschuh.net> In-Reply-To: <20240730-hid-const-fixup-v1-0-f667f9a653ba@weissschuh.net> To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Tho?= =?utf-8?q?mas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722375361; l=864; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=LHZUnDmwFmh2fmeCMgokisCrnfbDNiATUFJWQDX71ZM=; b=afXRryW/iPaJsDa968Z+1f22FEEueZPZVceiIxetaiVJMoY0pis3DPqzzzuD8hLjKMW4hAs08 L/GU02du/FFDDqzQFmFYG3MTOW9zxs/xIRrVdk/mtanxucgsGMB38sV X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The HID core now allows static report descriptors to be read-only, make use of it. Signed-off-by: Thomas Weißschuh --- drivers/hid/hid-cmedia.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/hid-cmedia.c b/drivers/hid/hid-cmedia.c index d235dbedab8c..528d7f361215 100644 --- a/drivers/hid/hid-cmedia.c +++ b/drivers/hid/hid-cmedia.c @@ -26,7 +26,7 @@ MODULE_LICENSE("GPL"); /* Fixed report descriptor of HS-100B audio chip * Bit 4 is an abolute Microphone mute usage instead of being unassigned. */ -static __u8 hs100b_rdesc_fixed[] = { +static const __u8 hs100b_rdesc_fixed[] = { 0x05, 0x0C, /* Usage Page (Consumer), */ 0x09, 0x01, /* Usage (Consumer Control), */ 0xA1, 0x01, /* Collection (Application), */