diff mbox series

[v2,4/5] HID: hid-betopff.c: Allocate mem before hid_parse, use devm_kzalloc()

Message ID 540730a4-cc4b-666a-505e-79980e6332ce@hanno.de (mailing list archive)
State New, archived
Headers show
Series HID: hid-betopff.c: Minor code refactoring | expand

Commit Message

Hanno Zulla July 23, 2018, 3:06 p.m. UTC
HID: hid-betopff.c: Allocate mem before hid_parse, use devm_kzalloc()

The driver's betopff struct should be allocated prior to parsing.
With devm_kzalloc() the use of kfree() turns obsolete and error
handling is simplified.

Signed-off-by: Hanno Zulla <kontakt@hanno.de>
---
 drivers/hid/hid-betopff.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/drivers/hid/hid-betopff.c b/drivers/hid/hid-betopff.c
index e4e9cbe44515..9edbdad5264e 100644
--- a/drivers/hid/hid-betopff.c
+++ b/drivers/hid/hid-betopff.c
@@ -65,6 +65,10 @@  static int betop_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	int error;
 	int i, j;
 
+	betopff = devm_kzalloc(&hdev->dev, sizeof(*betopff), GFP_KERNEL);
+	if (!betopff)
+		return -ENOMEM;
+
 	if (id->driver_data)
 		hdev->quirks |= HID_QUIRK_MULTI_INPUT;
 
@@ -108,17 +112,12 @@  static int betop_probe(struct hid_device *hdev, const struct hid_device_id *id)
 		return -ENODEV;
 	}
 
-	betopff = kzalloc(sizeof(*betopff), GFP_KERNEL);
-	if (!betopff)
-		return -ENOMEM;
-
 	hidinput = list_first_entry(&hdev->inputs, struct hid_input, list);
 	set_bit(FF_RUMBLE, hidinput->input->ffbit);
 
 	error = input_ff_create_memless(hidinput->input,
 			betopff, hid_betopff_play);
 	if (error) {
-		kfree(betopff);
 		return error;
 	}