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 <lizetao1@xxxxxxxxxx> --- 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[] = { -- 2.34.1