From patchwork Wed Jun 13 11:59:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanno Zulla X-Patchwork-Id: 10462109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DA17C60329 for ; Wed, 13 Jun 2018 12:00:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C56F52893D for ; Wed, 13 Jun 2018 12:00:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B96E128942; Wed, 13 Jun 2018 12:00:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5569428939 for ; Wed, 13 Jun 2018 12:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935398AbeFML77 (ORCPT ); Wed, 13 Jun 2018 07:59:59 -0400 Received: from zoot.epublica.de ([78.46.103.157]:51834 "EHLO zoot.epublica.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935408AbeFML76 (ORCPT ); Wed, 13 Jun 2018 07:59:58 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by zoot.epublica.de (Postfix) with ESMTP id 5838418405B4; Wed, 13 Jun 2018 13:59:57 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zoot.epublica.de Received: from zoot.epublica.de ([127.0.0.1]) by localhost (zoot.epublica.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1QCkBGCiqvIu; Wed, 13 Jun 2018 13:59:49 +0200 (CEST) Received: from [10.1.0.41] (ip1f12a024.dynamic.kabel-deutschland.de [31.18.160.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by zoot.epublica.de (Postfix) with ESMTPSA id 3AEAA1840389; Wed, 13 Jun 2018 13:59:49 +0200 (CEST) Subject: [PATCH 1/1] HID: hid-betopff.c: Use devm_kzalloc, move _init() code into _probe(). From: Hanno Zulla To: huangbobupt@163.com Cc: Jiri Kosina , Benjamin Tissoires , linux-input References: Message-ID: <99bd97d0-363a-21d6-5966-427f92c59889@hanno.de> Date: Wed, 13 Jun 2018 13:59:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Language: de-LU Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The use of kfree() can be avoided when using devm_kzalloc(). Also, the original _init() function didn't properly return error codes and the whole error handling can be simplified once the _init() function is moved into the _probe() function. Signed-off-by: Hanno Zulla --- drivers/hid/hid-betopff.c | 82 ++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 48 deletions(-) diff --git a/drivers/hid/hid-betopff.c b/drivers/hid/hid-betopff.c index 69cfc8dc6af1..04ea55a4250d 100644 --- a/drivers/hid/hid-betopff.c +++ b/drivers/hid/hid-betopff.c @@ -55,24 +55,40 @@ static int hid_betopff_play(struct input_dev *dev, void *data, return 0; } -static int betopff_init(struct hid_device *hid) +static int betop_probe(struct hid_device *hdev, const struct hid_device_id *id) { struct betopff_device *betopff; struct hid_report *report; - struct hid_input *hidinput = - list_first_entry(&hid->inputs, struct hid_input, list); - struct list_head *report_list = - &hid->report_enum[HID_OUTPUT_REPORT].report_list; - struct input_dev *dev = hidinput->input; + struct hid_input *hidinput; + struct list_head *report_list; int field_count = 0; 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; + + error = hid_parse(hdev); + if (error) { + hid_err(hdev, "parse failed\n"); + return error; + } + + error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); + if (error) { + hid_err(hdev, "hw start failed\n"); + return error; + } + + report_list = &hdev->report_enum[HID_OUTPUT_REPORT].report_list; if (list_empty(report_list)) { - hid_err(hid, "no output reports found\n"); + hid_err(hdev, "no output reports found\n"); return -ENODEV; } - report = list_first_entry(report_list, struct hid_report, list); /* * Actually there are 4 fields for 4 Bytes as below: @@ -90,55 +106,25 @@ static int betopff_init(struct hid_device *hid) } if (field_count < 4) { - hid_err(hid, "not enough fields in the report: %d\n", - field_count); + hid_err(hdev, "not enough fields in the report: %d\n", + field_count); return -ENODEV; } - betopff = kzalloc(sizeof(*betopff), GFP_KERNEL); - if (!betopff) - return -ENOMEM; - - set_bit(FF_RUMBLE, dev->ffbit); - - error = input_ff_create_memless(dev, betopff, hid_betopff_play); - if (error) { - kfree(betopff); - return error; - } - + hidinput = list_first_entry(&hdev->inputs, struct hid_input, list); + set_bit(FF_RUMBLE, hidinput->input->ffbit); betopff->report = report; - hid_hw_request(hid, betopff->report, HID_REQ_SET_REPORT); - hid_info(hid, "Force feedback for betop devices by huangbo \n"); - - return 0; -} - -static int betop_probe(struct hid_device *hdev, const struct hid_device_id *id) -{ - int ret; - - if (id->driver_data) - hdev->quirks |= HID_QUIRK_MULTI_INPUT; - - ret = hid_parse(hdev); - if (ret) { - hid_err(hdev, "parse failed\n"); - goto err; - } + error = input_ff_create_memless(hidinput->input, + betopff, hid_betopff_play); + if (error) + return error; - ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); - if (ret) { - hid_err(hdev, "hw start failed\n"); - goto err; - } + hid_hw_request(hdev, betopff->report, HID_REQ_SET_REPORT); - betopff_init(hdev); + hid_info(hdev, "Force feedback for betop devices by huangbo \n"); return 0; -err: - return ret; } static const struct hid_device_id betop_devices[] = {