Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp6272475rwp; Mon, 17 Jul 2023 19:09:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlHT6o7gbI81iKs4qYfBQ4m1kfBrrdDdKMz6bFXUb1ptWILyT8N1cfdvtg0glAlFKrAbQl9s X-Received: by 2002:aca:bcd6:0:b0:3a3:7acc:7dc7 with SMTP id m205-20020acabcd6000000b003a37acc7dc7mr11418949oif.12.1689646166303; Mon, 17 Jul 2023 19:09:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689646166; cv=none; d=google.com; s=arc-20160816; b=N2tqD3J4/vSpclNG7hHNXa8VQqgOFGyhwlewSkUbI0pfnmQKkkeX08xFAnBjKgEDT3 0dZawsoj1N+sEDrqvL7pX1vh+P7dpWVAJd6YAf7FuJzK5KGUsB/ppmDKDe4+tSFxMHjX BUvK0y7qzzQQZw3SHn+X1p54CAs7mOxfjDy/Wf6psI45xJ/JZEnUR5Vm9gQ7S2Su9lwj TJGiD0Vvt3AZ8PjFwTAB0VUMa17vn4/Ewn5ElSS5P4LMf7VCkJyqqMzvbGuE6bbtAeDA p5Yjy7EOudWiB2g1bIqgbFt+2F04BJvSAoojoe/rYXlb2zk8sdOfdS82Wep7GoxpmePo TOjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from:cc:to :content-language:subject:user-agent:mime-version:date:message-id; bh=Slbs0fwUUiVv7CIIvDaxYQMIC6QQTwadQLXUzEqVe4Y=; fh=iqyvbHplkF4KBXKlCJS8MSSCWOIGgOrAdnQ86jf5YLc=; b=rq/pWBmKGhYk57JpMP2aFi8H8dXrDfJ26oH3nFl8hJTlpP2MYxU7J+piqDBogybL/V tcdNsgH+u/REeTr+OwhZnNp9wPHcio5vudPpY+vBQodLQKMH7WHFDaHA83/XlIowUiZP oFid1n5R2ir5o5L0Kfys/EpCnF3x5VsXgoXozAoWLjVQ7FpV4CMzIH/ViIOEdxx+VbTz av6NRLUvOL/XJFTgLQkXwUuWTubr+9QN8jcmoJIUcymDL5hQwLJ7AHlwhQuZoCHhlw/D 4JYdQWdXC1w4TbFPlMZyeXx0Yu0yrVivv1lkERacxfNF4+ZgPTkgAZ/7HENeC5D32CWS MehA== 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 62-20020a630041000000b005573b42d9e3si701446pga.593.2023.07.17.19.09.14; Mon, 17 Jul 2023 19:09:26 -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; 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 S230062AbjGRBNS (ORCPT + 99 others); Mon, 17 Jul 2023 21:13:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229790AbjGRBNR (ORCPT ); Mon, 17 Jul 2023 21:13:17 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id D906BF0; Mon, 17 Jul 2023 18:13:15 -0700 (PDT) Received: from [172.30.11.106] (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPSA id B112C6085E131; Tue, 18 Jul 2023 09:13:11 +0800 (CST) Message-ID: <8a94e6dc-f664-84fa-32f7-7f45f22a410a@nfschina.com> Date: Tue, 18 Jul 2023 09:13:11 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH] drm/i915/tv: avoid possible division by zero Content-Language: en-US To: Andrzej Hajda , jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, tvrtko.ursulin@linux.intel.com, airlied@gmail.com, daniel@ffwll.ch, nathan@kernel.org, ndesaulniers@google.com, trix@redhat.com Cc: ville.syrjala@linux.intel.com, mripard@kernel.org, ankit.k.nautiyal@intel.com, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, kernel-janitors@vger.kernel.org X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui In-Reply-To: <0cae35ea-7635-383d-cae5-2051abbc6d64@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 On 2023/7/17 22:52, Andrzej Hajda wrote: > > > On 17.07.2023 08:22, Su Hui wrote: >> Clang warning: drivers/gpu/drm/i915/display/intel_tv.c: >> line 991, column 22 Division by zero. >> Assuming tv_mode->oversample=1 and (!tv_mode->progressive)=1, >> then division by zero will happen. >> >> Fixes: 1bba5543e4fe ("drm/i915: Fix TV encoder clock computation") >> Signed-off-by: Su Hui >> --- >>   drivers/gpu/drm/i915/display/intel_tv.c | 3 ++- >>   1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/gpu/drm/i915/display/intel_tv.c >> b/drivers/gpu/drm/i915/display/intel_tv.c >> index 36b479b46b60..82b54af51f23 100644 >> --- a/drivers/gpu/drm/i915/display/intel_tv.c >> +++ b/drivers/gpu/drm/i915/display/intel_tv.c >> @@ -988,7 +988,8 @@ intel_tv_mode_to_mode(struct drm_display_mode *mode, >>                 const struct tv_mode *tv_mode, >>                 int clock) >>   { >> -    mode->clock = clock / (tv_mode->oversample >> >> !tv_mode->progressive); >> +    mode->clock = clock / (tv_mode->oversample != 1 ? >> +            tv_mode->oversample >> !tv_mode->progressive : 1); > > Seems too smart to me, why not just: > mode->clock = clock / tv_mode->oversample; > if (!tv_mode->progressive) >     mode->clock <<= 1; > Or trying being smart: > mode->clock = clock / tv_mode->oversample << !tv_mode->progressive; Hi, Yes, this is more readable and clear. Thanks four your advice. I will send v2 soon. Su Hui > > Btw in both cases there is assumption tv_mode->oversample != 0, I > guess it is true. > > Regards > Andrzej > >>         /* >>        * tv_mode horizontal timings: >