From patchwork Sun Sep 11 04:09:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 9325119 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 5F0A36048B for ; Sun, 11 Sep 2016 04:09:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AC9B2921D for ; Sun, 11 Sep 2016 04:09:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A4822948F; Sun, 11 Sep 2016 04:09:43 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 0DF1D2921D for ; Sun, 11 Sep 2016 04:09:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750912AbcIKEJk (ORCPT ); Sun, 11 Sep 2016 00:09:40 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33728 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750758AbcIKEJj (ORCPT ); Sun, 11 Sep 2016 00:09:39 -0400 Received: by mail-pf0-f194.google.com with SMTP id 128so6193358pfb.0 for ; Sat, 10 Sep 2016 21:09:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ingics-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=op50vt1M2ZEDVeSrkpryzEbbKzbMdbk/7i3Jra8IQ2U=; b=a3Wx1ue94fiV5g0iSK9+MRih5ynGwBj0ko2BmWe7oDC/FBBDR1rRycZpnr0PTvhRyO Fcfya6b9/LVV8tGeRnBC4yFHWtWNR0NwjOcPd7eQomznULS5y2l7EL6dXcDjKZSSVIX7 F5LR7iKjTJ38s1a9eVcxpJ+7yR2v7JbGGUTiD5Mk6Iu+nzgFDbu+YdmdvKogUpgIIjAO 7/uFJJroBl+pJkhWZ+gv2w8PSaUYxUYjBAqrcgZcAdpKix/YlRUBdNuSDjhi/1s713Mh dxtCRDMjMabXNkH2muj4ePqAqQFKGM2dxMbVzmCt16EksO/I8OzABVJ5dIlwG4YBrr2P qw9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=op50vt1M2ZEDVeSrkpryzEbbKzbMdbk/7i3Jra8IQ2U=; b=O8dNcZ7NxjOnsNUAdVFSDni3zVT8INcUMXMiUWamrbj5+F/2uKoyprUc2gvHlENqPD IYbO77xot7LMBY/b77Qjs/B3uJai2KZpxRZp9kq7JHDcJqzQcd8LRCidCqnV57mKerHT KpO6c/3cpiJq6oBTAOgenbIXDfKIPoJz4auFuUQFF/jelQ4Avb/bn/mHHAq9m3fhz0+O ZV8qJprqRxsa54q1nUdO19TMI37GoS/si5ovzCvjFHNunVqkBAc/+iQPfZX700cH7Meh lWxxwaOYl+j8pJoEYA/Fx0XDJvJGLfW8KunQz4IceCErXLLObkuQrHNwLaKnUDFQcHe/ hQcg== X-Gm-Message-State: AE9vXwOPw+gyGyMsfIEixlZueUR4tnjQN/P/vnrJZE6AZnrAcXPXoOXtDv+2Mh7KZqbkHw== X-Received: by 10.98.33.205 with SMTP id o74mr20748310pfj.81.1473566978731; Sat, 10 Sep 2016 21:09:38 -0700 (PDT) Received: from localhost.localdomain (218-164-28-206.dynamic.hinet.net. [218.164.28.206]) by smtp.gmail.com with ESMTPSA id q82sm15043867pfk.80.2016.09.10.21.09.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Sep 2016 21:09:37 -0700 (PDT) From: Axel Lin To: Jiri Kosina Cc: Masaki Ota , Benjamin Tissoires , linux-input@vger.kernel.org, Axel Lin Subject: [PATCH] HID: alps: Fix memory leak Date: Sun, 11 Sep 2016 12:09:01 +0800 Message-Id: <1473566941-25149-1-git-send-email-axel.lin@ingics.com> X-Mailer: git-send-email 2.7.4 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 A kfree(readbuf) call was missed if hid_hw_raw_request() fails, fix it. Also avoid mixing direct return with goto in the error paths. Signed-off-by: Axel Lin Reviewed-by: Benjamin Tissoires --- drivers/hid/hid-alps.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c index 048befd..2808da9 100644 --- a/drivers/hid/hid-alps.c +++ b/drivers/hid/hid-alps.c @@ -139,8 +139,8 @@ static int u1_read_write_register(struct hid_device *hdev, u32 address, if (read_flag) { readbuf = kzalloc(U1_FEATURE_REPORT_LEN, GFP_KERNEL); if (!readbuf) { - kfree(input); - return -ENOMEM; + ret = -ENOMEM; + goto exit; } ret = hid_hw_raw_request(hdev, U1_FEATURE_REPORT_ID, readbuf, @@ -149,6 +149,7 @@ static int u1_read_write_register(struct hid_device *hdev, u32 address, if (ret < 0) { dev_err(&hdev->dev, "failed read register (%d)\n", ret); + kfree(readbuf); goto exit; }