From patchwork Wed Sep 4 12:35:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 825421 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (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 349C11D7E23; Wed, 4 Sep 2024 12:27:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452857; cv=none; b=dO5aBH+++7HjlbXUaqvUMs4EKAypOLgpyh6SqXoa3+JyynP4lbrl6Uj1svEG3XYwqobUmaD/aYU9govf5M0Pxzc51ZQJRMUHh+O/4EC3VW1mGv0ittsMIUzInSYLWL1ff4NAwpVYoiYeto1LbgnLK5S1clSeIcaQ9n+XQMmnu+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452857; c=relaxed/simple; bh=CW5GEcVRAatZr5h8ZOzMq8dC3CRsJQ04GRAxe09uDyE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ntjAfCzcPqsLkLFJdDSb9N+b+tumHHmoEZxTdrx7onvQL1/98pmKij2aLOr26TwzconkcCXB2RaO44OY/8fhLXeyX7c7wEL91SUCvLETtXYOU0KIaXFwXwlKVS9hi3xy1Y33bA4inMwpATyFHy8qe/eAD5VC1ESb8dht8KotkPc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4WzM7s2LxGz69WG; Wed, 4 Sep 2024 20:22:33 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id DE09818005F; Wed, 4 Sep 2024 20:27:30 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Wed, 4 Sep 2024 20:27:30 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next 01/19] HID: core: Use devm_add_action_or_reset helper to manage hid resources Date: Wed, 4 Sep 2024 20:35:49 +0800 Message-ID: <20240904123607.3407364-2-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904123607.3407364-1-lizetao1@huawei.com> References: <20240904123607.3407364-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemd500012.china.huawei.com (7.221.188.25) By adding a custom action to the device, it can bind the hid resource to the hid_device life cycle. The framework automatically close and stop the hid resources before hid_device is released, and the users do not need to pay attention to the timing of hid resource release. Signed-off-by: Li Zetao --- drivers/hid/hid-core.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/hid.h | 2 ++ 2 files changed, 42 insertions(+) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 30de92d0bf0f..71143c0a4a02 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -2416,6 +2416,46 @@ void hid_hw_close(struct hid_device *hdev) } EXPORT_SYMBOL_GPL(hid_hw_close); +static void hid_hw_close_and_stop(void *data) +{ + struct hid_device *hdev = data; + + hid_hw_close(hdev); + hid_hw_stop(hdev); +} + +/** + * devm_hid_hw_start_and_open - manage hid resources through custom action + * + * @hdev: hid device + * @connect_mask: which outputs to connect, see HID_CONNECT_* + * + * Bind the hid resource to the hid_device life cycle and register + * an action to release the hid resource. The users do not need to + * pay attention to the release of hid. + */ + +int devm_hid_hw_start_and_open(struct hid_device *hdev, unsigned int connect_mask) +{ + int ret; + + ret = hid_hw_start(hdev, connect_mask); + if (ret) { + hid_err(hdev, "hw start failed with %d\n", ret); + return ret; + } + + ret = hid_hw_open(hdev); + if (ret) { + hid_err(hdev, "hw open failed with %d\n", ret); + hid_hw_stop(hdev); + return ret; + } + + return devm_add_action_or_reset(&hdev->dev, hid_hw_close_and_stop, hdev); +} +EXPORT_SYMBOL_GPL(devm_hid_hw_start_and_open); + /** * hid_hw_request - send report request to device * diff --git a/include/linux/hid.h b/include/linux/hid.h index 121d5b8bc867..0ce217aa5f62 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1125,6 +1125,8 @@ int __must_check hid_hw_start(struct hid_device *hdev, void hid_hw_stop(struct hid_device *hdev); int __must_check hid_hw_open(struct hid_device *hdev); void hid_hw_close(struct hid_device *hdev); +int __must_check devm_hid_hw_start_and_open(struct hid_device *hdev, + unsigned int connect_mask); void hid_hw_request(struct hid_device *hdev, struct hid_report *report, enum hid_class_request reqtype); int __hid_hw_raw_request(struct hid_device *hdev, From patchwork Wed Sep 4 12:35:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 825420 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 A9EB91D88BB; Wed, 4 Sep 2024 12:27:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452857; cv=none; b=jK6BK4oVST3Hi5pla8VDRIDhmQ0thJFqJfwEIoYf4vySl7T/Chwt/yd2O1PEDdLE6KQFILDMDAWAIr1ojC78je9AhVbjO46/3xYNVm9Y9pctixsA40yJRNPmZdOX1WUVmJM/o+SKp8fygN5I7yv6fulLQba3E/7UJymMmMmKSFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452857; c=relaxed/simple; bh=cD/NexygJxM+WqNv0qEX/1P52KZPmiT2jbO4E3malAk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dGs7U/HmyFoBLEx1ZPjUlWVynMZUaEHLPHS4FbeyF59YTAGedqBXFVRopuDg8AfsO88eTz1bmoCAmp0Ax50YADVkhwGys1KyQDPWeBwtzRyhgvLS20u+rhvh6DK7iI8wjjk1l/rdcxCC4pEh8JAG2mIMZlnA18zxAkjgSlaC6eY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WzMFF0pYsz2Dbhr; Wed, 4 Sep 2024 20:27:13 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 83A721402CC; Wed, 4 Sep 2024 20:27:33 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Wed, 4 Sep 2024 20:27:32 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next 05/19] HID: mcp2221: Use devm_hid_hw_start_and_open in mcp2221_probe() Date: Wed, 4 Sep 2024 20:35:53 +0800 Message-ID: <20240904123607.3407364-6-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904123607.3407364-1-lizetao1@huawei.com> References: <20240904123607.3407364-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the mcp2221 module use devm_add_action_or_reset() to manage device resource for HID unregistration, now that a universal interface has been provided, consider using a universal interface to replace it. Signed-off-by: Li Zetao --- drivers/hid/hid-mcp2221.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c index 0f93c22a479f..3b8269f7e923 100644 --- a/drivers/hid/hid-mcp2221.c +++ b/drivers/hid/hid-mcp2221.c @@ -932,15 +932,6 @@ static int mcp2221_raw_event(struct hid_device *hdev, return 1; } -/* Device resource managed function for HID unregistration */ -static void mcp2221_hid_unregister(void *ptr) -{ - struct hid_device *hdev = ptr; - - hid_hw_close(hdev); - hid_hw_stop(hdev); -} - /* This is needed to be sure hid_hw_stop() isn't called twice by the subsystem */ static void mcp2221_remove(struct hid_device *hdev) { @@ -1141,31 +1132,18 @@ static int mcp2221_probe(struct hid_device *hdev, * This driver uses the .raw_event callback and therefore does not need any * HID_CONNECT_xxx flags. */ - ret = hid_hw_start(hdev, 0); - if (ret) { - hid_err(hdev, "can't start hardware\n"); + ret = devm_hid_hw_start_and_open(hdev, 0); + if (ret) return ret; - } hid_info(hdev, "USB HID v%x.%02x Device [%s] on %s\n", hdev->version >> 8, hdev->version & 0xff, hdev->name, hdev->phys); - ret = hid_hw_open(hdev); - if (ret) { - hid_err(hdev, "can't open device\n"); - hid_hw_stop(hdev); - return ret; - } - mutex_init(&mcp->lock); init_completion(&mcp->wait_in_report); hid_set_drvdata(hdev, mcp); mcp->hdev = hdev; - ret = devm_add_action_or_reset(&hdev->dev, mcp2221_hid_unregister, hdev); - if (ret) - return ret; - hid_device_io_start(hdev); /* Set I2C bus clock diviser */ From patchwork Wed Sep 4 12:35:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 825418 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 4DA351CCB5B; Wed, 4 Sep 2024 12:27:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452860; cv=none; b=JCpRvqBBxwkjFOcSSRAZyaYVNf6uHMiNqOXa2PJjLchunoxlclPAUb3PUHrr1pkk+hZV2MLop+CyJCb3dI6haXNrc/c81+3HP4di8SVT3YQvgqvZg71uExsaDq6YNpeikB/9NkjLpU57Yr8DubHUKbzDduNPYjEQNM4Ua/Y9WAk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452860; c=relaxed/simple; bh=f9uFQrzNSg5VkANf3YwBhU0Mjk2DALfu+37rTc/529U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r9IYVPel5DeR5V1NUb/bLWgUL88JB9i3G10PbqtLJTEuUDNP64pkrmdMQg9uNvr9pAHTHDe93hNWbL0wZJ2VSRF3UUXLQKBIIvOD1ande/ZlXf+lSIOvewTI+eOXEvt8gPY/0GzexdUPSpsGbvsNTA+t7yckIjtxAdJA8JTUVaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WzMCB6Xz7zgYvn; Wed, 4 Sep 2024 20:25:26 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 2BA401800D2; Wed, 4 Sep 2024 20:27:34 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Wed, 4 Sep 2024 20:27:33 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next 06/19] HID: nintendo: Use devm_hid_hw_start_and_open in nintendo_hid_probe() Date: Wed, 4 Sep 2024 20:35:54 +0800 Message-ID: <20240904123607.3407364-7-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904123607.3407364-1-lizetao1@huawei.com> References: <20240904123607.3407364-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the nintendo module needs to maintain hid resources by itself. Consider using devm_hid_hw_start_and_open helper to ensure that hid resources are consistent with the device life cycle, and release hid resources before device is released. At the same time, it can avoid the goto-release encoding, drop the err_close and err_stop lables. Signed-off-by: Li Zetao --- drivers/hid/hid-nintendo.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c index 58cd0506e431..45ac4fd3c7ea 100644 --- a/drivers/hid/hid-nintendo.c +++ b/drivers/hid/hid-nintendo.c @@ -2673,31 +2673,23 @@ static int nintendo_hid_probe(struct hid_device *hdev, */ hdev->version |= 0x8000; - ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); - if (ret) { - hid_err(hdev, "HW start failed\n"); + ret = devm_hid_hw_start_and_open(hdev, HID_CONNECT_HIDRAW); + if (ret) goto err_wq; - } - - ret = hid_hw_open(hdev); - if (ret) { - hid_err(hdev, "cannot start hardware I/O\n"); - goto err_stop; - } hid_device_io_start(hdev); ret = joycon_init(hdev); if (ret) { hid_err(hdev, "Failed to initialize controller; ret=%d\n", ret); - goto err_close; + goto err_wq; } /* Initialize the leds */ ret = joycon_leds_create(ctlr); if (ret) { hid_err(hdev, "Failed to create leds; ret=%d\n", ret); - goto err_close; + goto err_wq; } /* Initialize the battery power supply */ @@ -2720,10 +2712,6 @@ static int nintendo_hid_probe(struct hid_device *hdev, err_ida: ida_free(&nintendo_player_id_allocator, ctlr->player_id); -err_close: - hid_hw_close(hdev); -err_stop: - hid_hw_stop(hdev); err_wq: destroy_workqueue(ctlr->rumble_queue); err: @@ -2745,9 +2733,6 @@ static void nintendo_hid_remove(struct hid_device *hdev) destroy_workqueue(ctlr->rumble_queue); ida_free(&nintendo_player_id_allocator, ctlr->player_id); - - hid_hw_close(hdev); - hid_hw_stop(hdev); } #ifdef CONFIG_PM From patchwork Wed Sep 4 12:35:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 825419 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 4DA991D88D7; Wed, 4 Sep 2024 12:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452858; cv=none; b=I0MjVT6tdl0uHRaYHxGZ0gj5+ZfueaH9QNYBwnwZ0oU2tK0yWNzGbFdIjdtn4V8V4hsTNDi9t9jZtf2inKU++vHVluGoVn19Q6mPCPtg+E3QZ/5uIWz/uTQbff01Bn1zbTj/MQSecyUTw4yJJp8E+XdcAv2AdCldiMwRxiQLOJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452858; c=relaxed/simple; bh=bnFn7uxvlpgxDIFy5TCBWsZxDa/wTSED4on3nue5zsA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BMXB9IgSj/MknJg7w3FM3mW5SFvh4KGQeBTNJPfycfSRV7h5YU1SbfQcAPMxLQdTxR9+BTdYn9jF78WK0ldb2bI9P7yQN3g6s6bgBmupbsQFk4qWGcUVWvZxa4RKWRdYQsWHlmw74hlJK7t5uj0UJFR2gF1zqvM0XHfPywixFUA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WzMCC3z31zgYvr; Wed, 4 Sep 2024 20:25:27 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id C9AB714011A; Wed, 4 Sep 2024 20:27:34 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Wed, 4 Sep 2024 20:27:33 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next 07/19] HID: shield: Use devm_hid_hw_start_and_open in shield_probe() Date: Wed, 4 Sep 2024 20:35:55 +0800 Message-ID: <20240904123607.3407364-8-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904123607.3407364-1-lizetao1@huawei.com> References: <20240904123607.3407364-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the shield module needs to maintain hid resources by itself. Consider using devm_hid_hw_start_and_open helper to ensure that hid resources are consistent with the device life cycle, and release hid resources before device is released. At the same time, it can avoid the goto-release encoding, drop the err_stop and err_ts_create lables, and directly return the error code when an error occurs. Signed-off-by: Li Zetao --- drivers/hid/hid-nvidia-shield.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/drivers/hid/hid-nvidia-shield.c b/drivers/hid/hid-nvidia-shield.c index ff9078ad1961..747996a21dd9 100644 --- a/drivers/hid/hid-nvidia-shield.c +++ b/drivers/hid/hid-nvidia-shield.c @@ -1070,27 +1070,15 @@ static int shield_probe(struct hid_device *hdev, const struct hid_device_id *id) ts = container_of(shield_dev, struct thunderstrike, base); - ret = hid_hw_start(hdev, HID_CONNECT_HIDINPUT); + ret = devm_hid_hw_start_and_open(hdev, HID_CONNECT_HIDINPUT); if (ret) { - hid_err(hdev, "Failed to start HID device\n"); - goto err_ts_create; - } - - ret = hid_hw_open(hdev); - if (ret) { - hid_err(hdev, "Failed to open HID device\n"); - goto err_stop; + thunderstrike_destroy(ts); + return ret; } thunderstrike_device_init_info(shield_dev); return ret; - -err_stop: - hid_hw_stop(hdev); -err_ts_create: - thunderstrike_destroy(ts); - return ret; } static void shield_remove(struct hid_device *hdev) @@ -1100,11 +1088,9 @@ static void shield_remove(struct hid_device *hdev) ts = container_of(dev, struct thunderstrike, base); - hid_hw_close(hdev); thunderstrike_destroy(ts); del_timer_sync(&ts->psy_stats_timer); cancel_work_sync(&ts->hostcmd_req_work); - hid_hw_stop(hdev); } static const struct hid_device_id shield_devices[] = { From patchwork Wed Sep 4 12:35:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 825417 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (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 93C7E1D88BA; Wed, 4 Sep 2024 12:27:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452861; cv=none; b=U7rT9+yUoos731R9HxcJ2vCjTO8QKlG1Nxo85r/P/qBAkTQaKL6shsMvZUB9pKKXunrXxunJJ9BKtQlFX5nv5LSyJ1y8mrA4LirEbQeRyNBGLu77AD6LM5hwG91e+2wlR/jIAVvPNCkGXwPgcr7EGC2jbk7+ogPQSJJknHJOzE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452861; c=relaxed/simple; bh=E3o8zEbsfPn2OZAlNXSQVO1TSutcP7KycrZf12Ki+pY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CfD9//xvdCivDEeOw7mHUXkHevqHnmkNVHLKBh1JT/wi3LCo7suAdGfQeyJYdhmWVIeNWl/8PRFgTupsGvyiy30LxHvGKdI9v6wzhAEommln0pA17khVN7GrsH67A43lpaTGbIqNI22RmmQHlY3O+ARGubhBFbH1zth2+w50Hjc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4WzMFH0mn7z1S9lF; Wed, 4 Sep 2024 20:27:15 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 1B939180044; Wed, 4 Sep 2024 20:27:36 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Wed, 4 Sep 2024 20:27:35 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next 09/19] HID: playstation: Use devm_hid_hw_start_and_open in ps_probe() Date: Wed, 4 Sep 2024 20:35:57 +0800 Message-ID: <20240904123607.3407364-10-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904123607.3407364-1-lizetao1@huawei.com> References: <20240904123607.3407364-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the playstation module needs to maintain hid resources by itself. Consider using devm_hid_hw_start_and_open helper to ensure that hid resources are consistent with the device life cycle, and release hid resources before device is released. At the same time, it can avoid the goto-release encoding, drop the err_close and err_stop lables, and directly return the error code when an error occurs. Signed-off-by: Li Zetao --- drivers/hid/hid-playstation.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index 0d90d7ee693c..6dddb9451a37 100644 --- a/drivers/hid/hid-playstation.c +++ b/drivers/hid/hid-playstation.c @@ -2704,41 +2704,25 @@ static int ps_probe(struct hid_device *hdev, const struct hid_device_id *id) return ret; } - ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); - if (ret) { - hid_err(hdev, "Failed to start HID device\n"); + ret = devm_hid_hw_start_and_open(hdev, HID_CONNECT_HIDRAW); + if (ret) return ret; - } - - ret = hid_hw_open(hdev); - if (ret) { - hid_err(hdev, "Failed to open HID device\n"); - goto err_stop; - } if (id->driver_data == PS_TYPE_PS4_DUALSHOCK4) { dev = dualshock4_create(hdev); if (IS_ERR(dev)) { hid_err(hdev, "Failed to create dualshock4.\n"); - ret = PTR_ERR(dev); - goto err_close; + return PTR_ERR(dev); } } else if (id->driver_data == PS_TYPE_PS5_DUALSENSE) { dev = dualsense_create(hdev); if (IS_ERR(dev)) { hid_err(hdev, "Failed to create dualsense.\n"); - ret = PTR_ERR(dev); - goto err_close; + return PTR_ERR(dev); } } return ret; - -err_close: - hid_hw_close(hdev); -err_stop: - hid_hw_stop(hdev); - return ret; } static void ps_remove(struct hid_device *hdev) @@ -2750,9 +2734,6 @@ static void ps_remove(struct hid_device *hdev) if (dev->remove) dev->remove(dev); - - hid_hw_close(hdev); - hid_hw_stop(hdev); } static const struct hid_device_id ps_devices[] = { From patchwork Wed Sep 4 12:36:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 825416 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 44A2C1D9351; Wed, 4 Sep 2024 12:27:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452862; cv=none; b=eWqRgJb25hSif24be0rQNFUXAAQJv8IH3ybL0COrbytvL/eAWEip4CJBilUwwBBL4L8Tv61al0Ks4n9cABpybLCCk3ObhIAp71JLTQC5e1ZpNF2rtreLuy3bOALIVkxDeGznTZ5ciudG3B2xPScE3+GRgRRVT4rjbMKCieFEx3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452862; c=relaxed/simple; bh=PclyRyj08simZQDFeLMPTpwSfkCzHHD9bpcGdEnMNwk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QZ0qrwxnBg25zEXm3P72qzifA0Oil3NQ3qTXDu+xuv+w9keSZt2oVlesAvczWBFGXJkrgjjtl3FyfGUfXGceNXZi9R1m2V3aOMI2nY++H42LOO4I4b86Ag35+Od1Np4jJVCGDkZ6jRkmJnoXAo8FdsgdhQYSP/UrpcoLFGJ+P6U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WzMCY2QBkzpVJc; Wed, 4 Sep 2024 20:25:45 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 166AE140137; Wed, 4 Sep 2024 20:27:38 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Wed, 4 Sep 2024 20:27:37 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next 12/19] hwmon: (aquacomputer_d5next) Use devm_hid_hw_start_and_open in aqc_probe() Date: Wed, 4 Sep 2024 20:36:00 +0800 Message-ID: <20240904123607.3407364-13-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904123607.3407364-1-lizetao1@huawei.com> References: <20240904123607.3407364-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the aquacomputer_d5next module needs to maintain hid resources by itself. Consider using devm_hid_hw_start_and_open helper to ensure that hid resources are consistent with the device life cycle, and release hid resources before device is released. At the same time, it can avoid the goto-release encoding, drop the fail_and_close and fail_and_stop lables, and directly return the error code when an error occurs. Signed-off-by: Li Zetao --- drivers/hwmon/aquacomputer_d5next.c | 39 +++++++---------------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c index 8e55cd2f46f5..9b66ff0fe6e1 100644 --- a/drivers/hwmon/aquacomputer_d5next.c +++ b/drivers/hwmon/aquacomputer_d5next.c @@ -1556,14 +1556,10 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) if (ret) return ret; - ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); + ret = devm_hid_hw_start_and_open(hdev, HID_CONNECT_HIDRAW); if (ret) return ret; - ret = hid_hw_open(hdev); - if (ret) - goto fail_and_stop; - switch (hdev->product) { case USB_PRODUCT_ID_AQUAERO: /* @@ -1577,10 +1573,8 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) * they present. The two other devices have the type of the second element in * their respective collections set to 1, while the real device has it set to 0. */ - if (hdev->collection[1].type != 0) { - ret = -ENODEV; - goto fail_and_close; - } + if (hdev->collection[1].type != 0) + return -ENODEV; priv->kind = aquaero; @@ -1740,10 +1734,8 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) * Choose the right Leakshield device, because * the other one acts as a keyboard */ - if (hdev->type != 2) { - ret = -ENODEV; - goto fail_and_close; - } + if (hdev->type != 2) + return -ENODEV; priv->kind = leakshield; @@ -1865,30 +1857,20 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->name = aqc_device_names[priv->kind]; priv->buffer = devm_kzalloc(&hdev->dev, priv->buffer_size, GFP_KERNEL); - if (!priv->buffer) { - ret = -ENOMEM; - goto fail_and_close; - } + if (!priv->buffer) + return -ENOMEM; mutex_init(&priv->mutex); priv->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, priv->name, priv, &aqc_chip_info, NULL); - if (IS_ERR(priv->hwmon_dev)) { - ret = PTR_ERR(priv->hwmon_dev); - goto fail_and_close; - } + if (IS_ERR(priv->hwmon_dev)) + return PTR_ERR(priv->hwmon_dev); aqc_debugfs_init(priv); return 0; - -fail_and_close: - hid_hw_close(hdev); -fail_and_stop: - hid_hw_stop(hdev); - return ret; } static void aqc_remove(struct hid_device *hdev) @@ -1897,9 +1879,6 @@ static void aqc_remove(struct hid_device *hdev) debugfs_remove_recursive(priv->debugfs); hwmon_device_unregister(priv->hwmon_dev); - - hid_hw_close(hdev); - hid_hw_stop(hdev); } static const struct hid_device_id aqc_table[] = { From patchwork Wed Sep 4 12:36:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 825415 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (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 89CBA1D935E; Wed, 4 Sep 2024 12:27:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452863; cv=none; b=U2vUKCCXiHVnpwRSF27bvaPCtKAxAp3wboq9hhYwCC+6jhYXojAFvlO5Xbdaan0e2Kg8sdDyRcMVPEPCU0UbdxDR1atEKbUZKlXWxtLs1Ik48yf6jiR0DuUdQVR5rg47FX8QoCaJRHNtKd8S34EV4tqHUpNXqWSsyR7OlOjXNQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452863; c=relaxed/simple; bh=+XXON5r0eL2EVr0bDvRcSzlm3ma5it2X+MF3ELFTqf0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XXd3s7zK5YlhO0lh2Dhxua3JhIJLNN/qlZdfGt11WxNZeZIDTVp7Xb+YPYBEa1KJAxd6s+OSTUxepcUyrSKBllPrzXP+TCDxt9qXtjyP0wYvMzwWKU6NE+lbwHJvFE3gDJy9IIknjvrxUrF+QwJEXbareG3TQKHuSb/xJVOL1i8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4WzMFL30ygz1S9lR; Wed, 4 Sep 2024 20:27:18 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 6876C18002B; Wed, 4 Sep 2024 20:27:39 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Wed, 4 Sep 2024 20:27:38 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next 14/19] hwmon: (corsair-cpro) Use devm_hid_hw_start_and_open in ccp_probe() Date: Wed, 4 Sep 2024 20:36:02 +0800 Message-ID: <20240904123607.3407364-15-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904123607.3407364-1-lizetao1@huawei.com> References: <20240904123607.3407364-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the corsair-cpro module needs to maintain hid resources by itself. Consider using devm_hid_hw_start_and_open helper to ensure that hid resources are consistent with the device life cycle, and release hid resources before device is released. At the same time, it can avoid the goto-release encoding, drop the out_hw_close and hid_hw_stop lables, and directly return the error code when an error occurs. Signed-off-by: Li Zetao --- drivers/hwmon/corsair-cpro.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/drivers/hwmon/corsair-cpro.c b/drivers/hwmon/corsair-cpro.c index e1a7f7aa7f80..7bba30840f32 100644 --- a/drivers/hwmon/corsair-cpro.c +++ b/drivers/hwmon/corsair-cpro.c @@ -601,14 +601,10 @@ static int ccp_probe(struct hid_device *hdev, const struct hid_device_id *id) if (ret) return ret; - ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); + ret = devm_hid_hw_start_and_open(hdev, HID_CONNECT_HIDRAW); if (ret) return ret; - ret = hid_hw_open(hdev); - if (ret) - goto out_hw_stop; - ccp->hdev = hdev; hid_set_drvdata(hdev, ccp); @@ -621,28 +617,20 @@ static int ccp_probe(struct hid_device *hdev, const struct hid_device_id *id) /* temp and fan connection status only updates when device is powered on */ ret = get_temp_cnct(ccp); if (ret) - goto out_hw_close; + return ret; ret = get_fan_cnct(ccp); if (ret) - goto out_hw_close; + return ret; ccp_debugfs_init(ccp); ccp->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, "corsaircpro", ccp, &ccp_chip_info, NULL); - if (IS_ERR(ccp->hwmon_dev)) { - ret = PTR_ERR(ccp->hwmon_dev); - goto out_hw_close; - } + if (IS_ERR(ccp->hwmon_dev)) + return PTR_ERR(ccp->hwmon_dev); return 0; - -out_hw_close: - hid_hw_close(hdev); -out_hw_stop: - hid_hw_stop(hdev); - return ret; } static void ccp_remove(struct hid_device *hdev) @@ -651,8 +639,6 @@ static void ccp_remove(struct hid_device *hdev) debugfs_remove_recursive(ccp->debugfs); hwmon_device_unregister(ccp->hwmon_dev); - hid_hw_close(hdev); - hid_hw_stop(hdev); } static const struct hid_device_id ccp_devices[] = { From patchwork Wed Sep 4 12:36:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 825414 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 919F21D9351; Wed, 4 Sep 2024 12:27:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452864; cv=none; b=Cjqu5kAEF0cXWlUP1xirQmRlpbQ9mHX3qbzunTPL6ZmPM7hTEmTxmN1FT9RdsIsQnTJxZcrA5jJxx4B0U+956EgYiUBZTtVEgkFym7Q8IxpE8Y27TQzomSx0HxxlPEI8k1sTkVM16IHbGG5to5yqXwL1SY9TAI2Pxx+W1yJfzSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452864; c=relaxed/simple; bh=rcFM3hyBVmuVjsEwZGYb6qfFNP1tPy4pOJkJ6qaQEzI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fSvEU2y9MbBux0ZBguz3T0sI51PZCMA8+juGIH3XuxuG68yywbdi1nDbSVac5zOhPT92cISm/R8D3rqMGEcv9gnBlHTr4tHTBH05s6sEc8F8vUygBnqPQO0qEA6hX3oHu6DIyQaHUMGb9vrpjmIlXwBFZmKeJXYC4pwV0/o1THA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WzMFM64n7z1j7yM; Wed, 4 Sep 2024 20:27:19 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 17FA01400D7; Wed, 4 Sep 2024 20:27:40 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Wed, 4 Sep 2024 20:27:39 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next 15/19] hwmon: (corsair-psu) Use devm_hid_hw_start_and_open in corsairpsu_probe() Date: Wed, 4 Sep 2024 20:36:03 +0800 Message-ID: <20240904123607.3407364-16-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904123607.3407364-1-lizetao1@huawei.com> References: <20240904123607.3407364-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the corsair-psu module needs to maintain hid resources by itself. Consider using devm_hid_hw_start_and_open helper to ensure that hid resources are consistent with the device life cycle, and release hid resources before device is released. At the same time, it can avoid the goto-release encoding, drop the fail_and_close and fail_and_stop lables, and directly return the error code when an error occurs. Signed-off-by: Li Zetao --- drivers/hwmon/corsair-psu.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/drivers/hwmon/corsair-psu.c b/drivers/hwmon/corsair-psu.c index f8f22b8a67cd..b574ec9cd00f 100644 --- a/drivers/hwmon/corsair-psu.c +++ b/drivers/hwmon/corsair-psu.c @@ -787,14 +787,10 @@ static int corsairpsu_probe(struct hid_device *hdev, const struct hid_device_id if (ret) return ret; - ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); + ret = devm_hid_hw_start_and_open(hdev, HID_CONNECT_HIDRAW); if (ret) return ret; - ret = hid_hw_open(hdev); - if (ret) - goto fail_and_stop; - priv->hdev = hdev; hid_set_drvdata(hdev, priv); mutex_init(&priv->lock); @@ -805,13 +801,13 @@ static int corsairpsu_probe(struct hid_device *hdev, const struct hid_device_id ret = corsairpsu_init(priv); if (ret < 0) { dev_err(&hdev->dev, "unable to initialize device (%d)\n", ret); - goto fail_and_stop; + return ret; } ret = corsairpsu_fwinfo(priv); if (ret < 0) { dev_err(&hdev->dev, "unable to query firmware (%d)\n", ret); - goto fail_and_stop; + return ret; } corsairpsu_get_criticals(priv); @@ -820,20 +816,12 @@ static int corsairpsu_probe(struct hid_device *hdev, const struct hid_device_id priv->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, "corsairpsu", priv, &corsairpsu_chip_info, NULL); - if (IS_ERR(priv->hwmon_dev)) { - ret = PTR_ERR(priv->hwmon_dev); - goto fail_and_close; - } + if (IS_ERR(priv->hwmon_dev)) + return PTR_ERR(priv->hwmon_dev); corsairpsu_debugfs_init(priv); return 0; - -fail_and_close: - hid_hw_close(hdev); -fail_and_stop: - hid_hw_stop(hdev); - return ret; } static void corsairpsu_remove(struct hid_device *hdev) @@ -842,8 +830,6 @@ static void corsairpsu_remove(struct hid_device *hdev) debugfs_remove_recursive(priv->debugfs); hwmon_device_unregister(priv->hwmon_dev); - hid_hw_close(hdev); - hid_hw_stop(hdev); } static int corsairpsu_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *data, From patchwork Wed Sep 4 12:36:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 825413 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (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 D8C3D1D935E; Wed, 4 Sep 2024 12:27:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452865; cv=none; b=kPFJvh9KeYgMfCBmqeUMPMIi4TbhfZjI+WqiITUoiDh3UlsHXyx1k7lGapnthtZ6pP2SVFtcO7blzcXV+2er7VWGfYTtX2qkKrvvKXqBvehW5sIwcNryFWfhLwser9VkUwNEIJXkUVbQLY6omNCRdPdLhMGPV8G+nb6faLbqve8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452865; c=relaxed/simple; bh=uw4j/zlyC5vrAadl/KXV1Qt0z1isEAELIAL+OodPpws=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LKxjJHiIrbDX6yeLraXuvJ9CJadG0kEd8xoANv3lB1y8pyoHLfykABCJeWm3o7QvxEt96bV8Q2m+Dxhe8xLicpyhZGI0kDnDn7SKIll3MfQBVYRVlM9vivL1RJ3vhWPYkLCJJ5w4HtNVoud8YTj6pokOJ6Y4fR+8cDoMt9Jxh8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4WzM843VH9z69WC; Wed, 4 Sep 2024 20:22:44 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 1193714011A; Wed, 4 Sep 2024 20:27:42 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Wed, 4 Sep 2024 20:27:41 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next 18/19] hwmon: (nzxt-kraken3) Use devm_hid_hw_start_and_open in kraken3_probe() Date: Wed, 4 Sep 2024 20:36:06 +0800 Message-ID: <20240904123607.3407364-19-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904123607.3407364-1-lizetao1@huawei.com> References: <20240904123607.3407364-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the nzxt-kraken2 module needs to maintain hid resources by itself. Consider using devm_hid_hw_start_and_open helper to ensure that hid resources are consistent with the device life cycle, and release hid resources before device is released. At the same time, it can avoid the goto-release encoding, drop the fail_and_close and fail_and_stop lables, and directly return the error code when an error occurs. Signed-off-by: Li Zetao --- drivers/hwmon/nzxt-kraken3.c | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/drivers/hwmon/nzxt-kraken3.c b/drivers/hwmon/nzxt-kraken3.c index 00f3ac90a290..71b8c21cfe1b 100644 --- a/drivers/hwmon/nzxt-kraken3.c +++ b/drivers/hwmon/nzxt-kraken3.c @@ -897,17 +897,9 @@ static int kraken3_probe(struct hid_device *hdev, const struct hid_device_id *id } /* Enable hidraw so existing user-space tools can continue to work */ - ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); - if (ret) { - hid_err(hdev, "hid hw start failed with %d\n", ret); + ret = devm_hid_hw_start_and_open(hdev, HID_CONNECT_HIDRAW); + if (ret) return ret; - } - - ret = hid_hw_open(hdev); - if (ret) { - hid_err(hdev, "hid hw open failed with %d\n", ret); - goto fail_and_stop; - } switch (hdev->product) { case USB_PRODUCT_ID_X53: @@ -928,15 +920,12 @@ static int kraken3_probe(struct hid_device *hdev, const struct hid_device_id *id device_name = "kraken2023elite"; break; default: - ret = -ENODEV; - goto fail_and_close; + return -ENODEV; } priv->buffer = devm_kzalloc(&hdev->dev, MAX_REPORT_LENGTH, GFP_KERNEL); - if (!priv->buffer) { - ret = -ENOMEM; - goto fail_and_close; - } + if (!priv->buffer) + return -ENOMEM; mutex_init(&priv->buffer_lock); mutex_init(&priv->z53_status_request_lock); @@ -948,7 +937,7 @@ static int kraken3_probe(struct hid_device *hdev, const struct hid_device_id *id ret = kraken3_init_device(hdev); if (ret < 0) { hid_err(hdev, "device init failed with %d\n", ret); - goto fail_and_close; + return ret; } ret = kraken3_get_fw_ver(hdev); @@ -960,18 +949,12 @@ static int kraken3_probe(struct hid_device *hdev, const struct hid_device_id *id if (IS_ERR(priv->hwmon_dev)) { ret = PTR_ERR(priv->hwmon_dev); hid_err(hdev, "hwmon registration failed with %d\n", ret); - goto fail_and_close; + return ret; } kraken3_debugfs_init(priv, device_name); return 0; - -fail_and_close: - hid_hw_close(hdev); -fail_and_stop: - hid_hw_stop(hdev); - return ret; } static void kraken3_remove(struct hid_device *hdev) @@ -980,9 +963,6 @@ static void kraken3_remove(struct hid_device *hdev) debugfs_remove_recursive(priv->debugfs); hwmon_device_unregister(priv->hwmon_dev); - - hid_hw_close(hdev); - hid_hw_stop(hdev); } static const struct hid_device_id kraken3_table[] = {