From patchwork Tue Sep 15 14:12:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "gregkh@linuxfoundation.org" X-Patchwork-Id: 309678 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA505C43461 for ; Tue, 15 Sep 2020 23:24:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E2DA21974 for ; Tue, 15 Sep 2020 23:24:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600212284; bh=Cez5YrJMd+kRD6GKDOhBagZay32pDINJhG2yn//Ywjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ZryK2Xa+xxWbo3HVglzzKKyaEs2UTVz30cCpUXvgaDVrOVRpdUduzrYMuot11DCMS 4HU8I/nYAzNccn7quWcDmcxaMMwX6Eaewe0LFIOl1X57x0U1jFk3tHmsi4SAwg//53 Ytt/5pE8BLm/keGAQchKmZMLJA76wAJnhxSILUNU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727184AbgIOXYm (ORCPT ); Tue, 15 Sep 2020 19:24:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:48812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727178AbgIOOiA (ORCPT ); Tue, 15 Sep 2020 10:38:00 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 989BD2245F; Tue, 15 Sep 2020 14:27:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600180067; bh=Cez5YrJMd+kRD6GKDOhBagZay32pDINJhG2yn//Ywjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1lWYe2o+vHrMWJmP5+OZhy/Tye59UFQwAawPDK7N1Ei3FvBKFGaGEMRmBuJ80/BbL D87WnGBr1XhvJj+mvliyfMNty9rEEUTZV4aa5sW4LxhcleKfYip8lE84YwcBDbSZ08 DRid+8GRmp1qed/23rhUe8qpnlTomSaq+DzPST+0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dinghao Liu , Jiri Kosina , Sasha Levin Subject: [PATCH 5.8 096/177] HID: elan: Fix memleak in elan_input_configured Date: Tue, 15 Sep 2020 16:12:47 +0200 Message-Id: <20200915140658.243716637@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200915140653.610388773@linuxfoundation.org> References: <20200915140653.610388773@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Dinghao Liu [ Upstream commit b7429ea53d6c0936a0f10a5d64164f0aea440143 ] When input_mt_init_slots() fails, input should be freed to prevent memleak. When input_register_device() fails, we should call input_mt_destroy_slots() to free memory allocated by input_mt_init_slots(). Signed-off-by: Dinghao Liu Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-elan.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/hid/hid-elan.c b/drivers/hid/hid-elan.c index 45c4f888b7c4e..dae193749d443 100644 --- a/drivers/hid/hid-elan.c +++ b/drivers/hid/hid-elan.c @@ -188,6 +188,7 @@ static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi) ret = input_mt_init_slots(input, ELAN_MAX_FINGERS, INPUT_MT_POINTER); if (ret) { hid_err(hdev, "Failed to init elan MT slots: %d\n", ret); + input_free_device(input); return ret; } @@ -198,6 +199,7 @@ static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi) if (ret) { hid_err(hdev, "Failed to register elan input device: %d\n", ret); + input_mt_destroy_slots(input); input_free_device(input); return ret; }