Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1135713ybt; Sat, 20 Jun 2020 01:58:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZQczO/g7RJ4d4r/jv+pcED+ZdRl09ZfNS03IE1jgoF2iiz07VSLWzljP39HrFnHXxC6GQ X-Received: by 2002:a17:906:689:: with SMTP id u9mr6973059ejb.13.1592643520040; Sat, 20 Jun 2020 01:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592643520; cv=none; d=google.com; s=arc-20160816; b=B+pTSwcd7LnRSJ3HAU0TXde3cNNZNID1ds89TE7p6CgL++tZ09xC+718513rkVu9ha Hw3kXE2wlKn9rdHBFWeXIW+SHUTgLPtBD5d174sLocBM3DqoL07/pBWtvRDjj5qkEAQ9 cOZnw2famgIclYLZXSR26dgVRFrpK4tosackbsTYmCCF7niJSoki9yZrSNDijrkjro2r 3YjqXuLGPNsdnYBLt/iRvJ3wkBcKe+bWMjBaROD4BqoJEE1h7Er37rff75q+8LuFagwm sKub6MdAtNJOimvUVCABTl7T6QDRbjSz/daj391zR75KvUlkc780wGum+Ojb66S075e+ 17Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=0d8/ZoQCxU2OhB3WlgpZQ6xs2wt21D7t7E2y4wmJA3s=; b=LL2UiYjG0aEgLEBCsllphD8BAbE9gGzO+AmpfqOlVm1k3XdFYXxUo3yfEz39KT8Epq 4nA2Ec0jueCjAvZfvmdOrX+HJ1q2DxI8HHkgNeBa7uo/z2NgPqCP4spvlNl7s5Tl4RS3 xqCKSxyBqiWEzgMYdR++neIyJRAmANKK6c1pmUeFTMXPunu477FVhaYuVAPHGy/CqwS6 GntIPuKvjPlFpYe6X9s7CkgO66Rwy+Bblvpx/zbLHa0ZKoEitqaSas4L+xNeA0w6gd2C r0wKWB5HnDDMSwIaaDc5ehhPXCAqSeVs4i3kjgdy6QdnY7EhNcvl9Lq8gNAGltAFQDex BOTw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gh7si5324466ejb.81.2020.06.20.01.58.05; Sat, 20 Jun 2020 01:58:40 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727798AbgFTIyT (ORCPT + 99 others); Sat, 20 Jun 2020 04:54:19 -0400 Received: from mail-m17613.qiye.163.com ([59.111.176.13]:1572 "EHLO mail-m17613.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726838AbgFTIyS (ORCPT ); Sat, 20 Jun 2020 04:54:18 -0400 Received: from njvxl5505.vivo.xyz (unknown [157.0.31.125]) by mail-m17613.qiye.163.com (Hmail) with ESMTPA id 4787E481E89; Sat, 20 Jun 2020 16:54:13 +0800 (CST) From: Bernard Zhao To: Felix Kuehling , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , David Airlie , Daniel Vetter , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com, Bernard Zhao Subject: [PATCH v2] drm/amd: fix potential memleak in err branch Date: Sat, 20 Jun 2020 16:54:06 +0800 Message-Id: <20200620085407.21922-1-bernard@vivo.com> X-Mailer: git-send-email 2.17.1 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgYFAkeWUFZS1VLWVdZKFlBSE83V1ktWUFJV1kPCR oVCBIfWUFZSxhKGUxKTUxCSx9DVkpOQklNT0hJTkhPQ0xVEwETFhoSFyQUDg9ZV1kWGg8SFR0UWU FZT0tIVUpKS0hKTFVKS0tZBg++ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Ohg6Iyo5UTg1CQI*Cz0UITAi PC0wCTlVSlVKTkJJTU9ISU5IQ0JCVTMWGhIXVRkeCRUaCR87DRINFFUYFBZFWVdZEgtZQVlKTkxV S1VISlVKSU5ZV1kIAVlBSU5PSDcG X-HM-Tid: 0a72d0ef74b893bakuws4787e481e89 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function kobject_init_and_add alloc memory like: kobject_init_and_add->kobject_add_varg->kobject_set_name_vargs ->kvasprintf_const->kstrdup_const->kstrdup->kmalloc_track_caller ->kmalloc_slab, in err branch this memory not free. If use kmemleak, this path maybe catched. These changes are to add kobject_put in kobject_init_and_add failed branch, fix potential memleak. Signed-off-by: Bernard Zhao --- Changes since V1: *Remove duplicate changed file kfd_topology.c, this file`s fix already applied to the main line. --- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c index d27221ddcdeb..5ee4d6cfb16d 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -124,6 +124,7 @@ void kfd_procfs_init(void) if (ret) { pr_warn("Could not create procfs proc folder"); /* If we fail to create the procfs, clean up */ + kobject_put(procfs.kobj); kfd_procfs_shutdown(); } } @@ -428,6 +429,7 @@ struct kfd_process *kfd_create_process(struct file *filep) (int)process->lead_thread->pid); if (ret) { pr_warn("Creating procfs pid directory failed"); + kobject_put(process->kobj); goto out; } -- 2.17.1