lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221117121304.5516-1-marcus.folkesson@gmail.com>
Date:   Thu, 17 Nov 2022 13:13:04 +0100
From:   Marcus Folkesson <marcus.folkesson@...il.com>
To:     Jiri Kosina <jikos@...nel.org>,
        Benjamin Tissoires <benjamin.tissoires@...hat.com>,
        Marcus Folkesson <marcus.folkesson@...il.com>
Cc:     linux-kernel@...r.kernel.org, linux-input@...r.kernel.org
Subject: [PATCH v2] HID: hid-cmedia: use device managed resources

When we do not need to free() any memory in .remove, we can remove
cmhid_remove as well.
hid_device_remove() will call hid_hw_stop() as default .remove function
if no function is specified.

Signed-off-by: Marcus Folkesson <marcus.folkesson@...il.com>
---
 drivers/hid/hid-cmedia.c | 27 +++++----------------------
 1 file changed, 5 insertions(+), 22 deletions(-)

diff --git a/drivers/hid/hid-cmedia.c b/drivers/hid/hid-cmedia.c
index cab42047bc99..8b0007168afb 100644
--- a/drivers/hid/hid-cmedia.c
+++ b/drivers/hid/hid-cmedia.c
@@ -145,11 +145,9 @@ static int cmhid_probe(struct hid_device *hid, const struct hid_device_id *id)
 	int ret;
 	struct cmhid *cm;
 
-	cm = kzalloc(sizeof(struct cmhid), GFP_KERNEL);
-	if (!cm) {
-		ret = -ENOMEM;
-		goto allocfail;
-	}
+	cm = devm_kzalloc(&hid->dev, sizeof(struct cmhid), GFP_KERNEL);
+	if (!cm)
+		return -ENOMEM;
 
 	cm->hid = hid;
 
@@ -159,30 +157,16 @@ static int cmhid_probe(struct hid_device *hid, const struct hid_device_id *id)
 	ret = hid_parse(hid);
 	if (ret) {
 		hid_err(hid, "parse failed\n");
-		goto fail;
+		return ret;
 	}
 
 	ret = hid_hw_start(hid, HID_CONNECT_DEFAULT | HID_CONNECT_HIDDEV_FORCE);
-	if (ret) {
+	if (ret)
 		hid_err(hid, "hw start failed\n");
-		goto fail;
-	}
 
-	return 0;
-fail:
-	kfree(cm);
-allocfail:
 	return ret;
 }
 
-static void cmhid_remove(struct hid_device *hid)
-{
-	struct cmhid *cm = hid_get_drvdata(hid);
-
-	hid_hw_stop(hid);
-	kfree(cm);
-}
-
 static const struct hid_device_id cmhid_devices[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM6533) },
 	{ }
@@ -195,7 +179,6 @@ static struct hid_driver cmhid_driver = {
 	.raw_event = cmhid_raw_event,
 	.input_configured = cmhid_input_configured,
 	.probe = cmhid_probe,
-	.remove = cmhid_remove,
 	.input_mapping = cmhid_input_mapping,
 };
 
-- 
2.38.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ