From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4246FC433E0 for ; Thu, 30 Jul 2020 23:13:06 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 13D4020809 for ; Thu, 30 Jul 2020 23:13:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nVehFujm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 13D4020809 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A52B96E973; Thu, 30 Jul 2020 23:13:04 +0000 (UTC) Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by gabe.freedesktop.org (Postfix) with ESMTPS id 95F2C6E973 for ; Thu, 30 Jul 2020 23:13:03 +0000 (UTC) Received: from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D285E9B1; Fri, 31 Jul 2020 01:12:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1596150777; bh=U2AhUcM9xOgRljTgW3Ir7sj8Vyh/2BUPnmUtHh6/7hY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nVehFujmy2MNmF9aWy/qBjKtueH9/PbcqtF55T236zWL9omjo7J52V4vi+PCYFkzT IfYTb3/UQ3J9/4w578NQslOxOLZyxSPBLArLgesUHpr8PE8gIjUks02iG/CRTy8fA5 3TLTfsbHI4QtrL1wdMfGEEhXCZWvVEVDJY+5mDCI= Date: Fri, 31 Jul 2020 02:12:46 +0300 From: Laurent Pinchart To: Hyun Kwon Subject: Re: [PATCH v2 1/1] drm: xlnx: zynqmp: Use switch - case for link rate downshift Message-ID: <20200730231246.GJ6107@pendragon.ideasonboard.com> References: <1596065445-4630-1-git-send-email-hyun.kwon@xilinx.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1596065445-4630-1-git-send-email-hyun.kwon@xilinx.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dan Carpenter , dri-devel@lists.freedesktop.org, Daniel Vetter Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Hi Hyun, Thank you for the patch. On Wed, Jul 29, 2020 at 04:30:45PM -0700, Hyun Kwon wrote: > Use switch - case to downshift from the current link rate. It's a small > loop now, so fine to be replaced with switch - case. With a loop, it is > confusing and hard to follow as reported below. > > The patch d76271d22694: "drm: xlnx: DRM/KMS driver for Xilinx ZynqMP > DisplayPort Subsystem" from Jul 7, 2018, leads to the following > static checker warning: > > drivers/gpu/drm/xlnx/zynqmp_dp.c:594 zynqmp_dp_mode_configure() > error: iterator underflow 'bws' (-1)-2 > > Reported-by: Dan Carpenter > Signed-off-by: Hyun Kwon > --- > v2 > - Convert the for loop into switch - case > --- > --- > drivers/gpu/drm/xlnx/zynqmp_dp.c | 29 ++++++++++++++++------------- > 1 file changed, 16 insertions(+), 13 deletions(-) > > diff --git a/drivers/gpu/drm/xlnx/zynqmp_dp.c b/drivers/gpu/drm/xlnx/zynqmp_dp.c > index b735072..5d6adeaa 100644 > --- a/drivers/gpu/drm/xlnx/zynqmp_dp.c > +++ b/drivers/gpu/drm/xlnx/zynqmp_dp.c > @@ -567,34 +567,37 @@ static int zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock, > u8 current_bw) > { > int max_rate = dp->link_config.max_rate; > - u8 bws[3] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7, DP_LINK_BW_5_4 }; > + u8 bw_code; > u8 max_lanes = dp->link_config.max_lanes; > u8 max_link_rate_code = drm_dp_link_rate_to_bw_code(max_rate); > u8 bpp = dp->config.bpp; > u8 lane_cnt; > - s8 i; > > - if (current_bw == DP_LINK_BW_1_62) { > + /* Downshift from current one */ Maybe "Downshift from the current bandwidth" ? Reviewed-by: Laurent Pinchart > + switch (current_bw) { > + case DP_LINK_BW_5_4: > + bw_code = DP_LINK_BW_2_7; > + break; > + case DP_LINK_BW_2_7: > + bw_code = DP_LINK_BW_1_62; > + break; > + case DP_LINK_BW_1_62: > dev_err(dp->dev, "can't downshift. already lowest link rate\n"); > return -EINVAL; > - } > - > - for (i = ARRAY_SIZE(bws) - 1; i >= 0; i--) { > - if (current_bw && bws[i] >= current_bw) > - continue; > - > - if (bws[i] <= max_link_rate_code) > - break; > + default: > + /* If not given, start with max supported */ > + bw_code = max_link_rate_code; > + break; > } > > for (lane_cnt = 1; lane_cnt <= max_lanes; lane_cnt <<= 1) { > int bw; > u32 rate; > > - bw = drm_dp_bw_code_to_link_rate(bws[i]); > + bw = drm_dp_bw_code_to_link_rate(bw_code); > rate = zynqmp_dp_max_rate(bw, lane_cnt, bpp); > if (pclock <= rate) { > - dp->mode.bw_code = bws[i]; > + dp->mode.bw_code = bw_code; > dp->mode.lane_cnt = lane_cnt; > dp->mode.pclock = pclock; > return dp->mode.bw_code; -- Regards, Laurent Pinchart _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel