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: lizetao X-Patchwork-Id: 13790738 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-hwmon@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:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13790739 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 1DBC51D54DC; 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=nfzqLKWOYiCwInNwYZVpEMOWi8I9RdLp2qmufPDuibRqCfGQO76XMRkUuJpz3EnyDyUB1M8WkxtngOnTrIy2Nvctba7C87/fv7XXzBiU/BkPHzULZtTkZF6dXnh+qgOz0PYIGSIcn61K2X6tZI8zO0wdrTs2U1BOMsNg3urw3Ok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452857; c=relaxed/simple; bh=qSgrN06x9hDxRaTMql1PfTsxtnAVoc2I43BMIVKDs+E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MTgRiZnbbCSLeG+ldWAwj91bnpOio+Llzct+QRj/TOBXwsIbWB8BOmh35zJef3pt7pykymnx9X9UMaQ6Hm8Zvi8ejHkH6rC8H7/hJaLPP+mDgJUk1zloF3scw6MD+YIsarb/LRboD/GA+zbQ5tHqbzRrnbTHkwFeIZDNF075Ua4= 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.88.194]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4WzM7s6wDMz69WR; 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 865201400CA; Wed, 4 Sep 2024 20:27:31 +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 02/19] HID: cp2112: Use devm_hid_hw_start_and_open in cp2112_probe() Date: Wed, 4 Sep 2024 20:35:50 +0800 Message-ID: <20240904123607.3407364-3-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-hwmon@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 cp2112 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_hid_close and err_hid_stop lables. Signed-off-by: Li Zetao --- drivers/hid/hid-cp2112.c | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c index 20a0d1315d90..6d65c65f1b83 100644 --- a/drivers/hid/hid-cp2112.c +++ b/drivers/hid/hid-cp2112.c @@ -1215,22 +1215,14 @@ static int cp2112_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, "hw start failed\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, "hw open failed\n"); - goto err_hid_stop; - } ret = hid_hw_power(hdev, PM_HINT_FULLON); if (ret < 0) { hid_err(hdev, "power management error: %d\n", ret); - goto err_hid_close; + return ret; } ret = cp2112_hid_get(hdev, CP2112_GET_VERSION_INFO, buf, sizeof(buf), @@ -1334,10 +1326,6 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id) i2c_del_adapter(&dev->adap); err_power_normal: hid_hw_power(hdev, PM_HINT_NORMAL); -err_hid_close: - hid_hw_close(hdev); -err_hid_stop: - hid_hw_stop(hdev); return ret; } @@ -1354,14 +1342,6 @@ static void cp2112_remove(struct hid_device *hdev) } gpiochip_remove(&dev->gc); - /* i2c_del_adapter has finished removing all i2c devices from our - * adapter. Well behaved devices should no longer call our cp2112_xfer - * and should have waited for any pending calls to finish. It has also - * waited for device_unregister(&adap->dev) to complete. Therefore we - * can safely free our struct cp2112_device. - */ - hid_hw_close(hdev); - hid_hw_stop(hdev); } static int cp2112_raw_event(struct hid_device *hdev, struct hid_report *report, From patchwork Wed Sep 4 12:35:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13790737 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 B58E01CCB5B; Wed, 4 Sep 2024 12:27:34 +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=rq5W/Xfz9+z+KJNu4LeOMYwjGVa7lPoYAT99BNQRNxUfDMNeS0w+0XoUJGWwmr8sriEA10LpT7JDVyM6EaAHMyOb5WFTnV0WxAGaux2NnLwmBp6CLp8C5JCFBMxd0TotYzA4ppw1YuAywtgr8ZSbA62W6DD/vxJHh19mL05Xpqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452857; c=relaxed/simple; bh=ys4pqKPMR6lblOBaRRw2cpX5dr9ETzZE+fmugbR9tdo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nXUrxVdZQGKe9ElJEi3s6wmNV3rQPbgho2Wc5WfVAFUfv6l/I5lZrugaIFPBRn8uTewoKeAkThj8rSuxGn5V0hjkTk7YH74hPzfVz7RLd+AzyHz1pxxRFH01pvGpW898rtlgSx53Xa6xjM+Ka1vhwxaYGIV59apEMNuyv1Pup14= 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.163.17]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WzM7v0SmFz20nP6; Wed, 4 Sep 2024 20:22:35 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 340DB1A0188; Wed, 4 Sep 2024 20:27:32 +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:31 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next 03/19] HID: ft260: Use devm_hid_hw_start_and_open in ft260_probe() Date: Wed, 4 Sep 2024 20:35:51 +0800 Message-ID: <20240904123607.3407364-4-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-hwmon@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 ft260 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_hid_close, err_hid_stop and err_i2c_free lables, and directly return the error code when an error occurs. Signed-off-by: Li Zetao --- drivers/hid/hid-ft260.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index 333341e80b0e..272165ebf46c 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -976,23 +976,15 @@ static int ft260_probe(struct hid_device *hdev, const struct hid_device_id *id) return ret; } - ret = hid_hw_start(hdev, 0); - if (ret) { - hid_err(hdev, "failed to start HID HW\n"); + ret = devm_hid_hw_start_and_open(hdev, 0); + if (ret) return ret; - } - - ret = hid_hw_open(hdev); - if (ret) { - hid_err(hdev, "failed to open HID HW\n"); - goto err_hid_stop; - } ret = ft260_hid_feature_report_get(hdev, FT260_CHIP_VERSION, (u8 *)&version, sizeof(version)); if (ret < 0) { hid_err(hdev, "failed to retrieve chip version\n"); - goto err_hid_close; + return ret; } hid_info(hdev, "chip code: %02x%02x %02x%02x\n", @@ -1001,7 +993,7 @@ static int ft260_probe(struct hid_device *hdev, const struct hid_device_id *id) ret = ft260_is_interface_enabled(hdev); if (ret <= 0) - goto err_hid_close; + return ret; hid_info(hdev, "USB HID v%x.%02x Device [%s] on %s\n", hdev->version >> 8, hdev->version & 0xff, hdev->name, @@ -1028,24 +1020,17 @@ static int ft260_probe(struct hid_device *hdev, const struct hid_device_id *id) ret = i2c_add_adapter(&dev->adap); if (ret) { hid_err(hdev, "failed to add i2c adapter\n"); - goto err_hid_close; + return ret; } ret = sysfs_create_group(&hdev->dev.kobj, &ft260_attr_group); if (ret < 0) { hid_err(hdev, "failed to create sysfs attrs\n"); - goto err_i2c_free; + i2c_del_adapter(&dev->adap); + return ret; } return 0; - -err_i2c_free: - i2c_del_adapter(&dev->adap); -err_hid_close: - hid_hw_close(hdev); -err_hid_stop: - hid_hw_stop(hdev); - return ret; } static void ft260_remove(struct hid_device *hdev) @@ -1057,9 +1042,6 @@ static void ft260_remove(struct hid_device *hdev) sysfs_remove_group(&hdev->dev.kobj, &ft260_attr_group); i2c_del_adapter(&dev->adap); - - hid_hw_close(hdev); - hid_hw_stop(hdev); } static int ft260_raw_event(struct hid_device *hdev, struct hid_report *report, From patchwork Wed Sep 4 12:35:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13790741 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 A90841D88AF; Wed, 4 Sep 2024 12:27:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452857; cv=none; b=fPfaDbfpk/BH2qNeCDXo/h4zoZcc8t84o+UszOC9D/FCyonf46oWmDhfs4D6IghHBdJOh0GCOHVmL2yV57qelfgoRn/GCU4QkWUV0IaFbe+4/gflLeZ1N4N8pkqxpp1asMNGZThik16ipm/hbvDYo59Y82uO5g0mzfqIe4SCU+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452857; c=relaxed/simple; bh=xD37XwYy6cgbacO2bq/1Eht3gXuobF5FecaBHuh2t5Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HxTc60yTYFEwdYiSaI81mK4ZdBbdGoGR+alpgN6MLTwB+yiGOdkBsLSLuB9OG0j7GSsy0v24BXY867sxtiH6IKMfcsO0g47eP3BAaB3Lmryf6sUPn6dva69Ghg6gEnRfd0nGq3fIquRPXkCjga4ocUc7MWFaMpD1MW+bxU4C+ts= 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.187 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 szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WzMDt5dzXzyRNr; Wed, 4 Sep 2024 20:26:54 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id DDB311800D2; Wed, 4 Sep 2024 20:27:32 +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 04/19] HID: mcp2200: Use devm_hid_hw_start_and_open in mcp2200_probe() Date: Wed, 4 Sep 2024 20:35:52 +0800 Message-ID: <20240904123607.3407364-5-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-hwmon@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 mcp2200 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. So there is no need to close and stop hid when an error occurs. At the same time, since there is no need to do any operations in mcp2200_remove() now, so delete .remote operation. Signed-off-by: Li Zetao --- drivers/hid/hid-mcp2200.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/drivers/hid/hid-mcp2200.c b/drivers/hid/hid-mcp2200.c index bf57f7f6caa0..56d72fc5623d 100644 --- a/drivers/hid/hid-mcp2200.c +++ b/drivers/hid/hid-mcp2200.c @@ -329,22 +329,13 @@ static int mcp2200_probe(struct hid_device *hdev, const struct hid_device_id *id return ret; } - 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); @@ -356,20 +347,12 @@ static int mcp2200_probe(struct hid_device *hdev, const struct hid_device_id *id ret = devm_gpiochip_add_data(&hdev->dev, &mcp->gc, mcp); if (ret < 0) { hid_err(hdev, "Unable to register gpiochip\n"); - hid_hw_close(hdev); - hid_hw_stop(hdev); return ret; } return 0; } -static void mcp2200_remove(struct hid_device *hdev) -{ - hid_hw_close(hdev); - hid_hw_stop(hdev); -} - static const struct hid_device_id mcp2200_devices[] = { { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_MCP2200) }, { } @@ -380,7 +363,6 @@ static struct hid_driver mcp2200_driver = { .name = "mcp2200", .id_table = mcp2200_devices, .probe = mcp2200_probe, - .remove = mcp2200_remove, .raw_event = mcp2200_raw_event, }; 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: lizetao X-Patchwork-Id: 13790740 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-hwmon@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: lizetao X-Patchwork-Id: 13790744 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-hwmon@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: lizetao X-Patchwork-Id: 13790742 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-hwmon@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:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13790743 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 D84411D88AF; 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=1725452859; cv=none; b=MTGg8RqgNGwK1sZT+EFm9u7mVWI9bIR7G0Y2aYrXMhMdMX9I96jgQXNM74Jv6SvLCJ+fWjInY0z7iqGWVTEzChmYDVpVYzhK3KMLwP1YUBOxIi8iuUNRF4ZsvkBzhS3t9Qb5ngZkzUoGdQuxJtJgZRSdlvQpmVwVtQK7qTTatYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452859; c=relaxed/simple; bh=vQvPqAP0diQOLRiYXQiwLcyt/I7kkEFal1101rSZJoM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OnA3AZynhCLyGouqSN+1zUcwfNV0kOA6OkCc01VEps+L0dsBCwNT5vhdUZKNxk8YqTlyHuGDAGF6COmdFdKdZdlSoQ/Z2WHrm3Sd3XC6TSJXULvNKZOCVtgk4nQVo8C1VDTgCj1s+iHhxkbsxtKJcBQA5HYeiwPhYDb3ZDHU/iM= 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.194]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WzMCV540qzpSwV; Wed, 4 Sep 2024 20:25:42 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 711DD1400CA; Wed, 4 Sep 2024 20:27:35 +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:34 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next 08/19] HID: hid-picolcd: Use devm_hid_hw_start_and_open in picolcd_probe() Date: Wed, 4 Sep 2024 20:35:56 +0800 Message-ID: <20240904123607.3407364-9-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-hwmon@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 hid-picolcd 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_cleanup_hid_ll and err_cleanup_hid_hw lables. Signed-off-by: Li Zetao --- drivers/hid/hid-picolcd_core.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c index 297103be3381..973822d1b2db 100644 --- a/drivers/hid/hid-picolcd_core.c +++ b/drivers/hid/hid-picolcd_core.c @@ -551,23 +551,15 @@ static int picolcd_probe(struct hid_device *hdev, goto err_cleanup_data; } - error = hid_hw_start(hdev, 0); + error = devm_hid_hw_start_and_open(hdev, 0); if (error) { - hid_err(hdev, "hardware start failed\n"); + hid_err(hdev, "hardware start and open failed\n"); goto err_cleanup_data; } - error = hid_hw_open(hdev); - if (error) { - hid_err(hdev, "failed to open input interrupt pipe for key and IR events\n"); - goto err_cleanup_hid_hw; - } - error = device_create_file(&hdev->dev, &dev_attr_operation_mode_delay); - if (error) { - hid_err(hdev, "failed to create sysfs attributes\n"); - goto err_cleanup_hid_ll; - } + if (error) + goto err_cleanup_data; error = device_create_file(&hdev->dev, &dev_attr_operation_mode); if (error) { @@ -589,10 +581,6 @@ static int picolcd_probe(struct hid_device *hdev, device_remove_file(&hdev->dev, &dev_attr_operation_mode); err_cleanup_sysfs1: device_remove_file(&hdev->dev, &dev_attr_operation_mode_delay); -err_cleanup_hid_ll: - hid_hw_close(hdev); -err_cleanup_hid_hw: - hid_hw_stop(hdev); err_cleanup_data: kfree(data); return error; @@ -611,8 +599,6 @@ static void picolcd_remove(struct hid_device *hdev) picolcd_exit_devfs(data); device_remove_file(&hdev->dev, &dev_attr_operation_mode); device_remove_file(&hdev->dev, &dev_attr_operation_mode_delay); - hid_hw_close(hdev); - hid_hw_stop(hdev); /* Shortcut potential pending reply that will never arrive */ spin_lock_irqsave(&data->lock, flags); 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: lizetao X-Patchwork-Id: 13790746 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-hwmon@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:35:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13790745 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 D2D521D9339; Wed, 4 Sep 2024 12:27:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452860; cv=none; b=dvuLQliPpysjQlZnOhGBBWkkGMajB2c23HbffdKySs+dAfqDYYIQfDvS5dp1myVUCZmD4ptktQmTHU/w1V+hzMUJ84HPzB5jRyVsUzl7nHLFQa761C5Z+I2jjTC+LPPtty2VK1nRqZZ77MTAkisNcM8AQpVLLt+nfLEz+eXuxGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452860; c=relaxed/simple; bh=op25NKclmh5WszqVK31MArbkM2pkNrfc6LJ1tfFAAhE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QWqus4uvpnIdqC2Q+UyAqoRitkVS+4tLL/XnyqfKMXSubisswxRgGrNwNLvq3xT9yW5l+/deHfQTyBw1kuYyfQ1DJk7Ed8Qa/oAP2TRa0M/mcZ1eXlKtsfSgHPdqeH3MGLUK6AZ9BCf2hcozg8BmGzWFMqL22JjIr4nWMz7fFgk= 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.187 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.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WzMDb077lzyR5f; Wed, 4 Sep 2024 20:26:39 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id C0C461800FE; 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 10/19] HID: hid-steam: Use devm_hid_hw_start_and_open in steam_probe() Date: Wed, 4 Sep 2024 20:35:58 +0800 Message-ID: <20240904123607.3407364-11-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-hwmon@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 hid-steam 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_hw_close and err_hw_stop lables. Signed-off-by: Li Zetao --- drivers/hid/hid-steam.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c index bf8b633114be..d393762bf52f 100644 --- a/drivers/hid/hid-steam.c +++ b/drivers/hid/hid-steam.c @@ -1236,18 +1236,10 @@ static int steam_probe(struct hid_device *hdev, * With the real steam controller interface, do not connect hidraw. * Instead, create the client_hid and connect that. */ - ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_HIDRAW); + ret = devm_hid_hw_start_and_open(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_HIDRAW); if (ret) goto err_cancel_work; - ret = hid_hw_open(hdev); - if (ret) { - hid_err(hdev, - "%s:hid_hw_open\n", - __func__); - goto err_hw_stop; - } - if (steam->quirks & STEAM_QUIRK_WIRELESS) { hid_info(hdev, "Steam wireless receiver connected"); /* If using a wireless adaptor ask for connection status */ @@ -1261,7 +1253,7 @@ static int steam_probe(struct hid_device *hdev, hid_err(hdev, "%s:steam_register failed with error %d\n", __func__, ret); - goto err_hw_close; + goto err_cancel_work; } } @@ -1283,10 +1275,6 @@ static int steam_probe(struct hid_device *hdev, err_steam_unregister: if (steam->connected) steam_unregister(steam); -err_hw_close: - hid_hw_close(hdev); -err_hw_stop: - hid_hw_stop(hdev); err_cancel_work: cancel_work_sync(&steam->work_connect); cancel_delayed_work_sync(&steam->mode_switch); @@ -1312,8 +1300,6 @@ static void steam_remove(struct hid_device *hdev) if (steam->quirks & STEAM_QUIRK_WIRELESS) { hid_info(hdev, "Steam wireless receiver disconnected"); } - hid_hw_close(hdev); - hid_hw_stop(hdev); steam_unregister(steam); } From patchwork Wed Sep 4 12:35:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13790747 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 20FD91D934A; Wed, 4 Sep 2024 12:27:39 +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=1725452862; cv=none; b=FWNecOcLK4/OxpbSJPKMMjhl1mzmmp9F9xpklx+XVOpbwom4mrt1m50FN6jdMpTwBIKtpXVsxPEVOuERsBFfoh4ML90fwu20eUQjzuFYBRqPej3GRk4J1BeGKbtenbJ6L8ZhTa6qPpc5WL3uSnNMi0qQcZDscDZQMqnvELiCbw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452862; c=relaxed/simple; bh=Mt25IMtsKBHe3bcD5PB6r/GfTzzV6IPilXtjCw35K74=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mW2LJmyxPbIBp4NXSE63CMAX/YP2OGluo9rAXc+cK4YEd6cF5H++lvDue+y8tx4z5F4hgM4n6eRDP5lWwUQeiaWQHQBXK+oiym6IH2PPYlUSL5caEqwf7USe79pvr6KUHOfECW2U2qu1LLNoMzQdNPYvb24uRZ/LYbZ8jzTSbj4= 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.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WzM9j6CVBz1HJ9c; Wed, 4 Sep 2024 20:24:09 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 67EDA1402CC; Wed, 4 Sep 2024 20:27:37 +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:36 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next 11/19] HID: wiimote: Use devm_hid_hw_start_and_open in wiimote_hid_probe() Date: Wed, 4 Sep 2024 20:35:59 +0800 Message-ID: <20240904123607.3407364-12-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-hwmon@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 wiimote 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 Reviewed-by: David Rheinsberg --- drivers/hid/hid-wiimote-core.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/drivers/hid/hid-wiimote-core.c b/drivers/hid/hid-wiimote-core.c index 26167cfb696f..28cd9ccbb617 100644 --- a/drivers/hid/hid-wiimote-core.c +++ b/drivers/hid/hid-wiimote-core.c @@ -1780,8 +1780,6 @@ static void wiimote_destroy(struct wiimote_data *wdata) wiimote_ext_unload(wdata); wiimote_modules_unload(wdata); cancel_work_sync(&wdata->queue.worker); - hid_hw_close(wdata->hdev); - hid_hw_stop(wdata->hdev); kfree(wdata); } @@ -1806,22 +1804,14 @@ static int wiimote_hid_probe(struct hid_device *hdev, goto err; } - 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; - } - - ret = hid_hw_open(hdev); - if (ret) { - hid_err(hdev, "cannot start hardware I/O\n"); - goto err_stop; - } ret = device_create_file(&hdev->dev, &dev_attr_extension); if (ret) { hid_err(hdev, "cannot create sysfs attribute\n"); - goto err_close; + goto err; } ret = device_create_file(&hdev->dev, &dev_attr_devtype); @@ -1847,10 +1837,6 @@ static int wiimote_hid_probe(struct hid_device *hdev, err_ext: device_remove_file(&wdata->hdev->dev, &dev_attr_extension); -err_close: - hid_hw_close(hdev); -err_stop: - hid_hw_stop(hdev); err: input_free_device(wdata->ir); input_free_device(wdata->accel); 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: lizetao X-Patchwork-Id: 13790748 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-hwmon@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:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13790749 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 DBBF71CCB5B; Wed, 4 Sep 2024 12:27:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452862; cv=none; b=EIwpPPuWJPRb1DaAvcccnPN4KVeeRpoIGpBcds6jb0atKhD8vFMY3ev/M35CgrD4EJpvBvNYqXXigpkKEIVP2YV1BZN81WwFUG4OnTykZfmroL6dRP6WQp6HmzuLPL2HuTkUpMiyZQXZiRc+ecwlX39sAQNYhlLIxXjAN7X8OiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452862; c=relaxed/simple; bh=fzDTCsOysi/HRBMpnsZlWv2bxJKyX9SBKLugh+3TEZI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Xh7+xog2IkiUg4STRIdMbMaEoDqyGhIWwEJLPyGD/WwzatpmyqBkShqa7tW+f2EkAIMvdgaBpmIgYVI2fUyiXAtMbmlb4oH6qKnf1r0P4tJkMiQU1aMpjBUba80ycaTVATZuCZcr2OhZi4c6riTj33wDqYnyL9SirY9UAHiPkyk= 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.187 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.194]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WzMF04drYzyRRV; Wed, 4 Sep 2024 20:27:00 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id BD0A81400CA; 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 13/19] hwmon: Use devm_hid_hw_start_and_open in rog_ryujin_probe() Date: Wed, 4 Sep 2024 20:36:01 +0800 Message-ID: <20240904123607.3407364-14-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-hwmon@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 rog_ryujin 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/asus_rog_ryujin.c | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/drivers/hwmon/asus_rog_ryujin.c b/drivers/hwmon/asus_rog_ryujin.c index f8b20346a995..da03ba3b4e0f 100644 --- a/drivers/hwmon/asus_rog_ryujin.c +++ b/drivers/hwmon/asus_rog_ryujin.c @@ -520,23 +520,13 @@ static int rog_ryujin_probe(struct hid_device *hdev, const struct hid_device_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; - } 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->status_report_request_mutex); mutex_init(&priv->buffer_lock); @@ -553,16 +543,10 @@ static int rog_ryujin_probe(struct hid_device *hdev, const struct hid_device_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; } return 0; - -fail_and_close: - hid_hw_close(hdev); -fail_and_stop: - hid_hw_stop(hdev); - return ret; } static void rog_ryujin_remove(struct hid_device *hdev) @@ -570,9 +554,6 @@ static void rog_ryujin_remove(struct hid_device *hdev) struct rog_ryujin_data *priv = hid_get_drvdata(hdev); hwmon_device_unregister(priv->hwmon_dev); - - hid_hw_close(hdev); - hid_hw_stop(hdev); } static const struct hid_device_id rog_ryujin_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: lizetao X-Patchwork-Id: 13790750 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-hwmon@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: lizetao X-Patchwork-Id: 13790752 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-hwmon@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 Reviewed-by: Wilken Gottwalt --- 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:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13790751 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 78D8E1D88C6; Wed, 4 Sep 2024 12:27:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452864; cv=none; b=kYndxFZla5XFUl/ttA5nVjPIz3DD1bHYPmIyLrD0wluRpT62IIV8agP3iGcwHB6VTfzokZBKzTR52dgGG8f4+rB4cpcCUMTIiuDNG7zbLDvUSKbiN2ptDLFBLCGQf0cSmCNNPHnO93Z6Mn7Ha0HSpDsb4EQCFVSbk4Vsj+yMj2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452864; c=relaxed/simple; bh=BzYsafMvQvgq6kvA8ZtacSNyK5Ltj8z8IUKH0vkTVqs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uFY/lpZ5e8kqDTBNv01o7Ic8O2laSBzqawFTa6aRIMUSw5s5kMa7P+IeLjiTYOTANGeciX/u7DNtjJLXtnUPlakUdyfMIrVrYeKgiOI1pigzcB65RZoaE7c0mqp8Xz1OKUP11MfETHg0yAZuUDPjrQXydIAGFlhC5XWDUItzXGQ= 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.187 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.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WzMDg06dWzyR5c; Wed, 4 Sep 2024 20:26:43 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id C03891800FE; 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 16/19] hwmon: (gigabyte_waterforce) Use devm_hid_hw_start_and_open in waterforce_probe() Date: Wed, 4 Sep 2024 20:36:04 +0800 Message-ID: <20240904123607.3407364-17-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-hwmon@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 waterforce 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/gigabyte_waterforce.c | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/drivers/hwmon/gigabyte_waterforce.c b/drivers/hwmon/gigabyte_waterforce.c index 8129d7b3ceaf..9052d1c3d5aa 100644 --- a/drivers/hwmon/gigabyte_waterforce.c +++ b/drivers/hwmon/gigabyte_waterforce.c @@ -337,23 +337,13 @@ static int waterforce_probe(struct hid_device *hdev, const struct hid_device_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; - } 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->status_report_request_mutex); mutex_init(&priv->buffer_lock); @@ -371,18 +361,12 @@ static int waterforce_probe(struct hid_device *hdev, const struct hid_device_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; } waterforce_debugfs_init(priv); return 0; - -fail_and_close: - hid_hw_close(hdev); -fail_and_stop: - hid_hw_stop(hdev); - return ret; } static void waterforce_remove(struct hid_device *hdev) @@ -391,9 +375,6 @@ static void waterforce_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 waterforce_table[] = { From patchwork Wed Sep 4 12:36:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13790753 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 38B9C1CCB5B; Wed, 4 Sep 2024 12:27:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452864; cv=none; b=tlInGZ7uqyLCyFleeyu7efA0HIYL9BOh5x08lpE+ym+M4nkTTKApw1aPUSDPpx4qwFt+HHveKUW8pm+Q4kiJAeBbU6x9q+YNAqQM+VkaSyqE0VKbhjy0eHfluAA3G5LBrFmEj4YvmrwycxRDgj6jfZX5+m51lSwe+NFzJdhiZ10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452864; c=relaxed/simple; bh=7eFiUlPXZy+z3uiHQspc8FCh+JdGKLbcFBD2h2oakkg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ihNKTo8lb6EEE7bhYHxq53HAqilW/5n36VK1bc0Nd7B68McVjSAoZOyAyoTisz8+0wOTZ5BF/COLJndszOxiy5cd8Y0MDi3ThrsZODk7gD++hD8gKG1vFZ+KTvBSv0vRUoo3UGYUBQ4GK+5aU1j10i/GbdybNhkIefKmGfX97Og= 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.187 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.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WzMDg4lZCzyR5g; Wed, 4 Sep 2024 20:26:43 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 6BB5C1800FE; Wed, 4 Sep 2024 20:27:41 +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:40 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next 17/19] hwmon: (nzxt-kraken2) Use devm_hid_hw_start_and_open in kraken2_probe() Date: Wed, 4 Sep 2024 20:36:05 +0800 Message-ID: <20240904123607.3407364-18-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-hwmon@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-kraken2.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/drivers/hwmon/nzxt-kraken2.c b/drivers/hwmon/nzxt-kraken2.c index 7caf387eb144..aaaf857b42ed 100644 --- a/drivers/hwmon/nzxt-kraken2.c +++ b/drivers/hwmon/nzxt-kraken2.c @@ -158,17 +158,9 @@ static int kraken2_probe(struct hid_device *hdev, /* * 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; - } priv->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, "kraken2", priv, &kraken2_chip_info, @@ -176,16 +168,10 @@ static int kraken2_probe(struct hid_device *hdev, 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; } return 0; - -fail_and_close: - hid_hw_close(hdev); -fail_and_stop: - hid_hw_stop(hdev); - return ret; } static void kraken2_remove(struct hid_device *hdev) @@ -193,9 +179,6 @@ static void kraken2_remove(struct hid_device *hdev) struct kraken2_priv_data *priv = hid_get_drvdata(hdev); hwmon_device_unregister(priv->hwmon_dev); - - hid_hw_close(hdev); - hid_hw_stop(hdev); } static const struct hid_device_id kraken2_table[] = { 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: lizetao X-Patchwork-Id: 13790754 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-hwmon@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[] = { From patchwork Wed Sep 4 12:36:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13790755 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 93A831D9D99; Wed, 4 Sep 2024 12:27:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452866; cv=none; b=q6zAszjv7AG49GGrv2ld4pUTnDeJxgSGXuLKD3b+8Sr+0Gd8+Hp4ZTV8Fmwrr/uQNNccg9+lT797uai+DP1fllrxQ0bhYhB3HW0cK6TXpqryL2HRnsGLiOxgdx/T1iTd3rUCB1ybj93qqMo5oU4wBrbwK6rz3gGptLvOOFRP8SE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452866; c=relaxed/simple; bh=DTGh/1q2Odz1hSV0DApGpB4BaW6tTQi2v8++uFKMFq8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZSdfDc+EgkrFl0JocBKdV1fuJ+5pHJZ7AzS3II3qDIhZVRytMMXdVnhxefyBzwlA8ViFqYfCPYrSIysKGpYB3F8bpMsAqaPEcK0AjbV/HoSP2V2jjnItycvu9MCoJogJmsBGsvZkFpF9SIMES693jxohxMu27OeWgSPtXVxH5Ls= 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.187 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 szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WzMDh6j4CzyR68; Wed, 4 Sep 2024 20:26:44 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id AE795140137; 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 19/19] hwmon: (nzxt-smart2) Use devm_hid_hw_start_and_open in nzxt_smart2_hid_probe() Date: Wed, 4 Sep 2024 20:36:07 +0800 Message-ID: <20240904123607.3407364-20-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-hwmon@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-smart2 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 out_hw_stop lables, and directly return the error code when an error occurs. Signed-off-by: Li Zetao --- drivers/hwmon/nzxt-smart2.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/drivers/hwmon/nzxt-smart2.c b/drivers/hwmon/nzxt-smart2.c index df6fa72a6b59..b5721a42c0d3 100644 --- a/drivers/hwmon/nzxt-smart2.c +++ b/drivers/hwmon/nzxt-smart2.c @@ -750,14 +750,10 @@ static int nzxt_smart2_hid_probe(struct hid_device *hdev, 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; - hid_device_io_start(hdev); init_device(drvdata, UPDATE_INTERVAL_DEFAULT_MS); @@ -765,19 +761,10 @@ static int nzxt_smart2_hid_probe(struct hid_device *hdev, drvdata->hwmon = hwmon_device_register_with_info(&hdev->dev, "nzxtsmart2", drvdata, &nzxt_smart2_chip_info, NULL); - if (IS_ERR(drvdata->hwmon)) { - ret = PTR_ERR(drvdata->hwmon); - goto out_hw_close; - } + if (IS_ERR(drvdata->hwmon)) + return PTR_ERR(drvdata->hwmon); return 0; - -out_hw_close: - hid_hw_close(hdev); - -out_hw_stop: - hid_hw_stop(hdev); - return ret; } static void nzxt_smart2_hid_remove(struct hid_device *hdev) @@ -785,9 +772,6 @@ static void nzxt_smart2_hid_remove(struct hid_device *hdev) struct drvdata *drvdata = hid_get_drvdata(hdev); hwmon_device_unregister(drvdata->hwmon); - - hid_hw_close(hdev); - hid_hw_stop(hdev); } static const struct hid_device_id nzxt_smart2_hid_id_table[] = {