Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1145008ybt; Sat, 20 Jun 2020 02:14:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiIOKqtY6g6uMNnRePEYohDvKeiUkFb8pAwDheGo36/hKiaiQydt8NBW/yu7x8JUBMQqXx X-Received: by 2002:aa7:d987:: with SMTP id u7mr1631132eds.116.1592644460810; Sat, 20 Jun 2020 02:14:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592644460; cv=none; d=google.com; s=arc-20160816; b=T4zll0zi9lKGmYX9sMeIctkm13Q8BShlR9knrB9pR+IqxuGUVpZni9NsxUTw7pzFfr 006+G+8j76d16QqPYUOwNhQfA5AuKMbaZlcRMF0FwzJk/Gd8DmogMVxnFy7RBP3CdHHl UZGgWMaaUKYG5eTwPO5HRBhGZKYRvvioC7kPwZ+v7/hbjgONPwxPSNoRdIXpn5koHuqg yW7TMcPpsnUeVxjkXUyRLOGHGXsQSbGgDGXz/GwUswa0GQfTKcIXcfjlub5s2mMyN3J0 GlTELlxEYUT6c5ytTPFnhxhS8r2xt/CeISuIK5IAiURMjHNRt9XNbiHidbONB9WMzabK X59w== 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=LxgrqrtlS/TxTXkztAg3xZY9MpQ4bN+M8hh1dNds49k=; b=koorIN3wvWVx6dfhcpS/ESmI6YGyVee1JnRUgWdHuOp3KrqlA3RouJq4G7c0H55Kq2 RZcG8M9wcm861xoTve9GL1zi5uTzmAhWYP5As4h51fsfY78RotGe+mf/JWwo/xIbaSLv VBQFeQ1oRTXy0ZvkhYn/vY7ww1lX7L0iK6BpY77NG/ijCAV4Tev+b3K9MhnGsVerBI7p yoUP2BXrMXn8mX+F3KscBDiYcztzpQazvjZMbyOPXK7GQWSMGdTGyqs25s9PUmRLsU2U b/1vMAl/WG84LGYcrHMeMThGS5yBFtVwMYChzk922nQNaXFUzdUxeP6WbGRLCghi52C/ 5x+w== 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 i24si5384541eds.397.2020.06.20.02.13.58; Sat, 20 Jun 2020 02:14:20 -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 S1727826AbgFTJMN (ORCPT + 99 others); Sat, 20 Jun 2020 05:12:13 -0400 Received: from mail-m17613.qiye.163.com ([59.111.176.13]:33920 "EHLO mail-m17613.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726533AbgFTJMM (ORCPT ); Sat, 20 Jun 2020 05:12:12 -0400 Received: from njvxl5505.vivo.xyz (unknown [157.0.31.125]) by mail-m17613.qiye.163.com (Hmail) with ESMTPA id 03FEF4815C6; Sat, 20 Jun 2020 17:11:59 +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 v3] drm/amd: fix potential memleak in err branch Date: Sat, 20 Jun 2020 17:11:52 +0800 Message-Id: <20200620091152.11206-1-bernard@vivo.com> X-Mailer: git-send-email 2.17.1 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgYFAkeWUFZS1VLWVdZKFlBSE83V1ktWUFJV1kPCR oVCBIfWUFZTB8dQ0pISUxOSk5IVkpOQklNT09ISkJJSE5VEwETFhoSFyQUDg9ZV1kWGg8SFR0UWU FZT0tIVUpKS0hKTFVKS0tZBg++ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OTI6Sww5MDgxPwIySCg0MRUX ITwKCUxVSlVKTkJJTU9PSEpCTU9JVTMWGhIXVRkeCRUaCR87DRINFFUYFBZFWVdZEgtZQVlKTkxV S1VISlVKSU5ZV1kIAVlBSUhJQzcG X-HM-Tid: 0a72d0ffb7d393bakuws03fef4815c6 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 V2: *remove duplicate kobject_put in kfd_procfs_init. Link for V1: *https://lore.kernel.org/patchwork/patch/1258608/ --- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c index d27221ddcdeb..0e0c42e9f6a3 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -428,6 +428,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