Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp299235rwb; Mon, 26 Sep 2022 19:20:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM549IJjzDzCNVymF7hw/mIppBudVaiALfrmUPhPpNz2m5hVLkUZgPkBvM8eNMDk1IcKNuY7 X-Received: by 2002:a17:90b:4fc8:b0:202:a340:3594 with SMTP id qa8-20020a17090b4fc800b00202a3403594mr1920327pjb.149.1664245206137; Mon, 26 Sep 2022 19:20:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664245206; cv=none; d=google.com; s=arc-20160816; b=Q92hlG27r3f2wkuzjQkr90e9mwIBJudolVxsAROixdnGIovgYKNTxvlSNZLQaPuUyJ eTamnM6Za3RWl2jtSqDIFXpqbxKS+iCD4QGP8KG4joFr6QRxug3WcEV3L47XBQCrXAXM jpvk2Tn8dGynFXsWZU17WTz9zUV/XiGH6FG/e+MBhYOkY8v+B6khRPlZsV51uZM9meC4 Opm+eYPcWlob+pQzoJmHAo1R6qTUvZPdmEIiP4Q56WfyadJq9PV7ZTvCXNpBffpc5PY9 0dHxRPMau45k0w3DOG+OzIUvXeUSXPuwupdCzTBO4d5mW3JsSmSyH4EbyOhlRv+LF0lg +u9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Cr79RzFibVQ6og7d+FaiCnapsejqltlSPVL69eiwT4o=; b=HYmyW5AtyUC3wyXgjZhlkry0DekgZTrnIRpABzKOJIqofsTOct0Ji27sinEV54+s9i h2oo38dMCpN1riC7qrQQXqkCaAtNetUh5hiCRfiWZ8w9WAl0Sh3gXR5Vcii1zQqBzK8w dN51YfMiXRJ++4sgpQvf7N1J9nFQB+oM87110DeiDS+WdaSpZcjLOuKoVJH4k8wUbuh8 Jqty8nQ4ytw6UxyZzIH3EYkgz1KlirQvqn7IyBXfsyz+ixNpn1/bF35LdulhiX2bEv5N csVuWOlY4nVo/oieEd5yAzGJgbMAMKyFBUuEk+68JWK51/ENSVr0VReQx2Pjem1bPcqk wHvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e14-20020a17090301ce00b00176e9de1f46si440337plh.154.2022.09.26.19.19.54; Mon, 26 Sep 2022 19:20:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229582AbiI0CQY (ORCPT + 99 others); Mon, 26 Sep 2022 22:16:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbiI0CQW (ORCPT ); Mon, 26 Sep 2022 22:16:22 -0400 Received: from cstnet.cn (smtp21.cstnet.cn [159.226.251.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D7E85578A2 for ; Mon, 26 Sep 2022 19:16:20 -0700 (PDT) Received: from localhost.localdomain (unknown [124.16.138.125]) by APP-01 (Coremail) with SMTP id qwCowACnrY3tXDJj8U5dAg--.19578S2; Tue, 27 Sep 2022 10:16:13 +0800 (CST) From: Jiasheng Jiang To: harry.wentland@amd.com, sunpeng.li@amd.com, Rodrigo.Siqueira@amd.com, alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch, aurabindo.pillai@amd.com, Jerry.Zuo@amd.com, Alvin.Lee2@amd.com, dillon.varone@amd.com, Martin.Leung@amd.com Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH] drm/amd/display: Add check for memory allocation Date: Tue, 27 Sep 2022 10:16:12 +0800 Message-Id: <20220927021612.31815-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: qwCowACnrY3tXDJj8U5dAg--.19578S2 X-Coremail-Antispam: 1UD129KBjvJXoW7CFW5Cr4fJrykGF1xJFWxXrb_yoW8Aw1Upa 10y34YgwsrJF4jqry7JF4UWF4rAa4F9FyrCrZ8A3sIva47tr4rZF1YqF1qyan5KFWUCr17 Ja1jgr43uFnFkrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9j14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r 4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2Wl Yx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbV WUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7Cj xVA2Y2ka0xkIwI1lc2xSY4AK67AK6r4UMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4 AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE 17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMI IF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4l IxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvf C2KfnxnUUI43ZEXa7VUb9NVDUUUUU== X-Originating-IP: [124.16.138.125] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As kzalloc and dm_helpers_allocate_gpu_mem can return NULL pointer, it should be better to check the return value and return error. Moreover, the return value of dcn32_clk_mgr_construct should be checked by cascade. Fixes: 265280b99822 ("drm/amd/display: add CLKMGR changes for DCN32/321") Signed-off-by: Jiasheng Jiang --- .../drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c index c6785969eb1a..3dc04d780fbf 100644 --- a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c +++ b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c @@ -718,7 +718,7 @@ static struct clk_mgr_funcs dcn32_funcs = { .is_smu_present = dcn32_is_smu_present, }; -void dcn32_clk_mgr_construct( +int dcn32_clk_mgr_construct( struct dc_context *ctx, struct clk_mgr_internal *clk_mgr, struct pp_smu_funcs *pp_smu, @@ -779,11 +779,19 @@ void dcn32_clk_mgr_construct( clk_mgr->smu_present = false; clk_mgr->base.bw_params = kzalloc(sizeof(*clk_mgr->base.bw_params), GFP_KERNEL); + if (!clk_mgr->base.bw_params) + return -ENOMEM; /* need physical address of table to give to PMFW */ clk_mgr->wm_range_table = dm_helpers_allocate_gpu_mem(clk_mgr->base.ctx, DC_MEM_ALLOC_TYPE_GART, sizeof(WatermarksExternal_t), &clk_mgr->wm_range_table_addr); + if (!clk_mgr->wm_range_table) { + kfree(clk_mgr->base.bw_params); + return -ENOMEM; + } + + return 0; } void dcn32_clk_mgr_destroy(struct clk_mgr_internal *clk_mgr) -- 2.25.1