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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxx>
---
 drivers/hid/hid-betopff.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

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;
 	}
 
-- 
2.17.1

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux