From patchwork Tue Jan 2 03:05:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "He, Hongbo" X-Patchwork-Id: 10139901 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2A9C860362 for ; Tue, 2 Jan 2018 03:05:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1003527CAF for ; Tue, 2 Jan 2018 03:05:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01827286B4; Tue, 2 Jan 2018 03:05:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 45AFB27CAF for ; Tue, 2 Jan 2018 03:05:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CEDD2894C5; Tue, 2 Jan 2018 03:05:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0057.outbound.protection.outlook.com [104.47.38.57]) by gabe.freedesktop.org (Postfix) with ESMTPS id E461A894C5 for ; Tue, 2 Jan 2018 03:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=X/hvRFAG/Pd0o1r4vJJpovYA7wa991GOLdZkjtWfgIQ=; b=3Mdv8qofsqcRUpKPBiqjd2jjxd0NhjN0mDmuJNG1JYRQr+AtBDZE54jy+Mzhqs6LfgwILIoWzb+Chl3VR7f3A3EOJA7VWVo1aXEq+TOiEl3boH/UzC7EZzJPZ5PQMA/TXzqwkYHnm1GblTq6Q8Fwc1a8Ya6oXL6ihT8RGVdQth4= Received: from MWHPR1201MB0127.namprd12.prod.outlook.com (10.174.98.142) by CY4PR12MB1304.namprd12.prod.outlook.com (10.168.168.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.366.8; Tue, 2 Jan 2018 03:05:43 +0000 Received: from MWHPR1201MB0127.namprd12.prod.outlook.com ([10.174.98.142]) by MWHPR1201MB0127.namprd12.prod.outlook.com ([10.174.98.142]) with mapi id 15.20.0366.007; Tue, 2 Jan 2018 03:05:42 +0000 From: "He, Roger" To: Xiongwei Song , "Koenig, Christian" , "airlied@linux.ie" Subject: RE: [PATCH] drm/ttm: optimize errors checking and free _manager when finishing Thread-Topic: [PATCH] drm/ttm: optimize errors checking and free _manager when finishing Thread-Index: AQHTgiw4jOJwHqhHhEydtGmBttqpfKNf5gVQ Date: Tue, 2 Jan 2018 03:05:42 +0000 Message-ID: References: <20171231114024.5026-1-sxwjean@gmail.com> In-Reply-To: <20171231114024.5026-1-sxwjean@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Hongbo.He@amd.com; x-originating-ip: [116.228.147.241] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; CY4PR12MB1304; 7:0skl/v9PTSyiOdFPWnd4bu9ArpnV98bN5YxEIGD+Hng+NMOGzCSJ1GCTOU8l5KrCpKOrPhkNLJvJPnZDgByuud+ZFP8vb7Ix568HkI99n5eIrETN12Awhiis8T9wnXcSuKAflwT+g+VnJj69mn2rkdtkpmB1p29Ty5g8+mZHsUcjyioLs+T/PalrLFMpaPLdH3pdfGVgWTC8C2bKWsw4dcQAgUvRF49rhvzo2mJp5o33ulnoLNo/9tV1W7SuvO0G; 20:tFbyctg2aguYeJnJpLFiwhECT4RQz4gllcFa60a7HUzOh13Pexmn/fggDJFk79latUsyxtR8Da/ghzBYJhZtHf/kFXJx4ie4cnmDu1QvZ+gMJ9Nam/rCCVyZnZ2hRWX5y3Xfb1oj3MfR1AqU+lRFsFjgUSguCme/1TXty0DVgCJhsN+Iw4gjtiyyawCr7QMmSEyc3mQv8puocmNGrPa7bUZiLJtjHiZ6MmbrxtCx1azo+6mmaJYO+ZkrgbBFwfnz x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI; SCL:-1; SFV:NSPM; SFS:(10009020)(376002)(396003)(39380400002)(39860400002)(366004)(346002)(189003)(199004)(13464003)(3660700001)(3280700002)(6436002)(68736007)(76176011)(7696005)(53546011)(6506007)(2906002)(77096006)(105586002)(59450400001)(8936002)(55016002)(9686003)(33656002)(99286004)(81166006)(6116002)(2501003)(8676002)(5660300001)(3846002)(2950100002)(7736002)(106356001)(14454004)(66066001)(81156014)(72206003)(478600001)(305945005)(110136005)(74316002)(229853002)(4326008)(97736004)(54906003)(25786009)(86362001)(575784001)(102836004)(39060400002)(316002)(6246003)(53936002)(2900100001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1304; H:MWHPR1201MB0127.namprd12.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: c825a88f-a654-4c28-f96a-08d5518db608 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(3008032)(2017052603307)(7153060); SRVR:CY4PR12MB1304; x-ms-traffictypediagnostic: CY4PR12MB1304: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(767451399110)(217544274631240); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(3231023)(944501075)(6055026)(6041268)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123560045)(20161123564045)(6072148)(201708071742011); SRVR:CY4PR12MB1304; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:CY4PR12MB1304; x-forefront-prvs: 0540846A1D received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: VCTVy7a6kdr/foJGsW09Uxe4vv2DVGDzG1wxW+dxKs6DAWcUIESEVwjEnlJ5EJJeOZzfwORCPjKC4WZ/+8tIVw== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c825a88f-a654-4c28-f96a-08d5518db608 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Jan 2018 03:05:42.7667 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1304 Cc: "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP -----Original Message----- From: Xiongwei Song [mailto:sxwjean@gmail.com] Sent: Sunday, December 31, 2017 7:40 PM To: Koenig, Christian ; He, Roger ; airlied@linux.ie Cc: dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org Subject: [PATCH] drm/ttm: optimize errors checking and free _manager when finishing In the function ttm_page_alloc_init, kzalloc call is made for variable _manager, we need to check its return value, it may return NULL. In the function ttm_page_alloc_fini, we need to call kfree for variable _manager, instead of make _manager NULL directly. Signed-off-by: Xiongwei Song --- drivers/gpu/drm/ttm/ttm_page_alloc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) Thanks Roger(Hongbo.He) ttm_page_pool_init_locked(&_manager->wc_pool, GFP_HIGHUSER, "wc", 0); @@ -1034,13 +1038,17 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages) &glob->kobj, "pool"); if (unlikely(ret != 0)) { kobject_put(&_manager->kobj); - _manager = NULL; - return ret; + goto out_free_mgr; } ttm_pool_mm_shrink_init(_manager); return 0; +out_free_mgr: + kfree(_manager); + _manager = NULL; +out: + return ret; } void ttm_page_alloc_fini(void) @@ -1055,6 +1063,7 @@ void ttm_page_alloc_fini(void) ttm_page_pool_free(&_manager->pools[i], FREE_ALL_PAGES, true); kobject_put(&_manager->kobj); + kfree(_manager); _manager = NULL; } -- 2.15.1 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index b5ba6441489f..e20a0b8e352b 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -1007,6 +1007,10 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages) pr_info("Initializing pool allocator\n"); _manager = kzalloc(sizeof(*_manager), GFP_KERNEL); + if (!_manager) { + ret = -ENOMEM; + goto out; + } Seems we only need above here for this patch I think. The rest is no need, because ttm_pool_kobj_release will kfree _manager.