Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp432475rwb; Tue, 25 Jul 2023 18:59:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlGF5ZL/rkU0dFuGA8YHxVQZKmHPo2Om/XfHv7pMufY+RTylkCumyLsjtsmAoOwvYX09U8/R X-Received: by 2002:a05:6512:344d:b0:4fe:ee7:a32a with SMTP id j13-20020a056512344d00b004fe0ee7a32amr397673lfr.16.1690336779240; Tue, 25 Jul 2023 18:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690336779; cv=none; d=google.com; s=arc-20160816; b=WlsZ4o0U6hXlOjMi2b49MdLgOp3l+f3juQq2Tc4LSt16WQ6gAsH1WXj53vOPQ1tGy8 9l0z7yqulEePojR7faPLhqdiPYUBywtY9mHwIHd+XOlLJeK4Ba8LC6BhrV8dzzWbLNlP cL7UhHO97ebgswX3ZM5zDMjFjZEn32EPht9SzsfRWaCme/OgjVrCgZFKXxnniaMacgUb uqxETymMtx+min8TS8mfPs/E5ccDE8mFgx2xApgpf0gpo/ISOEder0X+RN1aokZVEyNw mx7EsPlg8LPWxmE/uJvqqjVHiigE4MR4YpKA5muzgXmkpcMFNcCZrppDBDJG1MCHPOji w7CQ== 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=Eq9hJZTASwwL3PpP49v6xryD07NPQfWFty0jydhOCq4=; fh=Wu5E9y+aQi34bCSikVU4J2v6n1Qv8Oh119t0dkys7Ns=; b=ravRUy52mkgDei5pDEq8yP35s+mbkqQWL+fj6JK9Az65RdfOa82iRJa4ZvYFf/0Iha 90ti5NsNBOuDlOoBFMIXxYUDkwq3DPEHNRm/HR4x02734VPAMqlzIRSI+JOdXrsKsG03 ajbZPfUm+xR3GmmLPs1eVMN9ZgR9T2JPez9SLvsoMGPLY28cqhJffUmyb9Gpwk2qI3Q2 UYjkdxZK42oo55iJEOGHgEbkVASqfLyEcb9JAKRGdNAqzKJMR7J1V17UC4vDiOToinK5 3UAAld5n9PzLldGqEdaVEhZdrSMbatBfDmh3tDVZDqO/jT8BxpN38EWpSyOYvGykzi22 DnZA== 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 p13-20020a056402074d00b005224e403e96si1733852edy.196.2023.07.25.18.59.15; Tue, 25 Jul 2023 18:59:39 -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 S229715AbjGZBWL (ORCPT + 99 others); Tue, 25 Jul 2023 21:22:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjGZBWK (ORCPT ); Tue, 25 Jul 2023 21:22:10 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 95EDDC0; Tue, 25 Jul 2023 18:22:09 -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 9DA4E6025FB42; Wed, 26 Jul 2023 09:21:51 +0800 (CST) Message-ID: <630b9f2e-00e8-5b54-ad1c-3e4d404454a1@nfschina.com> Date: Wed, 26 Jul 2023 09:21:50 +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: [Intel-gfx] [PATCH v2] drm/i915/tv: avoid possible division by zero Content-Language: en-US To: Dan Carpenter Cc: Andi Shyti , 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, andrzej.hajda@intel.com, intel-gfx@lists.freedesktop.org, llvm@lists.linux.dev, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, mripard@kernel.org X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui In-Reply-To: <5d096bcf-c394-4dad-b307-3d7e33ab6e6f@kadam.mountain> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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/25 13:51, Dan Carpenter wrote: > The reason why the first five attempts had bugs is because we are > trying to write it in the most complicated way possible, shifting by > logical not what? Wonderful! Should I add your name as signed-of-by? I will send a v3 patch later. Really thanks for your help! Su Hui > regards, > dan carpenter > > diff --git a/drivers/gpu/drm/i915/display/intel_tv.c b/drivers/gpu/drm/i915/display/intel_tv.c > index 36b479b46b60..6997b6cb1df2 100644 > --- a/drivers/gpu/drm/i915/display/intel_tv.c > +++ b/drivers/gpu/drm/i915/display/intel_tv.c > @@ -988,7 +988,13 @@ 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); > + int div = tv_mode->oversample; > + > + if (!tv_mode->progressive) > + div >>= 1; > + if (div == 0) > + div = 1; > + mode->clock = clock / div; > > /* > * tv_mode horizontal timings: > @@ -1135,6 +1141,8 @@ intel_tv_get_config(struct intel_encoder *encoder, > break; > default: > tv_mode.oversample = 1; > + WARN_ON_ONCE(!tv_mode.progressive); > + tv_mode.progressive = true; > break; > } > >