Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1716260rwb; Thu, 17 Nov 2022 00:29:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf4RRMRJFDZHAKmYlDsIfeeOEqoWdBTatvjuoE7ZLaWMmlpAlIhR08zqaOS6EeXGovt4eFuZ X-Received: by 2002:a17:903:12d3:b0:186:a394:aef7 with SMTP id io19-20020a17090312d300b00186a394aef7mr1781326plb.79.1668673757113; Thu, 17 Nov 2022 00:29:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668673757; cv=none; d=google.com; s=arc-20160816; b=y5c0RVqd4QfhXe2E+8quLULyIVpz8F/7xw/KJLXRX5CJJHduxL8L80p1nABfW6oamO Nuuod/vsKKOV1Vi+OilU1QN6+v6U9noqm9U7l5eNuTPOPRYAycQJfgraQYOxvFM41/FK K1BCdhhW+IXhh9D9PdaMuhWLfCI1lVmnxcUEBcZr21wMhgksOXXt8xBcb/WxdszX4iM1 OHz9b/9/+0QU4/VpwfCqLZ6lZPX1qDMLDwGxCk8Xr9j9iqXd2OuxxD0nslUOh/5Z0QOL NL86WhpN6Y7VKpUCFffdgycqzVQN7S+xclPhLXndxruW6ux8fxUmr1keIl1ZG0Lytdpc 0uWA== 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=MmmCytSuM+XJqPpHqYMSucTJdz0ireEqegO1dhH1nnw=; b=NGE8mZ6OA42p4VqX1oYdj01iWsmBAqQc+Gfnin6UgsNmtbzv1V5i9rbNcBobRTR5fX 4Rbsn68EVQ3/AKqXvbavfygFl77sJMp885AbU/qwgFVXN/Cm/z80Nuz3klu5OKpL9JMw 7xBhVw9FtVxEiNoVTqYKBzjstoY52fNurWtCdoHa4AjW8JP+SRrUixhBWbz7+eR4HVn3 e6lPx9s1y+jZLqslUO10AIeD/M6eN9Kr254loSm5Jx0Hw4ttTGK4r+KN0JOv4gku66Ze 9zv35vLhE5rX92QnnvYZQRQizBS/JazEdQayPpQjr3AUI1v1Q+bmiJpawWaS/DN9dBG4 u6Dw== 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 cp8-20020a056a00348800b0053e9c7939basi294866pfb.188.2022.11.17.00.29.04; Thu, 17 Nov 2022 00:29:17 -0800 (PST) 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 S239370AbiKQHdK (ORCPT + 91 others); Thu, 17 Nov 2022 02:33:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239367AbiKQHdI (ORCPT ); Thu, 17 Nov 2022 02:33:08 -0500 Received: from cstnet.cn (smtp23.cstnet.cn [159.226.251.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E38EA6DCFC for ; Wed, 16 Nov 2022 23:33:06 -0800 (PST) Received: from localhost.localdomain (unknown [124.16.138.125]) by APP-03 (Coremail) with SMTP id rQCowAD3_8Or43VjaDtaCQ--.57293S2; Thu, 17 Nov 2022 15:33:00 +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, nicholas.kazlauskas@amd.com, roman.li@amd.com, aurabindo.pillai@amd.com, Jerry.Zuo@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: rewrite the check for mods Date: Thu, 17 Nov 2022 15:32:58 +0800 Message-Id: <20221117073258.21214-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: rQCowAD3_8Or43VjaDtaCQ--.57293S2 X-Coremail-Antispam: 1UD129KBjvJXoW7ZFW5Cr45Kr1kWr1UWF4fGrg_yoW8GF1Dpr 4xGF1DX34vva1Iqa4UAF1rZFWa9a4xGrWjkrWUCw1qqw15trZ8WryYkF9Ygrs7WFW8u343 tFy7J3y7ZF1qvF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkE14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1I6r4UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628v n2kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F4 0E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_Wryl IxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxV AFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j 6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUq38 nUUUUU= 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 When the *mods is NULL, it should be better to return error immediately, rather than continue with redundant operations. Signed-off-by: Jiasheng Jiang --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c index e6854f7270a6..05efc76b2226 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c @@ -638,11 +638,14 @@ static int get_plane_modifiers(struct amdgpu_device *adev, unsigned int plane_ty return 0; *mods = kmalloc(capacity * sizeof(uint64_t), GFP_KERNEL); + if (!*mods) + return -ENOMEM; + if (plane_type == DRM_PLANE_TYPE_CURSOR) { add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_LINEAR); add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_INVALID); - return *mods ? 0 : -ENOMEM; + return 0; } switch (adev->family) { @@ -671,9 +674,6 @@ static int get_plane_modifiers(struct amdgpu_device *adev, unsigned int plane_ty /* INVALID marks the end of the list. */ add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_INVALID); - if (!*mods) - return -ENOMEM; - return 0; } -- 2.25.1