Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp729984imm; Wed, 1 Aug 2018 04:28:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdWK1lWm2aQwf6/SIHzTrVm4oDXf895SjGoXmFiJiqDZJo9SoHaq7BgFTyGE2hIihf2d8UM X-Received: by 2002:a17:902:585:: with SMTP id f5-v6mr24564134plf.7.1533122936054; Wed, 01 Aug 2018 04:28:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533122936; cv=none; d=google.com; s=arc-20160816; b=FXYf+55yggFOA7A4M6anFTkTS7PAmBV7UQmSOa4sxwXdQg5GQ0US64U3cwaymCs/by vqzp468Yp3noNBSIk8VpRJGaVjS8tfgegJiqswfLQ7BMGM4QITKWcvUd6X8c8+WcW3UK skX8xBI+cPEbiwl5ASAP1zSgBuMHo11x+12qQyMkVRAISGnGi37rG4rwmD9HBME7GqEU o41E6YLJkEC+hGhQG1fmYxPPpITfoTt4BYLDygf07d2hF/suq4ph08StPOKy1lqqR7Bs oxjb4cgutBUOtRwe4oVX//UjQL5vOhrJe2sQHye8Rj/5Bhx9+58P+gl2SwIJ7T5VD8ny 6QqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=TDw8JyF5JUHxJTuTLdmWLA4ZyIJl7JMZsEtPDSMa1oY=; b=gVvNfGj2N4p//VucwOERNDfI9ESDt6urp61fgGRDlE6EE2Yu6uZ/kPTRFObE2cRI2t iZyiYp5Zq02CBK7hZh434pxI7EGEubKJ9cHMwlY2eIsrRwThQ5BV0kizWDfrMDYTFJns j96+6339uEECrLqO0p76vqi+oJTCFr3aztMRq/CBgFXeHAMkqWp4WtZ67KE+xkIZ6QAa /NLiKgqflIKRG6yXji7LWgTi8RXSi/6yiFfeUybVqxTyRJ6VViufGailcV4rOwDjbp8x 5ZWBq4hvhqslCyFqVo2Hp7TCXoRrVD/guFhyCQSbCGyKGPsfEwR+UJKXuayg7cbi6YHu jPBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h16-v6si17260999pgb.39.2018.08.01.04.28.41; Wed, 01 Aug 2018 04:28:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389022AbeHANMh (ORCPT + 99 others); Wed, 1 Aug 2018 09:12:37 -0400 Received: from bran.ispras.ru ([83.149.199.196]:17498 "EHLO smtp.ispras.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388704AbeHANMg (ORCPT ); Wed, 1 Aug 2018 09:12:36 -0400 Received: from myklebust.intra.ispras.ru (unknown [10.10.2.207]) by smtp.ispras.ru (Postfix) with ESMTP id 5AA2F203CC; Wed, 1 Aug 2018 14:27:14 +0300 (MSK) From: Anton Vasilyev To: Srinivas Pandruvada Cc: Anton Vasilyev , Jiri Kosina , Benjamin Tissoires , Even Xu , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH v2] HID: intel_ish-hid: tx_buf memory leak on probe/remove Date: Wed, 1 Aug 2018 14:26:51 +0300 Message-Id: <20180801112651.6032-1-vasilyev@ispras.ru> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ish_dev_init() allocates 512*176 bytes memory for tx_buf and stores it at &dev->wr_free_list_head.link list on ish_probe(). But there is no deallocation of this memory in ish_remove() and in ish_probe() error path. So current intel-ish-ipc provides 88 KB memory leak for each probe/release. The patch replaces kzalloc allocation by devm_kzalloc and removes ishtp_device *dev deallocation by kfree. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Anton Vasilyev Acked-by: Srinivas Pandruvada --- v2: Fix align for multi line statements --- drivers/hid/intel-ish-hid/ipc/ipc.c | 9 ++++++--- drivers/hid/intel-ish-hid/ipc/pci-ish.c | 2 -- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/hid/intel-ish-hid/ipc/ipc.c b/drivers/hid/intel-ish-hid/ipc/ipc.c index 9a60ec13cb10..bfbca7ec54ce 100644 --- a/drivers/hid/intel-ish-hid/ipc/ipc.c +++ b/drivers/hid/intel-ish-hid/ipc/ipc.c @@ -907,8 +907,9 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev) struct ishtp_device *dev; int i; - dev = kzalloc(sizeof(struct ishtp_device) + sizeof(struct ish_hw), - GFP_KERNEL); + dev = devm_kzalloc(&pdev->dev, + sizeof(struct ishtp_device) + sizeof(struct ish_hw), + GFP_KERNEL); if (!dev) return NULL; @@ -925,7 +926,9 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev) for (i = 0; i < IPC_TX_FIFO_SIZE; ++i) { struct wr_msg_ctl_info *tx_buf; - tx_buf = kzalloc(sizeof(struct wr_msg_ctl_info), GFP_KERNEL); + tx_buf = devm_kzalloc(&pdev->dev, + sizeof(struct wr_msg_ctl_info), + GFP_KERNEL); if (!tx_buf) { /* * IPC buffers may be limited or not available diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c b/drivers/hid/intel-ish-hid/ipc/pci-ish.c index a2c53ea3b5ed..81d035a480bc 100644 --- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c +++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c @@ -172,7 +172,6 @@ static int ish_probe(struct pci_dev *pdev, const struct pci_device_id *ent) free_irq(pdev->irq, dev); free_device: pci_iounmap(pdev, hw->mem_addr); - kfree(dev); release_regions: pci_release_regions(pdev); disable_device: @@ -202,7 +201,6 @@ static void ish_remove(struct pci_dev *pdev) pci_release_regions(pdev); pci_clear_master(pdev); pci_disable_device(pdev); - kfree(ishtp_dev); } static struct device __maybe_unused *ish_resume_device; -- 2.18.0