Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752892AbeABJaU (ORCPT + 1 other); Tue, 2 Jan 2018 04:30:20 -0500 Received: from mail-bl2nam02on0058.outbound.protection.outlook.com ([104.47.38.58]:60192 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752837AbeABJaB (ORCPT ); Tue, 2 Jan 2018 04:30:01 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Christian.Koenig@amd.com; Subject: Re: [PATCH] drm/ttm: optimize errors checking and free _manager when finishing To: "He, Roger" , Xiongwei Song , "airlied@linux.ie" Cc: "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" References: <20171231114024.5026-1-sxwjean@gmail.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: Date: Tue, 2 Jan 2018 10:29:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [2a02:908:1251:8fc0:4c6d:7233:b7e1:3b88] X-ClientProxiedBy: DB6PR0202CA0013.eurprd02.prod.outlook.com (10.169.218.23) To MWHPR12MB1309.namprd12.prod.outlook.com (10.169.205.21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bc46e199-2a46-43fc-5045-08d551c36439 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7153060);SRVR:MWHPR12MB1309; X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1309;3:H9L/z/guCD5tPonugdb31bf4smbspA4Uf62xZc1VaVnCmGgrCNehyBS620ouRWuOFQW2t4jKtHT8ZlBINaO9arh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TsqFLC5Y8IM8jhvisxHug6F/15HPMLljGbG9izDMt6SgX7IBy3nQd92HsiZQA5qOfiFb9Ie3tDYFfA6FTbDaBetk3EStJGrvCRzwBuV1vt0oiInMbotsjazlmuicWzrPkEJsOSv5RSZBAlnlYcT/IAIpSxinZ+QawI+CJZaY6YtCIHuJQAYfDP1/V71yF9CoQWVh65fNQmjHrCl03DZbKK1OYFpHtOjD17zz7ydKUisz6ozd/Fs4kj3qYVGclpcxX/Zgbhn3PhSM;4:1JE9YGDA6R3thdBLnp+QGbxNWI2D8uCM5PcqYOFk9BSMW97/nZkeSdbDV2erPJWKfi4YzT/VQdDmcoNjs1pXxL9S/oTtC0ElDC9uchzn/GVh6ZNtVYpilG50jIRZa2WlUlDa8kNV6AVu5PrHoc/7wdDLelTE6sPAVmaNw2eXPKRmns73HKXFoCk84zdK910nhIfJ2XbFIjMGm+vIggX3lJgqexIRJQS1yCgaKjt2tAfMMq3C6Hu1SMjcLd6i9ejI7MKlOFSe9d748Cyzg78VEGJ4W5jF+/jqdn0J5GRvXz4U18lEH5uemOJK7XJa1xKpnsVKbNlL4hHAMIPukBRiOnutNmlxQLzKa44KSuI2b8bz8NPEhCblz6uHOgQ+gZxh 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)(5005006)(8121501046)(10201501046)(3231023)(944501075)(93006095)(93001095)(3002001)(6055026)(6041268)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011);SRVR:MWHPR12MB1309;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:MWHPR12MB1309; X-Forefront-PRVS: 0540846A1D X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(39380400002)(396003)(346002)(39860400002)(376002)(366004)(13464003)(189003)(199004)(31686004)(72206003)(47776003)(6116002)(1706002)(68736007)(64126003)(53936002)(2906002)(83506002)(67846002)(106356001)(50466002)(478600001)(105586002)(36756003)(6486002)(52396003)(2501003)(2950100002)(6666003)(229853002)(65826007)(8676002)(53546011)(58126008)(54906003)(110136005)(81156014)(316002)(230700001)(97736004)(386003)(76176011)(65956001)(31696002)(8936002)(59450400001)(305945005)(7736002)(65806001)(25786009)(2486003)(52146003)(575784001)(39060400002)(86362001)(52116002)(23676004)(6246003)(5660300001)(81166006)(4326008);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR12MB1309;H:[IPv6:2a02:908:1251:8fc0:4c6d:7233:b7e1:3b88];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjEyTUIxMzA5OzIzOis2aXhHU1JudVFnQmJxQXpTVk1DK1VYRGlW?= =?utf-8?B?WXkxVzAydVRQWTRlK0ZIbmU2cXphQTlwT2poTTdNWm9mSmE3S1ZVNFJYTkJT?= =?utf-8?B?TFdrOFBRMXBrV2FLeHdMUVBvNnV1UCtjSU10ckFtdlk1T1BBcWU5Mit4TlRX?= =?utf-8?B?cm9mQXJtSmpzSnJiK3UxWDU5QytWNGRibVZRS1FHem1Ib1pWZ2xQQmd1ODc5?= =?utf-8?B?bUwwUTNwc3hxSXJmYi9RLzVJYjNGcGgvQkhwK293ay9aekR0SjdOazV3eGVk?= =?utf-8?B?VEROd0owcHhxSVcxdExMOG1Ka1F3WjNXbHB0RVEwa3I2OFJIbWU2YThLR1hj?= =?utf-8?B?cnk2Lys3YXU5aHF2emtneHZZUU54TlBFbzBZeTdtSDU5eGc2TlhQRFVxSFBv?= =?utf-8?B?VmtSNXl4L3dMVUhjbVpsM2U4UTBRRTJ5bitpMTk5RXFvSGJUeVRBQnVtZUtU?= =?utf-8?B?UGZVK3NZUjk3eGhJQWVIMnpMUHI5V08ydHd1S2NzM0NEZ3lycjFFWHVyNmhk?= =?utf-8?B?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xpG3krbjXt/YPbPsu8XxjKGeqoeRqF0JA9BBcJEuLKCy9uyZOVyECA8mPlxdz0YvHIDdcEhrV1skddt54FHYlY9J8NyfQTv6k2Dvr4JEANlU45oK9gb4y30DXAupGHm0FcYwAOskn1Y=;24:gWeFjz39pQoGvLpGUw2V/ToVbgRJJ27ibE5b22EHcJ4xiPOJdxVL96yuTJT+HT7B2xNhJ61+oqjEBEg3Eo6oNLFXfd9agiyHnlylHricRMo=;7:YuEvZyT6IjGAr0Ohx1I1Ex5EI1nWENZAMqywLCSuTa8t18MAM0jN7sUlR8Qg/x4hMH+9IJTJh4ybcFtvWZeQVgqqsM0ZudnPv3a020NUpxr0FVjOYHRiZPcOWUBdU51DiAtilvm9KjB2Cra0b7vEvbd8pthrHS8+kB4HRob74iYiFHaKlCp4pOT3l6F1a9melkvRcVgmzpvrqjePSLUgZyYFAb4Q20KIzwtlgQoruZVQDWqdio53uEAdBtTkaoeB SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1309;20:ZEVrHM28vVVvUmt1vUxSQqGqaEA+I1K/ClErWSid37tOBBdPXrHjDvraFKfy1s50TJVhJ+fn36cPNcH+gAJfwbqCGQj6VOuNQkU+fXdkZNkAlT8dD17zZVtWsG8IkpwKuODeZhvAXd8SE4zw5Yesac2jhL5b3uoNnwaq3su7cBpgjvHjyWjzXvBTzaRxS50Mpam/0gehsRIEXCZy+7KlOEEPiUF56JfrkwXPT9qChMsAjKKpD4Pivp3lPHsbDL/3 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jan 2018 09:29:56.7712 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bc46e199-2a46-43fc-5045-08d551c36439 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1309 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Am 02.01.2018 um 04:05 schrieb He, Roger: > > -----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. Yes, agree. Freeing it again in ttm_page_alloc_fini will actually double free the memory and probably cause some problems. Please refine the patch with only the additional error handling. Regards, Christian. > > > 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 >