From patchwork Mon Sep 9 01:22:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795717 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 B849BBA42; Mon, 9 Sep 2024 01:14:23 +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=1725844467; cv=none; b=uYpVj4CUJJ4l7UC3+QD9Z4BmYwJaQwrRo366LAQt57Kr343ZbgCAdiNHiaP/vPY/+vIj97SeHPBpEGUAvePiLxbJV4KmPBer4WUqgmxwpOjH3absdueZz8sLTw0DGg6m3csoxtZayzd0umWNZWuwPAfSWVml54hyG8KiFzQFyv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844467; c=relaxed/simple; bh=wK0YNdrtg68ij9JLDEKdfQf95eHGfo+KduP/pbWdKlk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=L0hagKugiTtIH/zX3Wir+d5Z7m1AnLrjHCvp3lsSEm5GvBrMDWnNoOuUII4BZodqcu4HhAOi3AujJ2aQEYcLaRGmkazQOgYdsjhE9+BJbWbHlgs2FpIHlZJk92mlodOV4wxpA1SXJ6vDyLvhW1nw5zFUjXX4WYHGk6TlOyOFpfs= 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.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4X283x3LYyz2DbxK; Mon, 9 Sep 2024 09:13:49 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id B12F01A016C; Mon, 9 Sep 2024 09:14:15 +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; Mon, 9 Sep 2024 09:14:14 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 01/15] HID: core: Use devm_add_action_or_reset helper to manage hid resources Date: Mon, 9 Sep 2024 09:22:59 +0800 Message-ID: <20240909012313.500341-2-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) 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 --- v1 -> v2: Add function usage constraints in comments v1: https://lore.kernel.org/all/cyils23bh4xaiw7bydlpapz4ngqpya3c4kesifrdpnme2t4bib@6elk7u3wvhh2/ drivers/hid/hid-core.c | 44 ++++++++++++++++++++++++++++++++++++++++++ include/linux/hid.h | 2 ++ 2 files changed, 46 insertions(+) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 30de92d0bf0f..132c81639753 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -2416,6 +2416,50 @@ 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. + * + * Some usage constraints of this function: hid_device also needs to be + * allocated through the Devres API, such as devm_kzalloc; hid_hw_stop should + * be followed immediately by hid_hw_close in the remove operation. + */ + +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 Mon Sep 9 01:23:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795711 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 B846AB67F; Mon, 9 Sep 2024 01:14:23 +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=1725844466; cv=none; b=at6Vg9QG9JNK/OdlALL6A7oc6bk9sQ0jwR+A/X71coSwl7ILHN+aOJVqPXCk6AyaWnsMMC+n7+2WaX5F77aOPp00eHwRWqROE7z+eRavUEFgVzHeoOkykXQu5BmqtGtHKx3NFJeHWfyziRaaDKnOWdrBtnEAS+lHNlN1cAS9f3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844466; c=relaxed/simple; bh=Q0xBHys0QgDqAYhHqRXdhWYx9wVlAVaYECwYoVudiBM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GhBEAhibZ2uqGb3GizLkaudW1m4KdZUOstP7NYSBOlIixnnUZdNpSmm9cz0GV9n7utmwa6iG/VdwIIBZozjZWu+Nwp1ak8gCspBjkOGnX3TubiD5ymwYfvzlQuLbCV3ERsSiBQufWVOgca+7ScNE98Rr8X2/TlQlMP/nZ4q40Bg= 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.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4X283y0YQGz2Dbxm; Mon, 9 Sep 2024 09:13:50 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 509C71400DC; Mon, 9 Sep 2024 09:14:16 +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; Mon, 9 Sep 2024 09:14:15 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 02/15] HID: cp2112: Use devm_hid_hw_start_and_open in cp2112_probe() Date: Mon, 9 Sep 2024 09:23:00 +0800 Message-ID: <20240909012313.500341-3-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the cp2112 module needs to maintain hid resources by itself. Use 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 --- v1 -> v2: Adjust commit information v1: https://lore.kernel.org/all/20240904123607.3407364-3-lizetao1@huawei.com/ 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 Mon Sep 9 01:23:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795714 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 5B93CD53C; Mon, 9 Sep 2024 01:14:24 +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=1725844467; cv=none; b=qHx70+OMH/i9yLL5RPXAkZekS8pdVPXl1MckCmHn0X/vgEObjbBLwXKmgxWrltC6NaksTs3n2P0lvyM5MVeHgvvC+xgrIroi8aDx5cfHs5jlRoJR8/I3jKkUfsgtmRt9rmxtDzAY7i/P5D5oH7UnWX7YO3JNGSTwnr4DdGHNMyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844467; c=relaxed/simple; bh=7M/2yKo1rfbU6x1pgG+lP6625uQoKwCBnoBw5wnsFAQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cuxI09wFDRtMarNGr0qy8P3mHgmRCqTh1rMRUKk6MEp4QRdCY+TATG12dTUKVBJq+O48BzZMI5eCO4pkMrePp+P0b2F2NYvVTClXaftUBkHpOQ5CdrCJ83ABiNOqUHuBxXv391hOoJ8t9ft3VODW+xItrZcTuDu2GzOerqAEJqg= 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 4X28292TGdzpVCX; Mon, 9 Sep 2024 09:12:17 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id E8EB3180AE8; Mon, 9 Sep 2024 09:14:16 +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; Mon, 9 Sep 2024 09:14:16 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 03/15] HID: ft260: Use devm_hid_hw_start_and_open in ft260_probe() Date: Mon, 9 Sep 2024 09:23:01 +0800 Message-ID: <20240909012313.500341-4-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the ft260 module needs to maintain hid resources by itself. Use 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 --- v1 -> v2: Adjust commit information v1: https://lore.kernel.org/all/20240904123607.3407364-4-lizetao1@huawei.com/ 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 Mon Sep 9 01:23:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795718 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 1CE4728EF; Mon, 9 Sep 2024 01:14:25 +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=1725844467; cv=none; b=puUSkivL9kTcoCuKsPEizX+AQ480kw4Yeke/+sMuvsG4JxwHIDhpyn0+DMdbdGs2SaIe2ZpVA7zn2wh3fozoGxUgubakPY1Q61YL+/oBhEotE+iBDazMzgcjxRcpZbqgfmik3en+IHd9DkmPbfFEWh3MDQ7NKyVPF0l/18TkYS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844467; c=relaxed/simple; bh=BkQcviMIXgbXjNJfvW6RUri3oYz1lp61b2gghrCznQY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s9vt1+oCW2NkiMNN5xVwTFx6YmVxRKfyIvACcVGgKsLp8CSHnZe7dL4ICCtzIWVCKQ6IxulXm92NHp1sicaZRLAXqDKr6XQa1pKB780IgFRt/UG5Y40qD9+H+zB2zo44i/cjfhDXsK+AAGrakQhTstiI5aGDo6ZXFbp0d7XYCO4= 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.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4X283z3XsSz1j7mD; Mon, 9 Sep 2024 09:13:51 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 89AEE140337; Mon, 9 Sep 2024 09:14:17 +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; Mon, 9 Sep 2024 09:14:16 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 04/15] HID: mcp2200: Use devm_hid_hw_start_and_open in mcp2200_probe() Date: Mon, 9 Sep 2024 09:23:02 +0800 Message-ID: <20240909012313.500341-5-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the mcp2200 module needs to maintain hid resources by itself. Use 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 --- v1 -> v2: Adjust commit information v1: https://lore.kernel.org/all/20240904123607.3407364-5-lizetao1@huawei.com/ 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 Mon Sep 9 01:23:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795721 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 3F20F14267; Mon, 9 Sep 2024 01:14:26 +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=1725844469; cv=none; b=ohpwjnNs1eaNGbaYVWEsSVRG/oyYWvRyQjzM+DOKWNOX9gqGuuRIQnEf+LHEFq+E8SjFh4LEWb6spNLe5iVgLOM70tgRlHReXBcVbWyEgUiOArUicHHREGphPZG3poQCnKtjet12MPYLpuy0CvlYbqapqbPeYSVc2NTNSq24pjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844469; c=relaxed/simple; bh=ZxV7IU+t3xrOnhI7UELrdVwgRxKcp3ky69pUqWvXBqE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LSxMfzXBlUZHKKq0gFht6G5mmfcCI2l6fmjO5xbtzwtHymPz1Furo91EG0sNEJGlfcqSInZFd55IC0jb6qUzyOKKL2GMPSlhXBWmghzuFXTAKvIs/vb/Bd7seGYGhjXFkkx4YvmKjYZOKjVOKMu8YaIMFJtcU/QlCvEqCc5Xrd0= 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 4X284Q4SQMz69N3; Mon, 9 Sep 2024 09:14:14 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 2CA5B1400D1; Mon, 9 Sep 2024 09:14:18 +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; Mon, 9 Sep 2024 09:14:17 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 05/15] HID: mcp2221: Use devm_hid_hw_start_and_open in mcp2221_probe() Date: Mon, 9 Sep 2024 09:23:03 +0800 Message-ID: <20240909012313.500341-6-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) 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, use a universal interface to replace it. Signed-off-by: Li Zetao --- v1 -> v2: None v1: https://lore.kernel.org/all/20240904123607.3407364-6-lizetao1@huawei.com/ 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 Mon Sep 9 01:23:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795720 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 C56D811712; Mon, 9 Sep 2024 01:14:26 +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=1725844468; cv=none; b=N/g+v9Xpz1xOP5fEs8Shx5g+hakXtwrqlOL9802Vjt4lSIjaJ1wCTq2a0d2sz+dLx2nv89l2PgtxRQpjSN+89gAFmU2zTXqNpqOBZ6B6mGJ5u8BS4PnhDcAFCn3m4CokztEfApUq0u5OSkpBtNbXwfyW4aNZq67dL4KZMiiK0cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844468; c=relaxed/simple; bh=a2yNCQHSb4RsF8vhWd6Tml8oxseIm7aUqomMD6XfQDQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u0x3Rudc7bE2LxXQNbuWJu4VweeMdwc1SqJmA9NTscva3OESR33HdvCl1aCEWNm9EuyjevyHWysktAic/AZM1N10jpKNlNj//6IJvviE1Nx/P0q21ZdlvrkjkdjJi7wxY4NBtH3v6WdLJ984uJk+TKtNkEZmCz95RooFcphmG6A= 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.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4X283g58MRzyRf0; Mon, 9 Sep 2024 09:13:35 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id C9B2A1403D4; Mon, 9 Sep 2024 09:14:18 +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; Mon, 9 Sep 2024 09:14:18 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 06/15] HID: nintendo: Use devm_hid_hw_start_and_open in nintendo_hid_probe() Date: Mon, 9 Sep 2024 09:23:04 +0800 Message-ID: <20240909012313.500341-7-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the nintendo module needs to maintain hid resources by itself. Use 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 --- v1 -> v2: Adjust commit information v1: https://lore.kernel.org/all/20240904123607.3407364-7-lizetao1@huawei.com/ 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 Mon Sep 9 01:23:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795722 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 62C12175AE; Mon, 9 Sep 2024 01:14:27 +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=1725844469; cv=none; b=PTmpcHYszy2HjKcijrzZLruce+zU0EgPaTxfiuibQw9wZe1Kyq73w0+BgHyvKWtv+Kwxiz84dbSJpjvFjhOIg8eG66WH2yb8tGs5Yl70FB2GIubOF9Y7XaMjK4E77rSblD0R1RQnj+Z6vdmgzc2RTbqbFoMuWj2CbRM7+UMy280= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844469; c=relaxed/simple; bh=JFLIjC1PPR9Va59OYNU1SbHckYdIYOeRnHqM2PeJd6s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JePwuGRLDpKa9IBYqhF47cDUOR4Bo6hLliLuo2v7ucLZ3vJNRzE0gQxbdkTuJIu3ll2m7Oex9+XE4bqP4TO9GcwEqVU4nlXL2YmdlLTNXQLu5f2oSpKwOD5LX+kJeLlQ1fPaWZywX8qxX3f7D4B4abXCbKcH1PhleaYg3AZegME= 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.163]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4X28412V4Bz1j8CY; Mon, 9 Sep 2024 09:13:53 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 64FF8180041; Mon, 9 Sep 2024 09:14:19 +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; Mon, 9 Sep 2024 09:14:18 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 07/15] HID: playstation: Use devm_hid_hw_start_and_open in ps_probe() Date: Mon, 9 Sep 2024 09:23:05 +0800 Message-ID: <20240909012313.500341-8-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the playstation module needs to maintain hid resources by itself. Use 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 --- v1 -> v2: Adjust commit information v1: https://lore.kernel.org/all/20240904123607.3407364-10-lizetao1@huawei.com/ 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 Mon Sep 9 01:23:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795725 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (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 2C0D61C693; Mon, 9 Sep 2024 01:14:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844471; cv=none; b=YFgiCh1xB42ucQwTkzxNRbR/VNcs4LVwoPZC28XQGVMwRgwyWzyUgw3cx7KkRnajSxfavF45YeZl86qO8WBdPT4AOi0+IIDN9VcHFucHH7C49MVyK5GMdLJrgvZLelIEDpvAZBaxtzHL9tavjPQE/k630jUIte89TSnUtcMYTL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844471; c=relaxed/simple; bh=zKX/EfcsEKb1OAT3Isg8pJMNEnZ2ZUELN4axIB85uks=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UYs2OrYN/U7CiHKhGzMFldRNKvDzXlqj11pdjpVOPNkB6Gr460+XR764OMybZTo4x86WW2jnDfICgxfaSX76XbZdEzS172733/v/LRTquSnVSSqFAA1rQVLZfd53P6oIkcZwzq5ZgDmNswykoAr4dZDuSyi92WPRdH8NoRz6ngg= 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.255 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 szxga08-in.huawei.com (SkyGuard) with ESMTP id 4X283J4H6Dz1BNkw; Mon, 9 Sep 2024 09:13:16 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 0B68C180087; Mon, 9 Sep 2024 09:14:20 +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; Mon, 9 Sep 2024 09:14:19 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 08/15] hwmon: (aquacomputer_d5next) Use devm_hid_hw_start_and_open in aqc_probe() Date: Mon, 9 Sep 2024 09:23:06 +0800 Message-ID: <20240909012313.500341-9-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the aquacomputer_d5next module needs to maintain hid resources by itself. Use 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 Acked-by: Guenter Roeck Reviewed-by: Aleksa Savic --- v1 -> v2: Adjust commit information v1: https://lore.kernel.org/all/20240904123607.3407364-13-lizetao1@huawei.com/ 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 Mon Sep 9 01:23:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795724 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 69F5628EF; Mon, 9 Sep 2024 01:14:28 +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=1725844470; cv=none; b=b1w6MgkWvH4FCgV/r8Fqi6kDeDHXrAG3Qdl2qhKFwC5TM0ikWUIFdXjFIXTtWlAXVoeZRUSOcjtGO23zcPaPSV/2XEgy/HJqgG6IdWQKmHVUAEgqMR14SwIYb2EJ0SWkHcxJwE+Fz1jNlJ+Y8ksAgngU+CLdCjlBq1tdKPAMR/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844470; c=relaxed/simple; bh=n/G9/HCtpxKVqJWE2xfY4dF56kXGKgNNGxG7Jq+LkWA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OOn/X4sTaFo4vzCNmRJ1blWebe7OUpsAhpyJx7cuQv00HixP1h5u6AMVYaAaQzQCx+qwcnXsBxhf3eR5dYteMHt2721yh4T8HoqrxKEthc3R4nIzxXFxRhU4bp2awsp8cafmoSGjBOXyuDb/60oFSw95rczsSQlzBXCJRg5Leno= 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 4X282F0CsRzpVVW; Mon, 9 Sep 2024 09:12:21 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id A0B2914037D; Mon, 9 Sep 2024 09:14:20 +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; Mon, 9 Sep 2024 09:14:19 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 09/15] hwmon: Use devm_hid_hw_start_and_open in rog_ryujin_probe() Date: Mon, 9 Sep 2024 09:23:07 +0800 Message-ID: <20240909012313.500341-10-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the rog_ryujin module needs to maintain hid resources by itself. Use 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. Further optimization, use devm_hwmon_device_register_with_info to replace hwmon_device_register_with_info, the remote operation can be completely deleted, and the rog_ryujin_data structure no longer needs to hold hwmon device. Signed-off-by: Li Zetao Acked-by: Guenter Roeck Reviewed-by: Aleksa Savic --- v1 -> v2: 1) Further optimize using devm_hwmon_device_register_with_info and remove the .remove operation 2) Adjust commit information v1: https://lore.kernel.org/all/20240904123607.3407364-14-lizetao1@huawei.com/ drivers/hwmon/asus_rog_ryujin.c | 47 +++++---------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/drivers/hwmon/asus_rog_ryujin.c b/drivers/hwmon/asus_rog_ryujin.c index f8b20346a995..ef0d9b72a824 100644 --- a/drivers/hwmon/asus_rog_ryujin.c +++ b/drivers/hwmon/asus_rog_ryujin.c @@ -80,7 +80,6 @@ static const char *const rog_ryujin_speed_label[] = { struct rog_ryujin_data { struct hid_device *hdev; - struct device *hwmon_dev; /* For locking access to buffer */ struct mutex buffer_lock; /* For queueing multiple readers */ @@ -497,6 +496,7 @@ static int rog_ryujin_raw_event(struct hid_device *hdev, struct hid_report *repo static int rog_ryujin_probe(struct hid_device *hdev, const struct hid_device_id *id) { struct rog_ryujin_data *priv; + struct device *hwmon_dev; int ret; priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL); @@ -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); @@ -548,31 +538,9 @@ static int rog_ryujin_probe(struct hid_device *hdev, const struct hid_device_id init_completion(&priv->cooler_duty_set); init_completion(&priv->controller_duty_set); - priv->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, "rog_ryujin", + hwmon_dev = devm_hwmon_device_register_with_info(&hdev->dev, "rog_ryujin", priv, &rog_ryujin_chip_info, NULL); - 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 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) -{ - struct rog_ryujin_data *priv = hid_get_drvdata(hdev); - - hwmon_device_unregister(priv->hwmon_dev); - - hid_hw_close(hdev); - hid_hw_stop(hdev); + return PTR_ERR_OR_ZERO(hwmon_dev); } static const struct hid_device_id rog_ryujin_table[] = { @@ -586,7 +554,6 @@ static struct hid_driver rog_ryujin_driver = { .name = "rog_ryujin", .id_table = rog_ryujin_table, .probe = rog_ryujin_probe, - .remove = rog_ryujin_remove, .raw_event = rog_ryujin_raw_event, }; From patchwork Mon Sep 9 01:23:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795723 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 78B37BA42; Mon, 9 Sep 2024 01:14:28 +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=1725844470; cv=none; b=odq46zViiA021IlKx9bxBzWNlkSdavfzyjJEx1IqO0WWMWYG0jcgHU4XgYZYK/EUjOsQxjB48vY7WLOULfbixmhg2D+1f0k7q221JopWAeCF/DGC8wfJKm8yomRnmD68n9BQidgNHELdDpx1iGIdUPyafUwsekcAU6/s9QyTWFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844470; c=relaxed/simple; bh=/BSWCvgetkZdKoXmqL7il2Mnc8I2MOIUMx8gyU4OiwI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P7Qa+1Sq8HUYbIvlxEheEIEerRI4rCKLO+1e6f+BDa6IEAMnDc9hG6B+VPLbDBHOOJMLAmKZyY/2HDIgsxK7TkiEqFpDHJxmY7xc+TgF/7bMZFwZShQ8cSY6xO+AIqrV7DH1YCpM7TdbRUa320JmfgcIDIPhlHhNz2L8uJdSKrQ= 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 4X280S5PFQz1HJ7d; Mon, 9 Sep 2024 09:10:48 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 461171400DC; Mon, 9 Sep 2024 09:14:21 +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; Mon, 9 Sep 2024 09:14:20 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 10/15] hwmon: (corsair-cpro) Use devm_hid_hw_start_and_open in ccp_probe() Date: Mon, 9 Sep 2024 09:23:08 +0800 Message-ID: <20240909012313.500341-11-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the corsair-cpro module needs to maintain hid resources by itself. Use 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 Acked-by: Guenter Roeck Acked-by: Marius Zachmann --- v1 -> v2: Adjust commit information v1: https://lore.kernel.org/all/20240904123607.3407364-15-lizetao1@huawei.com/ 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 Mon Sep 9 01:23:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795716 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 67587101C8; Mon, 9 Sep 2024 01:14:24 +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=1725844467; cv=none; b=FA+DQmZfOEV7rp1mt3qNAFz7cp8ME67DdJZw3mGwDY2hmvJ2EU75rU4lsZhmGyvm+yTZkUYk06ezKh19fcNjeyVD2O9JQPJ3rcAIp6m0hP/wvKGBROd+7xca5RXK/ZKzuff6FnLsN91xdZHAKLMk3Pyjtv55ZajLkKxBY0q6x4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844467; c=relaxed/simple; bh=VKrl2UuLBLhvdHzlCmTF2H2WoON1mxOZYA6T2UqSwCI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kUyFrJDtnIM37WhL8e3l3Jc4Th5EXPSC5gRMw8VO90rx+tsWXiRrA+9lagtbLScE5gXp1VufplX53RvnAaDPkNf0Tnq31r47S0ckuQwEvhUMujxAo0q6Uv7PUR4JXkXbk71D8dsWmNy5lgWVKrvjouV8pveIbPmyxK19tpJSUj4= 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.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4X284V4RWdz20nfl; Mon, 9 Sep 2024 09:14:18 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id EBF5B1400DC; Mon, 9 Sep 2024 09:14:21 +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; Mon, 9 Sep 2024 09:14:21 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 11/15] hwmon: (corsair-psu) Use devm_hid_hw_start_and_open in corsairpsu_probe() Date: Mon, 9 Sep 2024 09:23:09 +0800 Message-ID: <20240909012313.500341-12-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the corsair-psu module needs to maintain hid resources by itself. Use 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. Reviewed-by: Wilken Gottwalt Signed-off-by: Li Zetao Acked-by: Guenter Roeck --- v1 -> v2: Adjust commit information v1: https://lore.kernel.org/all/20240904123607.3407364-15-lizetao1@huawei.com/ 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 Mon Sep 9 01:23:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795713 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 E66B1101F2; Mon, 9 Sep 2024 01:14:24 +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=1725844466; cv=none; b=Ug0X6Q2WCuvZQjaWL7A3ZgUPYJpXOkJ74KWBq+6ZZTqoHw947CwiWz/jdcUJ5tOMkqIJyLa9almR/ZeQLfCTmQA7QNheHEGG6npFHprSWgOqlLvv+oma87LEoB33hSIoLBb9esIzQNGClbViZ1MdGzXTSvTBxfsxdAi0jiiZUYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844466; c=relaxed/simple; bh=IQlexit9L51Ox188oD4PyFOIQfKNEy9faMQJhDzrkMk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JKg1h9057fkFXWhqnTs4Dux65y3AMs+VpgfqnKleV2p2qxngLejm8cLKhoyPHikbCbOqhPN7LNumsrtGKtdd/QX+n8iIlmRhs0mc8y0+zrZenhRyrkaphfJD6mzHYd9mJEN8Cxhy96veNvWy95nivzWNfEHtZCjyQJHhWxBbQEk= 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.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4X284427dwz2Dbxj; Mon, 9 Sep 2024 09:13:56 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 87E22180041; Mon, 9 Sep 2024 09:14:22 +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; Mon, 9 Sep 2024 09:14:21 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 12/15] hwmon: (gigabyte_waterforce) Use devm_hid_hw_start_and_open in waterforce_probe() Date: Mon, 9 Sep 2024 09:23:10 +0800 Message-ID: <20240909012313.500341-13-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the waterforce module needs to maintain hid resources by itself. Use 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 Acked-by: Guenter Roeck Reviewed-by: Aleksa Savic --- v1 -> v2: Adjust commit information v1: https://lore.kernel.org/all/20240904123607.3407364-16-lizetao1@huawei.com/ 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 Mon Sep 9 01:23:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795715 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 67C1C101F7; Mon, 9 Sep 2024 01:14:25 +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=1725844467; cv=none; b=CPUNy5dQO6FECwSwvpFXxmBZ4sJoibRJeshGpV5vLxzYfn+VO09TZTenaMkDhzrn3XxDiP0j/Sgen655J4bGabAMeflPdVaFkQEUyYFihvEsq7O+M6OL8n/9MRg84FlaGQSWmRRiEHapOj+Nte8TwELU+sx6P2978DezLymUzh4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844467; c=relaxed/simple; bh=mIKEzNdss1fD9JD100CdqdH5EmO882ndqIfOhY/zxcM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=S5ZXGWv2OwPrRt73J5By14oYWnlDqBShpzOedijdMGUMw/WEYBbQZZfOKqRyERwmskAFI1EIK7kc96nR7P7N+PSPO8vkC9hRD/vbWM1NT0oqHeGDzIXNuvbbkDXnOLAxqmMVIyWIxK0J3OvB+efrBbvEWarVwB0lMGlzcPi4cAY= 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.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4X284W5wKjz20nMJ; Mon, 9 Sep 2024 09:14:19 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 2A077140337; Mon, 9 Sep 2024 09:14:23 +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; Mon, 9 Sep 2024 09:14:22 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 13/15] hwmon: (nzxt-kraken2) Use devm_hid_hw_start_and_open in kraken2_probe() Date: Mon, 9 Sep 2024 09:23:11 +0800 Message-ID: <20240909012313.500341-14-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the nzxt-kraken2 module needs to maintain hid resources by itself. Use 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. Further optimization, use devm_hwmon_device_register_with_info to replace hwmon_device_register_with_info, the remote operation can be completely deleted, and the kraken2_priv_data no longer needs to hold hwmon device. Signed-off-by: Li Zetao Acked-by: Guenter Roeck Acked-by: Jonas Malaco --- v1 -> v2: 1) Further optimize using devm_hwmon_device_register_with_info and remove the .remove operation 2) Adjust commit information v1: https://lore.kernel.org/all/20240904123607.3407364-18-lizetao1@huawei.com/ drivers/hwmon/nzxt-kraken2.c | 45 ++++++------------------------------ 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/drivers/hwmon/nzxt-kraken2.c b/drivers/hwmon/nzxt-kraken2.c index 7caf387eb144..5b618fc2c17f 100644 --- a/drivers/hwmon/nzxt-kraken2.c +++ b/drivers/hwmon/nzxt-kraken2.c @@ -29,7 +29,6 @@ static const char *const kraken2_fan_label[] = { struct kraken2_priv_data { struct hid_device *hid_dev; - struct device *hwmon_dev; s32 temp_input[1]; u16 fan_input[2]; unsigned long updated; /* jiffies */ @@ -133,6 +132,7 @@ static int kraken2_probe(struct hid_device *hdev, const struct hid_device_id *id) { struct kraken2_priv_data *priv; + struct device *hwmon_dev; int ret; priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL); @@ -158,44 +158,14 @@ 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, - NULL); - 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 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) -{ - struct kraken2_priv_data *priv = hid_get_drvdata(hdev); - - hwmon_device_unregister(priv->hwmon_dev); - hid_hw_close(hdev); - hid_hw_stop(hdev); + hwmon_dev = devm_hwmon_device_register_with_info(&hdev->dev, "kraken2", + priv, &kraken2_chip_info, + NULL); + return PTR_ERR_OR_ZERO(hwmon_dev); } static const struct hid_device_id kraken2_table[] = { @@ -209,7 +179,6 @@ static struct hid_driver kraken2_driver = { .name = "nzxt-kraken2", .id_table = kraken2_table, .probe = kraken2_probe, - .remove = kraken2_remove, .raw_event = kraken2_raw_event, }; From patchwork Mon Sep 9 01:23:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795719 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 1E5D1A932; Mon, 9 Sep 2024 01:14:25 +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=1725844468; cv=none; b=S38/QkhOgMegZSXZM3i5g1psVIdktZJ8FC0xpENd17SrzBHCdb9ONUI5zLalB1pVyXkTtqa0HVCAbCpz4trDVZH/5jK146mIrvUH5dqGmfhBVY8O78HiSFfeIgb0+gGv2zBSqwnK0tfRZKLR/O3D0e46OiBYlRulE8yMV1LZLWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844468; c=relaxed/simple; bh=VRfZBD5j6lzrYFnlOvgAE7SYrKCRfdZmUY09ETxQKkc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bmmkFzsyikIGUz0aznxCZd1Nfn7pr/rc2zE83J+5v58m4yOGDln28V+upBMcbMBixJrI+VdOvKvjO74tayLrMwZuBN1udnAkumofwF+LC2P6He4svCXM2DBgyrGoEK5/l9Iso+TYxYEg5boLwZMWdfH5HR5OAaLURr3B+IHQr7Y= 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 4X28455KY1z1j836; Mon, 9 Sep 2024 09:13:57 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id C87D21400DC; Mon, 9 Sep 2024 09:14:23 +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; Mon, 9 Sep 2024 09:14:23 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 14/15] hwmon: (nzxt-kraken3) Use devm_hid_hw_start_and_open in kraken3_probe() Date: Mon, 9 Sep 2024 09:23:12 +0800 Message-ID: <20240909012313.500341-15-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the nzxt-kraken2 module needs to maintain hid resources by itself. Use 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 Acked-by: Guenter Roeck Reviewed-by: Aleksa Savic --- v1 -> v2: Adjust commit information v1: https://lore.kernel.org/all/20240904123607.3407364-19-lizetao1@huawei.com/ 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 Mon Sep 9 01:23:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13795726 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 A46691078B; Mon, 9 Sep 2024 01:14:31 +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=1725844473; cv=none; b=frcclKfv997zsAMPKL4GqTZEjWOuzAZr9Q8Jm8Gql05TRtjKtan1MMOscWxZEwyREQkz/OoQAzi584fRA9taULgLVt8/P3/zWyex6ry4Td62EblVD+gS8pHrb5J5Gb82Kh/wVq9331QL/Y1ai7npXHrF3GBGTrnSgpGc/l2aS3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725844473; c=relaxed/simple; bh=AP2HopHUUt5Hx6YaR2uv2rICTXiMqOqgayan1s2YR20=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IELcc74DEso9QO1ARrTaAWeRha10pN/3W4kpW50V9/PZl8LQeLH7bXARaXLctN6DHLhxiNN2H8PHrbENetW0+8wzq4JDBwbmHiz0vut5J262GLt/Yb0Alc5McYJjNO058XseIWbA5/akUJXXhFpaFFLl3mYeg614YuS0kr8lMlc= 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 4X283n2RpCzyRbm; Mon, 9 Sep 2024 09:13:41 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 6DFFD1403D5; Mon, 9 Sep 2024 09:14:24 +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; Mon, 9 Sep 2024 09:14:23 +0800 From: Li Zetao To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH -next v2 15/15] hwmon: (nzxt-smart2) Use devm_hid_hw_start_and_open in nzxt_smart2_hid_probe() Date: Mon, 9 Sep 2024 09:23:13 +0800 Message-ID: <20240909012313.500341-16-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909012313.500341-1-lizetao1@huawei.com> References: <20240909012313.500341-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: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd500012.china.huawei.com (7.221.188.25) Currently, the nzxt-smart2 module needs to maintain hid resources by itself. Use 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. Further optimization, use devm_hwmon_device_register_with_info to replace hwmon_device_register_with_info, the remote operation can be completely deleted, and the drvdata no longer needs to hold hwmon device Signed-off-by: Li Zetao Acked-by: Guenter Roeck --- v1 -> v2: 1) Further optimize using devm_hwmon_device_register_with_info and remove the .remove operation 2) Adjust commit information v1: https://lore.kernel.org/all/20240904123607.3407364-20-lizetao1@huawei.com/ drivers/hwmon/nzxt-smart2.c | 38 +++++-------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/drivers/hwmon/nzxt-smart2.c b/drivers/hwmon/nzxt-smart2.c index df6fa72a6b59..9c6d020ac896 100644 --- a/drivers/hwmon/nzxt-smart2.c +++ b/drivers/hwmon/nzxt-smart2.c @@ -172,7 +172,6 @@ struct set_fan_speed_report { struct drvdata { struct hid_device *hid; - struct device *hwmon; u8 fan_duty_percent[FAN_CHANNELS]; u16 fan_rpm[FAN_CHANNELS]; @@ -730,6 +729,7 @@ static int nzxt_smart2_hid_probe(struct hid_device *hdev, const struct hid_device_id *id) { struct drvdata *drvdata; + struct device *hwmon; int ret; drvdata = devm_kzalloc(&hdev->dev, sizeof(struct drvdata), GFP_KERNEL); @@ -750,44 +750,17 @@ 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); - 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; - } - - 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) -{ - struct drvdata *drvdata = hid_get_drvdata(hdev); - - hwmon_device_unregister(drvdata->hwmon); - - hid_hw_close(hdev); - hid_hw_stop(hdev); + hwmon = devm_hwmon_device_register_with_info(&hdev->dev, "nzxtsmart2", drvdata, + &nzxt_smart2_chip_info, NULL); + return PTR_ERR_OR_ZERO(hwmon); } static const struct hid_device_id nzxt_smart2_hid_id_table[] = { @@ -807,7 +780,6 @@ static struct hid_driver nzxt_smart2_hid_driver = { .name = "nzxt-smart2", .id_table = nzxt_smart2_hid_id_table, .probe = nzxt_smart2_hid_probe, - .remove = nzxt_smart2_hid_remove, .raw_event = nzxt_smart2_hid_raw_event, #ifdef CONFIG_PM .reset_resume = nzxt_smart2_hid_reset_resume,