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: Li Zetao X-Patchwork-Id: 825395 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-i2c@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: Li Zetao X-Patchwork-Id: 825396 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-i2c@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: Li Zetao X-Patchwork-Id: 825394 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-i2c@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:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 825393 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-i2c@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:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 825392 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-i2c@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: Li Zetao X-Patchwork-Id: 825391 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-i2c@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 --- 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:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 825390 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-i2c@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:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 825389 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-i2c@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: Li Zetao X-Patchwork-Id: 825388 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-i2c@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:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 825387 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-i2c@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[] = {