Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp7982442ioo; Fri, 3 Jun 2022 18:55:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3wM2oIIHo49lWIicQ0R6yuLpBylnxoCdeimukSGHZbTx0zhnotgJuxD7eQkquraIrV2ub X-Received: by 2002:a17:907:da1:b0:6fe:a1a5:36b9 with SMTP id go33-20020a1709070da100b006fea1a536b9mr11082924ejc.728.1654307743087; Fri, 03 Jun 2022 18:55:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654307743; cv=none; d=google.com; s=arc-20160816; b=bd9IhLfuN2x6O05sRkoM64e2NyI4snhITPYLx/DM8v9YUOv4obUICjn7K7QZN94ykI dEVdRZXHgOn+2zQUdeO/kNff4c9onftf0TCHTGeiltq+xEDpSVLTR2oi5pJjKslQZ0Qi 37gYbewxIHcudq1RAB84XczML5IU5H/l1xiAgoTtuo9mgnsI5osVLn7oWhtKMpJ5zUsY 0C2ns+24XkeSs1T3M3z/J3bdQ/SwCk6iB038W+h2YS1alTP5IROEIWE/JkuaLpi0q8w4 jxILAVbDOhzETgSB+XfSDI2HJnYO57euMaB13JgzxuusT9SBHyvTtrMyG10E4ERfr7D4 k1uQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=krZbVlK3Z1/IgWXud2lUTsTQaV8i8IJv68G2uGF/JVY=; b=HzSJKDfB46R0kcYzFVBk97Sq7f96PyGhyaFvHg7TfSgojFtFuWrJj+7kPmkLDeNPj1 GkDcmZZLVKub95WxmRP6WMh5HmuiwbXa0zX6UvCNcZLEAfLaQNcYUIgubbFYyknPDMJk 0cZkAW4e/sWOIhdyRc7R6CB6s8py8CC1FgOJWJ6imMiocvUk6cbF/FOYGWpuXkjpMLI5 syQXjaOm/UzxAaoUp4CTE8FWeDl0zU5krfaggagCHmYcCt89qETompFwPU1ZoS1SOEG5 /h6m2npPti7xrhGrJl/ra++KAG4yaQwNQ4Uri2kz5Q+9U+ayuswn+cb+/7mxyLWC4tRC ox8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Nk/xoewy"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp17-20020a170906c15100b0070ef64a5880si3527189ejc.454.2022.06.03.18.55.09; Fri, 03 Jun 2022 18:55:43 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Nk/xoewy"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239308AbiFBVBS (ORCPT + 99 others); Thu, 2 Jun 2022 17:01:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239291AbiFBVBN (ORCPT ); Thu, 2 Jun 2022 17:01:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4EDDF34BB6 for ; Thu, 2 Jun 2022 14:01:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654203671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=krZbVlK3Z1/IgWXud2lUTsTQaV8i8IJv68G2uGF/JVY=; b=Nk/xoewyXr2BLsx2HlTov3XvRYkqe3fSUtJN8pj5UNVkG7i8/tP49hweeX/gBM7QnAlZOR aP6zASGqbkGrr+e8T5UFFPYboaO+wrJpsj3tZMMJq3MdWezHkwN8owh6z4nexh/mhzqJsL i5eswOb1lF5UyOBXIAbE21o9wS5dKd0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-55-dLxcq075PHG6Mmz-Sz_acg-1; Thu, 02 Jun 2022 17:01:09 -0400 X-MC-Unique: dLxcq075PHG6Mmz-Sz_acg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B739F3C10142; Thu, 2 Jun 2022 21:01:08 +0000 (UTC) Received: from emerald.redhat.com (unknown [10.22.34.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E6821410F36; Thu, 2 Jun 2022 21:01:08 +0000 (UTC) From: Lyude Paul To: amd-gfx@freedesktop.org Cc: Harry Wentland , Leo Li , Rodrigo Siqueira , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Hersen Wu , Roman Li , Thomas Zimmermann , Fangzhi Zuo , Nicholas Kazlauskas , amd-gfx@lists.freedesktop.org (open list:AMD DISPLAY CORE), dri-devel@lists.freedesktop.org (open list:DRM DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 3/3] drm/amdgpu/dm: Drop != NULL check in dm_mst_get_pbn_divider() Date: Thu, 2 Jun 2022 17:00:56 -0400 Message-Id: <20220602210056.73316-4-lyude@redhat.com> In-Reply-To: <20220602210056.73316-1-lyude@redhat.com> References: <20220602210056.73316-1-lyude@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 A lot of code in amdgpu seems to sprinkle in if (foo != NULL) … Checks pretty much all over the place, many times in locations where it's clear foo (whatever foo may be) should never be NULL unless we've run into a programming error. This is definitely one of those places, as dm_mst_get_pbn_divider() should never be getting called with a NULL dc_link pointer. The problem with this code pattern is that many times the places I've seen it used in amdgpu have no real error handling. This is actually quite bad, if we try to avoid the NULL pointer and instead simply skip any code that was expecting a valid pointer - we're already in undefined territory. Subsequent code we execute may have expected sideaffects from the code we skipped that are no longer present, which leads to even more unpredictable behavior then a simple segfault. This could be silent errors or even just another segfault somewhere else. If we simply segfault though, that's not good either. But unlike the former solution, no subsequent code in the kernel thread will execute - and we will likely even get a clear backtrace from the invalid memory access. Of course, the preferred approach is to simply handle the possibility of both NULL and non-NULL pointers with nice error handling code. However, that's not always desirable or even possible, and in those cases it's likely just better to fail predictably rather than unpredictably. This code is a nice example of that - if link is NULL, you'll return a PBN divisor of 0. And thus, you've simply traded in your potential segfault for a potential divide by 0 error. This was something I actually managed to hit while working on the legacy MST removal work. Signed-off-by: Lyude Paul --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c index 1259f2f7a8f9..35c7def8f2bd 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c @@ -537,9 +537,6 @@ void amdgpu_dm_initialize_dp_connector(struct amdgpu_display_manager *dm, int dm_mst_get_pbn_divider(struct dc_link *link) { - if (!link) - return 0; - return dc_link_bandwidth_kbps(link, dc_link_get_link_cap(link)) / (8 * 1000 * 54); } -- 2.35.3