Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2491164pxj; Mon, 31 May 2021 03:37:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyt7BZncDXI3Tf53PiyNm0J8D9GL3z115kExHchSkQwJpTPnBkiViemf4E1hJWqfNEtaBZZ X-Received: by 2002:a17:906:b10e:: with SMTP id u14mr21886682ejy.546.1622457473263; Mon, 31 May 2021 03:37:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622457473; cv=none; d=google.com; s=arc-20160816; b=ZUcVaruztZFeMQLfcrefhzGuKKFWC6YvGKEOP95Nbgdi2NF9+JkbqaUwwHEqZmIj5F UeA7lfLYqja1DCsoX/eSp0LtCwD2VJE9ElU82kYnj/W8t2vgcN3dBnyJQaUBRjeF/IYE UKzWAgGWoeVIrdJVx0dV45Es38G6WgiZob4bqSL4WvrquZW0NykZorJOxF6pt6C/l95I FcYCFB4kdFWWZ7+Pvx+gnuiSDjjXdO/dLyANnoFwY3FdJSK/CAj8Q2DPMWnqsJA7OTLm OTXRi4i+NvQeYHf5CDwQnPE8J4s83OC4pHJ2/bhZ9Tht4wBf/huFwO8IrtRgZOD43Z6X LlTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :organization:in-reply-to:subject:to:from:ironport-sdr:ironport-sdr; bh=hUKMC5XwflAh/+Y4RhDHPdIYp/3kWs5YnPXaWozb4qI=; b=QFqCjYNv1ZVQzHKg7JyVaqaU5Wlk2tGo1Kq/AqRrKrYF3Gt6wombshgjERn4w0IgKo cS5yvXXKwlwYVEUP/TRjdsjQVkdIK/sf0cTO8j7oDvF6S658WNSh+Rostryv925YSRZo djyCwATr68YME9CP/R2Tm77RG43r50dwmTGz7beyqQS0BulfnOoyxn1dofNPA+8HWSIX YKY1RzOVaIC+EFbLFJBEe2BBO6BMkar6oUItJ0EMcUA9IOpmq06ZA5bHlBcfxa06QeCD BxARtM46ac927vj4wa/EhN3Wg4EA+u7dXgfTRWe0vGrmCg04sixSvnuYJ4QERuavZMWg 2/ag== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a16si6717507eds.411.2021.05.31.03.37.30; Mon, 31 May 2021 03:37:53 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231228AbhEaKh7 (ORCPT + 99 others); Mon, 31 May 2021 06:37:59 -0400 Received: from mga03.intel.com ([134.134.136.65]:19934 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230518AbhEaKh4 (ORCPT ); Mon, 31 May 2021 06:37:56 -0400 IronPort-SDR: fUlbuzYPBUU6lWEh/uwVu0Ot5LSdrryVd68ibTLk2s9XQIh3vihv9fto9cknlD/PsSQVuQeG9c 2ff08evH+UnA== X-IronPort-AV: E=McAfee;i="6200,9189,10000"; a="203372104" X-IronPort-AV: E=Sophos;i="5.83,236,1616482800"; d="scan'208";a="203372104" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2021 03:36:15 -0700 IronPort-SDR: HtVCOtOiT+hoRPoQF93NTuFq5tj2wMUpN+om1cuqCAjxvjgzyh/V9aoQDSIXheVSYSJEz7VgFm 6QFytasDk19Q== X-IronPort-AV: E=Sophos;i="5.83,236,1616482800"; d="scan'208";a="478865479" Received: from masayag-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.52.77]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2021 03:36:12 -0700 From: Jani Nikula To: "Leizhen \(ThunderTown\)" , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Daniel Vetter , intel-gfx , dri-devel , linux-kernel Subject: Re: [PATCH 1/1] drm/i915/hdcp: Simplify code in intel_hdcp_auth_downstream() In-Reply-To: <86f64463-87df-9e62-a5ea-f411fcb54c19@huawei.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20210527090421.9172-1-thunder.leizhen@huawei.com> <87sg28a3xg.fsf@intel.com> <86f64463-87df-9e62-a5ea-f411fcb54c19@huawei.com> Date: Mon, 31 May 2021 13:36:08 +0300 Message-ID: <87wnrfqjfr.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 28 May 2021, "Leizhen (ThunderTown)" wrote: > 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. Yes, if the loop is abstracted to a separate function. BR, Jani. > > >> >> 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; >>> } >> > -- Jani Nikula, Intel Open Source Graphics Center