From patchwork Thu Oct 12 10:23:38 2023 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: 13418808 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63B5ACDB482 for ; Thu, 12 Oct 2023 10:23:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234179AbjJLKX5 (ORCPT ); Thu, 12 Oct 2023 06:23:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347111AbjJLKXw (ORCPT ); Thu, 12 Oct 2023 06:23:52 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88A0CD3; Thu, 12 Oct 2023 03:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1697106227; bh=dcNGhXp5FPTom7QF06OFWt6twK9Wx0jnbCF/HnZ41vM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IxEIFffOIC37ReXiTicel+yXLwHpChvLvrPq5QvxGftNl0sTXr6LNSyA3qazcweoj kEp0rmPIun58vHqP6kaUkoSA4vTSKCd+WrY6xBl0PdPlPGdQX7lO0RFGa0MW2rF+tl F7d+9YguOHYV/qFTj11zoovw6XbwvJPnG3QgPn1E= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 12 Oct 2023 12:23:38 +0200 Subject: [PATCH 1/4] HID: core: remove #ifdef CONFIG_PM from hid_driver MIME-Version: 1.0 Message-Id: <20231012-hid-pm_ptr-v1-1-0a71531ca93b@weissschuh.net> References: <20231012-hid-pm_ptr-v1-0-0a71531ca93b@weissschuh.net> In-Reply-To: <20231012-hid-pm_ptr-v1-0-0a71531ca93b@weissschuh.net> To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1697106227; l=1175; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=dcNGhXp5FPTom7QF06OFWt6twK9Wx0jnbCF/HnZ41vM=; b=Iad8VW67+qA6YLgatRKUO/dbPz3xzTYuvOSHdHEpMdPKfTICbIfy4mSCjas9tG9y14b1Q5eNN 58M7fGLO+jMAhHHV3SuHZoD3CSvt+G3f25G61eBrc9MgUUFGGNLWWuL X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Allow HID drivers to pass ->suspend, ->resume and ->reset_resume via pm_ptr(). Through the usage of pm_ptr() the CONFIG_PM-dependent code will always be compiled, protecting against bitrot. The linker will then garbage-collect the unused function avoiding any overhead. The only overhead in the final kernel image and at runtime are a few extra bytes in 'struct hid_driver'. The same approach is chosen by 'struct usb_driver' and other subsystems. Signed-off-by: Thomas Weißschuh --- include/linux/hid.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/hid.h b/include/linux/hid.h index 964ca1f15e3f..5a8387a4a712 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -833,11 +833,11 @@ struct hid_driver { void (*feature_mapping)(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage); -#ifdef CONFIG_PM + int (*suspend)(struct hid_device *hdev, pm_message_t message); int (*resume)(struct hid_device *hdev); int (*reset_resume)(struct hid_device *hdev); -#endif + /* private: */ struct device_driver driver; }; From patchwork Thu Oct 12 10:23:39 2023 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: 13418810 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66438CDB483 for ; Thu, 12 Oct 2023 10:23:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377851AbjJLKX6 (ORCPT ); Thu, 12 Oct 2023 06:23:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347120AbjJLKXw (ORCPT ); Thu, 12 Oct 2023 06:23:52 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9505D7; Thu, 12 Oct 2023 03:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1697106227; bh=alxO7xFWraA3HKM6WF41cUbPDoefLV3zZhv5I90E+pg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rE7peiHE79iPAIiKLaF0z/949FLJ/Zy4UCL+cNac8N6NcqZdKIxFaw0cJlnM1gWTR j15Ej4Uyo85TUj4naLqIYbTrz5witbF5s+X8Vm7IZyT3Bz8felUWwe/mTjExTs+YRO v07pzvJbFfHJnc1RJ2Krkqf5EZQ4cQ+4XtYmwD/0= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 12 Oct 2023 12:23:39 +0200 Subject: [PATCH 2/4] HID: usbhid: remove #ifdef CONFIG_PM MIME-Version: 1.0 Message-Id: <20231012-hid-pm_ptr-v1-2-0a71531ca93b@weissschuh.net> References: <20231012-hid-pm_ptr-v1-0-0a71531ca93b@weissschuh.net> In-Reply-To: <20231012-hid-pm_ptr-v1-0-0a71531ca93b@weissschuh.net> To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1697106227; l=1539; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=alxO7xFWraA3HKM6WF41cUbPDoefLV3zZhv5I90E+pg=; b=QZGILVOJ+QPVXAY6Zni77eIF0Yi697+rGGIobSGwqD/pkwi/PhoZXOeEfnzUUGYNGtyCSDWc+ uIpEsguUtBWBcXXSKwecJem0jyUsiScgV+6RI3orm8tGu70OZQf7tqH X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Through the usage of pm_ptr() the CONFIG_PM-dependent code will always be compiled, protecting against bitrot. The linker will then garbage-collect the unused function avoiding any overhead. Signed-off-by: Thomas Weißschuh --- drivers/hid/usbhid/hid-core.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 257dd73e37bf..a90ed2ceae84 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -1562,7 +1562,6 @@ static int hid_post_reset(struct usb_interface *intf) return 0; } -#ifdef CONFIG_PM static int hid_resume_common(struct hid_device *hid, bool driver_suspended) { int status = 0; @@ -1654,8 +1653,6 @@ static int hid_reset_resume(struct usb_interface *intf) return status; } -#endif /* CONFIG_PM */ - static const struct usb_device_id hid_usb_ids[] = { { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS, .bInterfaceClass = USB_INTERFACE_CLASS_HID }, @@ -1668,11 +1665,9 @@ static struct usb_driver hid_driver = { .name = "usbhid", .probe = usbhid_probe, .disconnect = usbhid_disconnect, -#ifdef CONFIG_PM - .suspend = hid_suspend, - .resume = hid_resume, - .reset_resume = hid_reset_resume, -#endif + .suspend = pm_ptr(hid_suspend), + .resume = pm_ptr(hid_resume), + .reset_resume = pm_ptr(hid_reset_resume), .pre_reset = hid_pre_reset, .post_reset = hid_post_reset, .id_table = hid_usb_ids, From patchwork Thu Oct 12 10:23:40 2023 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: 13418812 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D09ACDB46E for ; Thu, 12 Oct 2023 10:24:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347111AbjJLKX7 (ORCPT ); Thu, 12 Oct 2023 06:23:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347126AbjJLKXw (ORCPT ); Thu, 12 Oct 2023 06:23:52 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7E18D6; Thu, 12 Oct 2023 03:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1697106227; bh=YveTPkYULLlyEsdLlGA46f1LzhfC/wP+L0Bg43PHoWM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WSw3ac5i301zeAp93+JgG8P+/dbjE6iJwrFUgvgDOcmbL+ihwU1NJW6dnRY5bSNAT K1XArJ0hoKRw49I+WWAvIFZQzDyvTos6aP7M77giF2PMcLFGCPSKQqtTzga9I7/Jb/ xaSOHAmGmSbCIal7m6S7U9LRsCpXENQoDnQu1+8w= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 12 Oct 2023 12:23:40 +0200 Subject: [PATCH 3/4] HID: multitouch: remove #ifdef CONFIG_PM MIME-Version: 1.0 Message-Id: <20231012-hid-pm_ptr-v1-3-0a71531ca93b@weissschuh.net> References: <20231012-hid-pm_ptr-v1-0-0a71531ca93b@weissschuh.net> In-Reply-To: <20231012-hid-pm_ptr-v1-0-0a71531ca93b@weissschuh.net> To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1697106227; l=1381; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=YveTPkYULLlyEsdLlGA46f1LzhfC/wP+L0Bg43PHoWM=; b=i7mP2224uBTGN/Zh76uFUX2dWrxHLRZqal53sVh/xAs7qvfoXcmHUigUcyaoqKjkusVT48IFQ KzCQUgxJJTbAyUUO8Ltk+LzVUb/rArUYbqPhCDY+vtmLPSRnwwmZG4r X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Through the usage of pm_ptr() the CONFIG_PM-dependent code will always be compiled, protecting against bitrot. The linker will then garbage-collect the unused function avoiding any overhead. Signed-off-by: Thomas Weißschuh --- drivers/hid/hid-multitouch.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 521b2ffb4244..2cdfc2a70a83 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -1802,7 +1802,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) return 0; } -#ifdef CONFIG_PM static int mt_suspend(struct hid_device *hdev, pm_message_t state) { struct mt_device *td = hid_get_drvdata(hdev); @@ -1836,7 +1835,6 @@ static int mt_resume(struct hid_device *hdev) return 0; } -#endif static void mt_remove(struct hid_device *hdev) { @@ -2255,10 +2253,8 @@ static struct hid_driver mt_driver = { .usage_table = mt_grabbed_usages, .event = mt_event, .report = mt_report, -#ifdef CONFIG_PM - .suspend = mt_suspend, - .reset_resume = mt_reset_resume, - .resume = mt_resume, -#endif + .suspend = pm_ptr(mt_suspend), + .reset_resume = pm_ptr(mt_reset_resume), + .resume = pm_ptr(mt_resume), }; module_hid_driver(mt_driver); From patchwork Thu Oct 12 10:23:41 2023 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: 13418811 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB049C46CA1 for ; Thu, 12 Oct 2023 10:24:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347129AbjJLKX7 (ORCPT ); Thu, 12 Oct 2023 06:23:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347133AbjJLKXw (ORCPT ); Thu, 12 Oct 2023 06:23:52 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC586D8; Thu, 12 Oct 2023 03:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1697106227; bh=5SDzzt7XMUNLkvBvYEQuCiuGLibIrAFTowagRCe9Ajs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=oWroPJNTMC8gtNsmULdL/9mutmcnqCq14qB3jD6uP8AeUqfk55rqGzOP+tshfTy+G UoacmJ39q0qb5cpMrvr+HqrDDuJmqA0DV3JpdrwnoVCNNqnoSW5eK3gBAzmirhKuZv qm3W1ENvyB5QtWZ4EppYfkq64C8rRifigulx8JR0= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 12 Oct 2023 12:23:41 +0200 Subject: [PATCH 4/4] HID: rmi: remove #ifdef CONFIG_PM MIME-Version: 1.0 Message-Id: <20231012-hid-pm_ptr-v1-4-0a71531ca93b@weissschuh.net> References: <20231012-hid-pm_ptr-v1-0-0a71531ca93b@weissschuh.net> In-Reply-To: <20231012-hid-pm_ptr-v1-0-0a71531ca93b@weissschuh.net> To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1697106227; l=1495; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=5SDzzt7XMUNLkvBvYEQuCiuGLibIrAFTowagRCe9Ajs=; b=M2Rn5UBq5P/gACg74ZfSclny/wCeyqbwxYn0CkHIk8fyb5HNmVZAcKUVOI7MrfDzNO2ubN77k UYptybFID/7BMvOT6sF2m4865QwQnEePXz3yrgm89ADgYFLSrkHFqGq X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Through the usage of pm_ptr() the CONFIG_PM-dependent code will always be compiled, protecting against bitrot. The linker will then garbage-collect the unused function avoiding any overhead. Signed-off-by: Thomas Weißschuh --- drivers/hid/hid-rmi.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c index 84e7ba5314d3..d4af17fdba46 100644 --- a/drivers/hid/hid-rmi.c +++ b/drivers/hid/hid-rmi.c @@ -436,7 +436,6 @@ static void rmi_report(struct hid_device *hid, struct hid_report *report) input_sync(field->hidinput->input); } -#ifdef CONFIG_PM static int rmi_suspend(struct hid_device *hdev, pm_message_t message) { struct rmi_data *data = hid_get_drvdata(hdev); @@ -483,7 +482,6 @@ static int rmi_post_resume(struct hid_device *hdev) hid_hw_close(hdev); return ret; } -#endif /* CONFIG_PM */ static int rmi_hid_reset(struct rmi_transport_dev *xport, u16 reset_addr) { @@ -774,11 +772,9 @@ static struct hid_driver rmi_driver = { .report = rmi_report, .input_mapping = rmi_input_mapping, .input_configured = rmi_input_configured, -#ifdef CONFIG_PM - .suspend = rmi_suspend, - .resume = rmi_post_resume, - .reset_resume = rmi_post_resume, -#endif + .suspend = pm_ptr(rmi_suspend), + .resume = pm_ptr(rmi_post_resume), + .reset_resume = pm_ptr(rmi_post_resume), }; module_hid_driver(rmi_driver);