Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp232023pxj; Fri, 28 May 2021 02:37:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLigkbS8BFsof9g84tfgdzXhWFBj6I6TBM/ywal2ucbVGb2Uzvim4m3f8AbI6H5Kz0IL06 X-Received: by 2002:a6b:ec03:: with SMTP id c3mr6435257ioh.103.1622194670737; Fri, 28 May 2021 02:37:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622194670; cv=none; d=google.com; s=arc-20160816; b=gNFNkvM+PUCo81L5eO9FVBWLBU9aapNQeD70CzijzCyfwrhuCo+lDlWwFTDeV+eLW3 ykDvQlTzopluRhb4R/UpgdtTPnhWfaYvVUWXhA0K23c1enEMEaw/16tjQ2vlVnHI0rk0 hJvvZzAK2tee97lYF7UKq7EY8l3EgCIMsrqqb8DaX/ZoZpQdRgXgj+FScywIK7k2Rze7 epSuiCBNh1iQwWM2EW0IvSNswl/caKUK6C8q4fl/sopD1DnqT6Jr72M+CoU0t1+WrhUt +eMBvjcZ/khLPBITbuzsluDpTCS9G/SVHnRX+mk7tfKAtmZ2pcoEdUjysOgRR8nIYFwC WJgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject; bh=6RZR5m60PFCokWsOQrkpBS/KDgoFs3QXOsUP+ei9Y1A=; b=0ANm+bTzBf0XwJO5jzCVN/6pBm8tIhpXkqysjJc/HgB8wpifu6RXdGH3wMBXsOgau6 /wFpTgzrmsJGdE56PAfsHH5fq2nLZsIhSYEQDHUn/aoxhoxAnH2KPpcrzhXtD/evbG7X zwG9g2+4i3KEkPjvx/pjKRL0fgSc3c7HoK00xt85Eb1Q/+s26cvbTUXHoVntgn6qgBGQ 8if6XGcUl+XRltFif0PkNZ6GtMQVTpFkimWj6THqPhp6tG7ElShza+xj1Epf67mffK2H Gg2Z8fhBdB4GvZSHsdPBoMuuRKYdx0jJJtekag7dyoyOefi7VuvGphlOo2oHPs5M1VeB BwwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b12si5076929jag.53.2021.05.28.02.37.37; Fri, 28 May 2021 02:37:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229911AbhE1Jii (ORCPT + 99 others); Fri, 28 May 2021 05:38:38 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:2333 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229774AbhE1JiV (ORCPT ); Fri, 28 May 2021 05:38:21 -0400 Received: from dggeml711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Frzwm4fBvz1BFYK; Fri, 28 May 2021 17:32:08 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggeml711-chm.china.huawei.com (10.3.17.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Fri, 28 May 2021 17:36:44 +0800 Received: from [127.0.0.1] (10.174.177.72) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 28 May 2021 17:36:44 +0800 Subject: Re: [PATCH 1/1] drm/i915/hdcp: Simplify code in intel_hdcp_auth_downstream() To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Daniel Vetter , intel-gfx , dri-devel , linux-kernel References: <20210527090421.9172-1-thunder.leizhen@huawei.com> <87sg28a3xg.fsf@intel.com> From: "Leizhen (ThunderTown)" Message-ID: <86f64463-87df-9e62-a5ea-f411fcb54c19@huawei.com> Date: Fri, 28 May 2021 17:36:43 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <87sg28a3xg.fsf@intel.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.72] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/5/27 18:04, Jani Nikula wrote: > On Thu, 27 May 2021, Zhen Lei wrote: >> If intel_hdcp_validate_v_prime() has been successful within the allowed >> number of tries, we can directly call drm_dbg_kms() and "goto out" without >> jumping out of the loop and repeatedly judging whether the operation is >> successful. This can help us reduce an unnecessary if judgment. And it's >> a little clearer to read. > > Generally I think the "happy day scenario" should be at the topmost > indentation level and not buried in the ifs with a goto exit. for (xxx) { if (a == b) return found; } At least this way of writing is common. > > BR, > Jani. > >> >> No functional change. >> >> Signed-off-by: Zhen Lei >> --- >> drivers/gpu/drm/i915/display/intel_hdcp.c | 24 ++++++++++------------- >> 1 file changed, 10 insertions(+), 14 deletions(-) >> >> diff --git a/drivers/gpu/drm/i915/display/intel_hdcp.c b/drivers/gpu/drm/i915/display/intel_hdcp.c >> index d8570e14fe60..c32a854eda66 100644 >> --- a/drivers/gpu/drm/i915/display/intel_hdcp.c >> +++ b/drivers/gpu/drm/i915/display/intel_hdcp.c >> @@ -663,13 +663,13 @@ int intel_hdcp_auth_downstream(struct intel_connector *connector) >> >> ret = shim->read_ksv_fifo(dig_port, num_downstream, ksv_fifo); >> if (ret) >> - goto err; >> + goto out; >> >> if (drm_hdcp_check_ksvs_revoked(&dev_priv->drm, ksv_fifo, >> num_downstream) > 0) { >> drm_err(&dev_priv->drm, "Revoked Ksv(s) in ksv_fifo\n"); >> ret = -EPERM; >> - goto err; >> + goto out; >> } >> >> /* >> @@ -680,20 +680,16 @@ int intel_hdcp_auth_downstream(struct intel_connector *connector) >> ret = intel_hdcp_validate_v_prime(connector, shim, >> ksv_fifo, num_downstream, >> bstatus); >> - if (!ret) >> - break; >> - } >> - >> - if (i == tries) { >> - drm_dbg_kms(&dev_priv->drm, >> - "V Prime validation failed.(%d)\n", ret); >> - goto err; >> + if (!ret) { >> + drm_dbg_kms(&dev_priv->drm, >> + "HDCP is enabled (%d downstream devices)\n", >> + num_downstream); >> + goto out; >> + } >> } >> >> - drm_dbg_kms(&dev_priv->drm, "HDCP is enabled (%d downstream devices)\n", >> - num_downstream); >> - ret = 0; >> -err: >> + drm_dbg_kms(&dev_priv->drm, "V Prime validation failed.(%d)\n", ret); >> +out: >> kfree(ksv_fifo); >> return ret; >> } >