Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753799AbeABDFr (ORCPT + 1 other); Mon, 1 Jan 2018 22:05:47 -0500 Received: from mail-bl2nam02on0055.outbound.protection.outlook.com ([104.47.38.55]:5457 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753279AbeABDFq (ORCPT ); Mon, 1 Jan 2018 22:05:46 -0500 From: "He, Roger" To: Xiongwei Song , "Koenig, Christian" , "airlied@linux.ie" CC: "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" 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 x-microsoft-antispam-message-info: VCTVy7a6kdr/foJGsW09Uxe4vv2DVGDzG1wxW+dxKs6DAWcUIESEVwjEnlJ5EJJeOZzfwORCPjKC4WZ/+8tIVw== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT 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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: -----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(-) 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. 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