Message ID | 20230516165931.2989639-1-suijingfeng@loongson.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp576224vqo; Tue, 16 May 2023 10:04:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4M/GOoLrmZnVmKT7ImfLjxhafcZEICyXDIPuyZuNRAJLTyVoirSJXrAiHVAovnbv04uQ3K X-Received: by 2002:a05:6a00:990:b0:638:edbc:74ca with SMTP id u16-20020a056a00099000b00638edbc74camr51837600pfg.0.1684256682449; Tue, 16 May 2023 10:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684256682; cv=none; d=google.com; s=arc-20160816; b=uySME0855f9K+GMu3lSCR/YGDvZ+bMxiTrIyKgO+25vAUl0gwTcE015T9e6xnN9Yuq Yp1z7+ljNGiBTIq78mIwTYICKQGON286PeEpu4XTQL3hxHVeQNk4PkwhzWCa8MzAw5sx sAiEWoQk3hhGOfykC2ryjWjuEWCZIQa4lVqjPlCsCT6oFD/fxBI8GZAhjPhBrWMw39aO 0Oll01UY4FbOICzTbyNH55IKCxKan7vSXaAK90Vg8mrHsjM3qxXxKW3LbWexaar797E8 pYC7XJiQrTOq9x/wWoMi1u807h37fNIr/yyhYZGTNv6IJ8U0AuLrON8lR8UgaJd0iLpE N2pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=3OnYNnXCrs9nuES2qFw8UOb1Fwu+E60yzIVm7otDJ3g=; b=MQbC8WhHBYYc1NN4KZS8Ce8qOeE8PPxkCyPEUYWj+goTH5M1KO0x0ina09ZUcFoRjF J1XSuok9RsynapwRSy8xisoBQKWtm6jd6EEwz/N+iLuwdMhoYIn8BN3NKrF/f/0dOxD7 RwFdbcGbJbI0Vsbbes6ut8tQUNouqhnMqU2VjE0dfadnoOoelTOmArr/ipXL/KF13wwT sch79/NvnCcMF6lDT36C9eN4pSvOVozQVYoiLfCuIge1hnOeoYZQOKTAD/Tu1Hy8gJiV vmgBk1mP4GLdq/C0Kym0uu8hmgwWLxxZMaCDQ8BH/z4P3GxWE54jz9w2QmyGlGyBJsuE FloA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j2-20020a636e02000000b00530b1dec2desi8457329pgc.601.2023.05.16.10.04.26; Tue, 16 May 2023 10:04:42 -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 S231841AbjEPRAY (ORCPT <rfc822;peekingduck44@gmail.com> + 99 others); Tue, 16 May 2023 13:00:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230258AbjEPRAV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 16 May 2023 13:00:21 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0A36D8689 for <linux-kernel@vger.kernel.org>; Tue, 16 May 2023 09:59:37 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8CxvOp3tmNkfzcJAA--.15797S3; Wed, 17 May 2023 00:59:35 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx87R0tmNksMhjAA--.39626S2; Wed, 17 May 2023 00:59:33 +0800 (CST) From: Sui Jingfeng <suijingfeng@loongson.cn> To: suijingfeng <15330273260@189.cn> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>, Maxime Ripard <mripard@kernel.org>, Thomas Zimmermann <tzimmermann@suse.de>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast Date: Wed, 17 May 2023 00:59:31 +0800 Message-Id: <20230516165931.2989639-1-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Dx87R0tmNksMhjAA--.39626S2 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7tFWDAw1rtFWktw47Ww4fAFb_yoW8Ww4DpF srtryqkr4Fya40yasrCF1fAFy5Xasxt3W2yrWDu34akF1YqF13AFyFyr47WFWUX3ZFka4a yrsrXF1Fq3WUuaDanT9S1TB71UUUUjDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bfxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwA2z4 x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AKxVW8JVW8Jr1ln4kS 14v26r126r1DM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r126r1DMcIj6I8E87Iv 67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2 AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xF xVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWw C2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_ Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJV WUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBI daVFxhVjvjDU0xZFpf9x07j5o7tUUUUU= X-Spam-Status: No, score=1.4 required=5.0 tests=BAYES_00,RCVD_IN_SBL_CSS, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766071134775919004?= X-GMAIL-MSGID: =?utf-8?q?1766071134775919004?= |
Series |
drm/drm_vblank.c: avoid unsigned int to signed int cast
|
|
Commit Message
Sui Jingfeng
May 16, 2023, 4:59 p.m. UTC
Both mode->crtc_htotal and mode->crtc_vtotal are u16 type,
mode->crtc_htotal * mode->crtc_vtotal will results a unsigned type.
Using a u32 is enough to store the result, but considering that the
result will be casted to u64 soon after. We use a u64 type directly.
So there no need to cast it to signed type and cast back then.
Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
---
drivers/gpu/drm/drm_vblank.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
Am 16.05.23 um 18:59 schrieb Sui Jingfeng: > Both mode->crtc_htotal and mode->crtc_vtotal are u16 type, > mode->crtc_htotal * mode->crtc_vtotal will results a unsigned type. > Using a u32 is enough to store the result, but considering that the > result will be casted to u64 soon after. We use a u64 type directly. > > So there no need to cast it to signed type and cast back then. > > Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> > Cc: Maxime Ripard <mripard@kernel.org> > Cc: Thomas Zimmermann <tzimmermann@suse.de> > Cc: David Airlie <airlied@gmail.com> > Cc: Daniel Vetter <daniel@ffwll.ch> > Cc: dri-devel@lists.freedesktop.org > Cc: linux-kernel@vger.kernel.org Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de> > --- > drivers/gpu/drm/drm_vblank.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c > index 877e2067534f..d99c404b181b 100644 > --- a/drivers/gpu/drm/drm_vblank.c > +++ b/drivers/gpu/drm/drm_vblank.c > @@ -622,7 +622,7 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc, > > /* Valid dotclock? */ > if (dotclock > 0) { > - int frame_size = mode->crtc_htotal * mode->crtc_vtotal; > + u64 frame_size = mode->crtc_htotal * mode->crtc_vtotal; > > /* > * Convert scanline length in pixels and video > @@ -630,7 +630,7 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc, > * in nanoseconds: > */ > linedur_ns = div_u64((u64) mode->crtc_htotal * 1000000, dotclock); > - framedur_ns = div_u64((u64) frame_size * 1000000, dotclock); > + framedur_ns = div_u64(frame_size * 1000000, dotclock); > > /* > * Fields of interlaced scanout modes are only half a frame duration. -- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstrasse 146, 90461 Nuernberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman HRB 36809 (AG Nuernberg)
Hi, On 2023/5/17 01:06, Thomas Zimmermann wrote: > > > Am 16.05.23 um 18:59 schrieb Sui Jingfeng: >> Both mode->crtc_htotal and mode->crtc_vtotal are u16 type, >> mode->crtc_htotal * mode->crtc_vtotal will results a unsigned type. >> Using a u32 is enough to store the result, but considering that the >> result will be casted to u64 soon after. We use a u64 type directly. >> >> So there no need to cast it to signed type and cast back then. >> >> Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> >> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> >> Cc: Maxime Ripard <mripard@kernel.org> >> Cc: Thomas Zimmermann <tzimmermann@suse.de> >> Cc: David Airlie <airlied@gmail.com> >> Cc: Daniel Vetter <daniel@ffwll.ch> >> Cc: dri-devel@lists.freedesktop.org >> Cc: linux-kernel@vger.kernel.org > > Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de> > Thanks a lot, thanks for the response time also. >> --- >> drivers/gpu/drm/drm_vblank.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c >> index 877e2067534f..d99c404b181b 100644 >> --- a/drivers/gpu/drm/drm_vblank.c >> +++ b/drivers/gpu/drm/drm_vblank.c >> @@ -622,7 +622,7 @@ void drm_calc_timestamping_constants(struct >> drm_crtc *crtc, >> /* Valid dotclock? */ >> if (dotclock > 0) { >> - int frame_size = mode->crtc_htotal * mode->crtc_vtotal; >> + u64 frame_size = mode->crtc_htotal * mode->crtc_vtotal; >> /* >> * Convert scanline length in pixels and video >> @@ -630,7 +630,7 @@ void drm_calc_timestamping_constants(struct >> drm_crtc *crtc, >> * in nanoseconds: >> */ >> linedur_ns = div_u64((u64) mode->crtc_htotal * 1000000, >> dotclock); >> - framedur_ns = div_u64((u64) frame_size * 1000000, dotclock); >> + framedur_ns = div_u64(frame_size * 1000000, dotclock); >> /* >> * Fields of interlaced scanout modes are only half a frame >> duration. >
diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 877e2067534f..d99c404b181b 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -622,7 +622,7 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc, /* Valid dotclock? */ if (dotclock > 0) { - int frame_size = mode->crtc_htotal * mode->crtc_vtotal; + u64 frame_size = mode->crtc_htotal * mode->crtc_vtotal; /* * Convert scanline length in pixels and video @@ -630,7 +630,7 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc, * in nanoseconds: */ linedur_ns = div_u64((u64) mode->crtc_htotal * 1000000, dotclock); - framedur_ns = div_u64((u64) frame_size * 1000000, dotclock); + framedur_ns = div_u64(frame_size * 1000000, dotclock); /* * Fields of interlaced scanout modes are only half a frame duration.