Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1930055pxu; Sun, 13 Dec 2020 07:56:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJzhyBznocQUU9KOMAP2MhXknB3QUq7jK5rQxS30PuDsGPZLwdA2sY+KEF+N9gFT0HPZV4dv X-Received: by 2002:a17:906:4d52:: with SMTP id b18mr18304184ejv.405.1607875015281; Sun, 13 Dec 2020 07:56:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607875015; cv=none; d=google.com; s=arc-20160816; b=WAqTgRsfZsEfTRSIW1pPto0u/G0qmeLDFnahdCEjxifMgqIWZ0hQ9XY49vaQgL3Zta RFioQVDcGd/sPpi8PtbOKSj1hkF1P7mSp6rYULCXXKa9kiebSeGeMm8rSeZL0637VhDb Z5EzXHAbn+q3Ap1zM5Tr41K6Po9OgQfTHQ//b3CWR8pbj12UkDteqjNrz9PqeFEqhLB3 NGicOtRF01HizmDBns2UoGt3q+WDoYj1Npte+8NAyk0vlswRAqUE3hYC0UbzgtnmI1hY r77xq1qTbXA7NFO4HLfEmnVHpNStLxToktuoa8FR+6rHUT8eAkdgLF9GBSGtJ1zbI7IE XVeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=BUh+Dbb3satIUXdIV1SaaQo3YGDUJJb5p2mL09mZgBM=; b=DK9JiZmzLFyJQMFv200CA8rcA0i7c0t3nPaXJDg35jq/gMWZrsyy3lbBB7J9XXYJUw YTKP1K0hUj/j9iB/Nr2jMo55ZEw0nCYh+GI4OEB4i1k1FrTHBJa9n74pXAEv1+xjhSCQ pRjqcfzvZ0Byj3t1EWN7fuHYOtDeYjv7DDkTLpkGkeFD7HB0McgbFulaPKZ4urXoGruB Uf1i2pYa+KvobNjMXVF/cgt3Lgnt0YIW3+rdL1RgAg1KtMc13Cd/cyZmWaF609ntCy7T EF8XMSJ1QweWTDmsP29aNXqlrOkVJofd9GvmwX8Ycm3+wV84gMTtNbyy0RNPrhpfRlyy 2yUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id he7si7918104ejc.676.2020.12.13.07.56.32; Sun, 13 Dec 2020 07:56:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405839AbgLLQLh (ORCPT + 99 others); Sat, 12 Dec 2020 11:11:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:57720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439378AbgLLQJg (ORCPT ); Sat, 12 Dec 2020 11:09:36 -0500 From: Sasha Levin Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ofir Bitton , Oded Gabbay , Sasha Levin Subject: [PATCH AUTOSEL 5.9 11/23] habanalabs: put devices before driver removal Date: Sat, 12 Dec 2020 11:07:52 -0500 Message-Id: <20201212160804.2334982-11-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201212160804.2334982-1-sashal@kernel.org> References: <20201212160804.2334982-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ofir Bitton [ Upstream commit 5555b7c56bdec7a29c789fec27f84d40f52fbdfa ] Driver never puts its device and control_device objects, hence a memory leak is introduced every driver removal. Signed-off-by: Ofir Bitton Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay Signed-off-by: Sasha Levin --- drivers/misc/habanalabs/common/device.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/misc/habanalabs/common/device.c b/drivers/misc/habanalabs/common/device.c index 24b01cce0a384..39fa31d05d9cd 100644 --- a/drivers/misc/habanalabs/common/device.c +++ b/drivers/misc/habanalabs/common/device.c @@ -227,16 +227,16 @@ delete_cdev_device: static void device_cdev_sysfs_del(struct hl_device *hdev) { - /* device_release() won't be called so must free devices explicitly */ - if (!hdev->cdev_sysfs_created) { - kfree(hdev->dev_ctrl); - kfree(hdev->dev); - return; - } + if (!hdev->cdev_sysfs_created) + goto put_devices; hl_sysfs_fini(hdev); cdev_device_del(&hdev->cdev_ctrl, hdev->dev_ctrl); cdev_device_del(&hdev->cdev, hdev->dev); + +put_devices: + put_device(hdev->dev); + put_device(hdev->dev_ctrl); } /* @@ -1362,9 +1362,9 @@ sw_fini: early_fini: device_early_fini(hdev); free_dev_ctrl: - kfree(hdev->dev_ctrl); + put_device(hdev->dev_ctrl); free_dev: - kfree(hdev->dev); + put_device(hdev->dev); out_disabled: hdev->disabled = true; if (add_cdev_sysfs_on_err) -- 2.27.0