Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp7049266imm; Tue, 24 Jul 2018 07:37:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfAo63qk1C2cJ0llh4UM5id7yU6C2HDhLoj3WvZQX9GQo0jnrQReSYTurZU7t1NdBMx2JaV X-Received: by 2002:a17:902:b693:: with SMTP id c19-v6mr17383428pls.114.1532443037761; Tue, 24 Jul 2018 07:37:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532443037; cv=none; d=google.com; s=arc-20160816; b=hkRtaJCfMbvNaGsWGsoe+k9nmhWb+z9sWiVmBF5z+RvSdd/bjo7iXHJyeTEL6hn++M GGm0ZPM+1M+jOVh4LN1zpdtOASsIwrVUG83wzjhSotOh65SEtW4GP/9gZOWkw7huoM0T xkSnWPT4tPK/nT7tQzRXlXKqEMO1BV3FT6hx4+XdnoT6+hOmMihoebavQfWMvMly4tGz E7pA4YO8xkkrxLfjvfsJCLKnO3c4Dvv+QD4wm7Fpss/tV9kfwQcrLv1X0hV/Of7zArao QJhAGWRK02Qm6xFv1IMHj5vm+LhKYBrYebCxK0h048vlwOzxTHIxlby1c2DhWyrUkulX 0aNA== 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=NGdjtTtxl/UA5KgSNIX7Vnb+1X0IOJJcOxk2T9Kafz0=; b=HdqHWUQZLN56bI9m4GXH4XfmcoH/edPG309PeQnKqNcKLMpIUo6FRAGLgjoLQ9j4Af /P8tUdYRfTRHsOh+H8ar81x8sd8hUVkfsirO+YsLb9ms0KjHcrlMaFBg9UiYcE7C21Dx k3HFw42PnyQOdBRiGR+cJLcdJnc2VdcFLsBTb4cChIPgQMfNZXGeuXC6hUW8qHAg1xdc F8iUfkFa22hiNqzFmBuxgkg/HyySISxqp/G400jCFjAzYQ/Jk1002LyOYyy/kkDtphZk SNwtirtbXNEAlcgZy687JGTUfxHXYCPRJQZEuG0TMMmDi0ZXASCxo+7VpHfECP2YlcYJ X4cg== 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 u13-v6si10192736plq.320.2018.07.24.07.37.02; Tue, 24 Jul 2018 07:37:17 -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 S2388611AbeGXPmw (ORCPT + 99 others); Tue, 24 Jul 2018 11:42:52 -0400 Received: from bran.ispras.ru ([83.149.199.196]:16389 "EHLO smtp.ispras.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388448AbeGXPmv (ORCPT ); Tue, 24 Jul 2018 11:42:51 -0400 Received: from myklebust.intra.ispras.ru (unknown [10.10.2.207]) by smtp.ispras.ru (Postfix) with ESMTP id E7056203C6; Tue, 24 Jul 2018 17:36:02 +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] HID: intel_ish-hid: tx_buf memory leak on probe/remove Date: Tue, 24 Jul 2018 17:34:55 +0300 Message-Id: <20180724143455.13770-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 --- drivers/hid/intel-ish-hid/ipc/ipc.c | 7 +++++-- drivers/hid/intel-ish-hid/ipc/pci-ish.c | 2 -- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/hid/intel-ish-hid/ipc/ipc.c b/drivers/hid/intel-ish-hid/ipc/ipc.c index 9a60ec13cb10..2f8e5402b450 100644 --- a/drivers/hid/intel-ish-hid/ipc/ipc.c +++ b/drivers/hid/intel-ish-hid/ipc/ipc.c @@ -907,7 +907,8 @@ 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), + 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