From patchwork Mon Jul 23 15:06:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanno Zulla X-Patchwork-Id: 10540489 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9CF1314BC for ; Mon, 23 Jul 2018 15:07:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 891E320243 for ; Mon, 23 Jul 2018 15:07:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73F7A28498; Mon, 23 Jul 2018 15:07:01 +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 2132327FB0 for ; Mon, 23 Jul 2018 15:07:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387966AbeGWQIj (ORCPT ); Mon, 23 Jul 2018 12:08:39 -0400 Received: from zoot.epublica.de ([78.46.103.157]:49872 "EHLO zoot.epublica.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387852AbeGWQIj (ORCPT ); Mon, 23 Jul 2018 12:08:39 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by zoot.epublica.de (Postfix) with ESMTP id 97EC718400A6; Mon, 23 Jul 2018 17:06:58 +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 5LwdlWG4SyhF; Mon, 23 Jul 2018 17:06:57 +0200 (CEST) Received: from [10.1.0.41] (ip1f103e43.dynamic.kabel-deutschland.de [31.16.62.67]) (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 524FA18405BB; Mon, 23 Jul 2018 17:06:57 +0200 (CEST) Subject: [PATCH v2 4/5] HID: hid-betopff.c: Allocate mem before hid_parse, use devm_kzalloc() From: Hanno Zulla To: huangbobupt@163.com Cc: Jiri Kosina , Benjamin Tissoires , linux-input References: <84e73143-a5da-9e8d-4ec8-ce425e1b4699@hanno.de> <3865de51-b659-c24f-6394-6934f004dccd@hanno.de> <386e2cdd-49ec-fe4c-ead7-78dc5384cab9@hanno.de> <05803eec-3fa5-61fb-2129-991b15bc8618@hanno.de> Message-ID: <540730a4-cc4b-666a-505e-79980e6332ce@hanno.de> Date: Mon, 23 Jul 2018 17:06:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <05803eec-3fa5-61fb-2129-991b15bc8618@hanno.de> 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 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 --- 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; }