From patchwork Wed Jan 31 20:21:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Perches X-Patchwork-Id: 194919 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp1706dyc; Wed, 31 Jan 2024 12:23:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IH62Eux96ovKAgprKWrGVdmVEXjqv80xjFXuzA0qdgf2EzqP5zujCB2BwUhWLAmGe0dL9MO X-Received: by 2002:aa7:d394:0:b0:55e:d728:eaa6 with SMTP id x20-20020aa7d394000000b0055ed728eaa6mr4966611edq.19.1706732608232; Wed, 31 Jan 2024 12:23:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706732608; cv=pass; d=google.com; s=arc-20160816; b=jZvdnmpSL06nsSHvm17MV76/uvsYIr2snuWXloQjov51hlbyX5LN2mLlRz93TdXcXv TT71uCZ6I8zHHdvhgI9je3DfzVM3e2UOEWBjQKWQNlkszLhjltaRX1ge7erD7wezfjU5 2rh0d+TZ4pwEjUNvQtGsBc5qxsxGp38e01rPy1GMFkxSkgnJ3LT7pb2N0U+l3Pq7IyBW OhI0s9M+jDzf10grV7vXLPPs4GMBQybRjmocPd65tMHCMgA05dD8G4rcZQCjR+mI8Y0D +sNFaKNEyozGHkP4sBEmfcJUxGnotPmNpQSxL8dNj3wxN/EWn22ZNfGLYaVjkZaJlJTc 1jlg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=B46BFxnK3wuVynfm7QaYyePgdILTucFUjGYpsAU1kkA=; fh=z/+3cAa7IbcsETqun4OXHUBpZfk0cW0XJvzpoAuzW1M=; b=ZAbbuho+cYIMYi9LRfWerU/M170G80EdUStLd0+Q1ggHWUdeqjwtWyrAKWY1PUtrJd /Gw7LVqPCHqecwDLG9CvokxSHPp4m/9U1tLvK6IzVYSlwThD+RXsnUYvQ1XJwO7ApbQw AwmyItRurAVTyOFHMiljuwzfILDQzh4WsbKYtfH5pZmJwU1qi5b3/Q+kEiNBNYSYFT7Z jY30a3dWw7aIA7tY1nmnSS7A8Tb8pFtFDZYS+1noivp42ErikL1KG1SmcURj9PU4GgQf PyUDdntqE7S3SOMyhNS0N9BT0i9IHw1812vDngWiy00gO+QjQHbzWbG4ONNONBET/0BU i9dw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=perches.com); spf=pass (google.com: domain of linux-kernel+bounces-47061-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47061-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVqg+DP/QBkGgqmXqG7sEh2hwllDVLnqNgIIkUwRuIatfFwfF5qAdDWtvMjpDQwxXHs1KSIFFWOnmJi+0HDMSaTT79ryg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c12-20020a50d64c000000b0055cc324ec7csi6209644edj.353.2024.01.31.12.23.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 12:23:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47061-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=perches.com); spf=pass (google.com: domain of linux-kernel+bounces-47061-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47061-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 765031F2330F for ; Wed, 31 Jan 2024 20:23:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4ED17405D8; Wed, 31 Jan 2024 20:23:03 +0000 (UTC) Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) (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 645733FE20; Wed, 31 Jan 2024 20:22:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.40.44.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706732580; cv=none; b=We9LjKuIQ8yncrYcnpmilnvKu6VCo3pKT4KoZ+Y3BTKKr8z4jEbnzTG6Yi8W8zwP0TCRxVs0kyCI8D21nsyRZTDeTcr4X1AsZTlafR6eBdksJQIHmGsPMSaiNKOITAcgDeLfjWIwzvTK5hdXbt+RrcBNhOGVCnbOWuogeq+Rju0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706732580; c=relaxed/simple; bh=kzei8YWWi1vwFBuTAKOyOGKxOcpujzjI9lYL/4wSxIU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dqBNcsHMQ7xEme2SHNmZ76lxodHlSqsBnTO+zE9Pwld8CevaJ2vaFXLotXueISFQrrY9wxyoz/OjQbIrSQ3wF/QGZeeyvXTroSJ7E+pRiClCgAzQgU4CFy0o0+muso8aKEqpjDNVElNzWNr9cq2XIDd/gUomyF4oVaxsbH9fZho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=perches.com; spf=pass smtp.mailfrom=perches.com; arc=none smtp.client-ip=216.40.44.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=perches.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=perches.com Received: from omf01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DE4D41A0D9C; Wed, 31 Jan 2024 20:22:56 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf01.hostedemail.com (Postfix) with ESMTPA id AB4256000C; Wed, 31 Jan 2024 20:22:40 +0000 (UTC) From: Joe Perches To: Jiri Kosina , Benjamin Tissoires Cc: Sandeep C S , Junwan Cho , Jitender Sajwan , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] HID: samsung: Object size reduction and neatening Date: Wed, 31 Jan 2024 12:21:37 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: AB4256000C X-Stat-Signature: witbnhdefiu1taqjw7z7potc8thxnxqm X-Rspamd-Server: rspamout04 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1/sGWd9AtS21nJhxuYC7ToKxHkz4KvdAAw= X-HE-Tag: 1706732560-721697 X-HE-Meta: U2FsdGVkX1/b8I9eB1qR9uZkl8WC4GRPRa7N2Fps1EcL3Es7JFYZ/dtGi/JXFdwxAItyPX+VP++rELgkiiP8WMJF7dwWqJ2lY0asEKYJ8JAUoNArtorjeBEHegFdO70DRqCSWgBKShHTTG3D66Ic+l4XgzfBDQojRBDl1nVHMrTvyF9HXmYUKNcGOqLDhRlYjCut1AopSPEhvCus6b6OZAW7o5vikaxBt2Jk+ky8QOGyNUP9Lv66QHXs7oXdnXMFhB1jEO/6cR1ne5lgIKumxnL4azIevcoQbCCmlApkWP/Vn6yXgVyxX31XO2jt6ceCyvSlpHusQf0= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789638851166662758 X-GMAIL-MSGID: 1789638851166662758 Use a switch/case in samsung_input_mapping to reduce object size. $ size drivers/hid/hid-samsung.o* text data bss dec hex filename 2842 432 0 3274 cca drivers/hid/hid-samsung.o.new 3203 440 0 3643 e3b drivers/hid/hid-samsung.o.old Miscellaneous style neatening: o Use unsigned int instead of unsigned o Alignment to open parenthesis o Line wrapping Signed-off-by: Joe Perches --- drivers/hid/hid-samsung.c | 166 +++++++++++++++++++++----------------- 1 file changed, 94 insertions(+), 72 deletions(-) diff --git a/drivers/hid/hid-samsung.c b/drivers/hid/hid-samsung.c index d701dd3a914e7..63c18b9b8279f 100644 --- a/drivers/hid/hid-samsung.c +++ b/drivers/hid/hid-samsung.c @@ -49,31 +49,35 @@ * Report #3 has an array field with logical range 0..1 instead of 1..3. */ static inline void samsung_irda_dev_trace(struct hid_device *hdev, - unsigned int rsize) + unsigned int rsize) { hid_info(hdev, "fixing up Samsung IrDA %d byte report descriptor\n", rsize); } static __u8 *samsung_irda_report_fixup(struct hid_device *hdev, __u8 *rdesc, - unsigned int *rsize) + unsigned int *rsize) { - if (*rsize == 184 && !memcmp(&rdesc[175], "\x25\x40\x75\x30\x95\x01", 6) && - rdesc[182] == 0x40) { + if (*rsize == 184 && + !memcmp(&rdesc[175], "\x25\x40\x75\x30\x95\x01", 6) && + rdesc[182] == 0x40) { samsung_irda_dev_trace(hdev, 184); rdesc[176] = 0xff; rdesc[178] = 0x08; rdesc[180] = 0x06; rdesc[182] = 0x42; - } else if (*rsize == 203 && !memcmp(&rdesc[192], "\x15\x00\x25\x12", 4)) { + } else if (*rsize == 203 && + !memcmp(&rdesc[192], "\x15\x00\x25\x12", 4)) { samsung_irda_dev_trace(hdev, 203); rdesc[193] = 0x01; rdesc[195] = 0x0f; - } else if (*rsize == 135 && !memcmp(&rdesc[124], "\x15\x00\x25\x11", 4)) { + } else if (*rsize == 135 && + !memcmp(&rdesc[124], "\x15\x00\x25\x11", 4)) { samsung_irda_dev_trace(hdev, 135); rdesc[125] = 0x01; rdesc[127] = 0x0e; - } else if (*rsize == 171 && !memcmp(&rdesc[160], "\x15\x00\x25\x01", 4)) { + } else if (*rsize == 171 && + !memcmp(&rdesc[160], "\x15\x00\x25\x01", 4)) { samsung_irda_dev_trace(hdev, 171); rdesc[161] = 0x01; rdesc[163] = 0x03; @@ -82,19 +86,21 @@ static __u8 *samsung_irda_report_fixup(struct hid_device *hdev, __u8 *rdesc, } struct key_clear_map { - unsigned use; + unsigned int use; __u16 kb; }; static int samsung_kbd_mouse_input_mapping(struct hid_device *hdev, - struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, - unsigned long **bit, int *max) + struct hid_input *hi, + struct hid_field *field, + struct hid_usage *usage, + unsigned long **bit, int *max) { struct usb_interface *intf = to_usb_interface(hdev->dev.parent); unsigned short ifnum = intf->cur_altsetting->desc.bInterfaceNumber; int i; - unsigned use; - unsigned up = usage->hid & HID_USAGE_PAGE; + unsigned int use; + unsigned int up = usage->hid & HID_USAGE_PAGE; static const struct key_clear_map kcm[] = { { 0x183, KEY_MEDIA }, { 0x195, KEY_EMAIL }, @@ -129,12 +135,14 @@ static int samsung_kbd_mouse_input_mapping(struct hid_device *hdev, } static int samsung_kbd_input_mapping(struct hid_device *hdev, - struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, - unsigned long **bit, int *max) + struct hid_input *hi, + struct hid_field *field, + struct hid_usage *usage, + unsigned long **bit, int *max) { int i; - unsigned use; - unsigned up = usage->hid & HID_USAGE_PAGE; + unsigned int use; + unsigned int up = usage->hid & HID_USAGE_PAGE; if (!(up == HID_UP_CONSUMER || up == HID_UP_KEYBOARD)) return 0; @@ -193,12 +201,14 @@ static int samsung_kbd_input_mapping(struct hid_device *hdev, } static int samsung_gamepad_input_mapping(struct hid_device *hdev, - struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, - unsigned long **bit, int *max) + struct hid_input *hi, + struct hid_field *field, + struct hid_usage *usage, + unsigned long **bit, int *max) { int i; - unsigned use; - unsigned up = usage->hid & HID_USAGE_PAGE; + unsigned int use; + unsigned int up = usage->hid & HID_USAGE_PAGE; if (!(up == HID_UP_BUTTON || up == HID_UP_CONSUMER)) return 0; @@ -258,12 +268,14 @@ static int samsung_gamepad_input_mapping(struct hid_device *hdev, } static int samsung_actionmouse_input_mapping(struct hid_device *hdev, - struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, - unsigned long **bit, int *max) + struct hid_input *hi, + struct hid_field *field, + struct hid_usage *usage, + unsigned long **bit, int *max) { int i; - unsigned use; - unsigned up = usage->hid & HID_USAGE_PAGE; + unsigned int use; + unsigned int up = usage->hid & HID_USAGE_PAGE; static const struct key_clear_map kcm[] = { { 0x301, 254 }, }; @@ -271,7 +283,8 @@ static int samsung_actionmouse_input_mapping(struct hid_device *hdev, use = usage->hid & HID_USAGE; dbg_hid("samsung wireless actionmouse input mapping event [0x%x], [0x%x], %ld, %ld, [0x%x]\n", - use, usage->hid & HID_USAGE, hi->input->evbit[0], hi->input->absbit[0], + use, usage->hid & HID_USAGE, + hi->input->evbit[0], hi->input->absbit[0], up); if (!(up == HID_UP_CONSUMER || up == HID_UP_BUTTON)) @@ -288,12 +301,14 @@ static int samsung_actionmouse_input_mapping(struct hid_device *hdev, } static int samsung_universal_kbd_input_mapping(struct hid_device *hdev, - struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, - unsigned long **bit, int *max) + struct hid_input *hi, + struct hid_field *field, + struct hid_usage *usage, + unsigned long **bit, int *max) { int i; - unsigned use; - unsigned up = usage->hid & HID_USAGE_PAGE; + unsigned int use; + unsigned int up = usage->hid & HID_USAGE_PAGE; if (!(up == HID_UP_CONSUMER || up == HID_UP_KEYBOARD)) return 0; @@ -362,43 +377,46 @@ static int samsung_universal_kbd_input_mapping(struct hid_device *hdev, } static __u8 *samsung_report_fixup(struct hid_device *hdev, __u8 *rdesc, - unsigned int *rsize) + unsigned int *rsize) { - if (hdev->product == USB_DEVICE_ID_SAMSUNG_IR_REMOTE && hid_is_usb(hdev)) + if (hdev->product == USB_DEVICE_ID_SAMSUNG_IR_REMOTE && + hid_is_usb(hdev)) rdesc = samsung_irda_report_fixup(hdev, rdesc, rsize); return rdesc; } -static int samsung_input_mapping(struct hid_device *hdev, struct hid_input *hi, - struct hid_field *field, struct hid_usage *usage, - unsigned long **bit, int *max) +static int samsung_input_mapping(struct hid_device *hdev, + struct hid_input *hi, + struct hid_field *field, + struct hid_usage *usage, + unsigned long **bit, int *max) { - int ret = 0; - - if (hdev->product == USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE && hid_is_usb(hdev)) - ret = samsung_kbd_mouse_input_mapping(hdev, - hi, field, usage, bit, max); - else if (hdev->product == USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD) - ret = samsung_kbd_input_mapping(hdev, - hi, field, usage, bit, max); - else if (hdev->product == USB_DEVICE_ID_SAMSUNG_WIRELESS_GAMEPAD) - ret = samsung_gamepad_input_mapping(hdev, - hi, field, usage, bit, max); - else if (hdev->product == USB_DEVICE_ID_SAMSUNG_WIRELESS_ACTIONMOUSE) - ret = samsung_actionmouse_input_mapping(hdev, - hi, field, usage, bit, max); - else if (hdev->product == USB_DEVICE_ID_SAMSUNG_WIRELESS_UNIVERSAL_KBD) - ret = samsung_universal_kbd_input_mapping(hdev, - hi, field, usage, bit, max); - else if (hdev->product == USB_DEVICE_ID_SAMSUNG_WIRELESS_MULTI_HOGP_KBD) - ret = samsung_universal_kbd_input_mapping(hdev, - hi, field, usage, bit, max); - - return ret; + switch (hdev->product) { + case USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE: + if (hid_is_usb(hdev)) + return samsung_kbd_mouse_input_mapping(hdev, hi, field, + usage, bit, max); + break; + case USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD: + return samsung_kbd_input_mapping(hdev, hi, field, + usage, bit, max); + case USB_DEVICE_ID_SAMSUNG_WIRELESS_GAMEPAD: + return samsung_gamepad_input_mapping(hdev, hi, field, + usage, bit, max); + case USB_DEVICE_ID_SAMSUNG_WIRELESS_ACTIONMOUSE: + return samsung_actionmouse_input_mapping(hdev, hi, field, + usage, bit, max); + case USB_DEVICE_ID_SAMSUNG_WIRELESS_UNIVERSAL_KBD: + case USB_DEVICE_ID_SAMSUNG_WIRELESS_MULTI_HOGP_KBD: + return samsung_universal_kbd_input_mapping(hdev, hi, field, + usage, bit, max); + } + + return 0; } static int samsung_probe(struct hid_device *hdev, - const struct hid_device_id *id) + const struct hid_device_id *id) { int ret; unsigned int cmask = HID_CONNECT_DEFAULT; @@ -406,14 +424,13 @@ static int samsung_probe(struct hid_device *hdev, ret = hid_parse(hdev); if (ret) { hid_err(hdev, "parse failed\n"); - goto err_free; + return ret; } if (hdev->product == USB_DEVICE_ID_SAMSUNG_IR_REMOTE) { - if (!hid_is_usb(hdev)) { - ret = -EINVAL; - goto err_free; - } + if (!hid_is_usb(hdev)) + return -EINVAL; + if (hdev->rsize == 184) { /* disable hidinput, force hiddev */ cmask = (cmask & ~HID_CONNECT_HIDINPUT) | @@ -424,22 +441,27 @@ static int samsung_probe(struct hid_device *hdev, ret = hid_hw_start(hdev, cmask); if (ret) { hid_err(hdev, "hw start failed\n"); - goto err_free; + return ret; } return 0; -err_free: - return ret; } static const struct hid_device_id samsung_devices[] = { - { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, - { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) }, - { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SAMSUNG_ELECTRONICS, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD) }, - { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SAMSUNG_ELECTRONICS, USB_DEVICE_ID_SAMSUNG_WIRELESS_GAMEPAD) }, - { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SAMSUNG_ELECTRONICS, USB_DEVICE_ID_SAMSUNG_WIRELESS_ACTIONMOUSE) }, - { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SAMSUNG_ELECTRONICS, USB_DEVICE_ID_SAMSUNG_WIRELESS_UNIVERSAL_KBD) }, - { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SAMSUNG_ELECTRONICS, USB_DEVICE_ID_SAMSUNG_WIRELESS_MULTI_HOGP_KBD) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, + USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, + USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SAMSUNG_ELECTRONICS, + USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD) }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SAMSUNG_ELECTRONICS, + USB_DEVICE_ID_SAMSUNG_WIRELESS_GAMEPAD) }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SAMSUNG_ELECTRONICS, + USB_DEVICE_ID_SAMSUNG_WIRELESS_ACTIONMOUSE) }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SAMSUNG_ELECTRONICS, + USB_DEVICE_ID_SAMSUNG_WIRELESS_UNIVERSAL_KBD) }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SAMSUNG_ELECTRONICS, + USB_DEVICE_ID_SAMSUNG_WIRELESS_MULTI_HOGP_KBD) }, { } }; MODULE_DEVICE_TABLE(hid, samsung_devices);