Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1972091rwd; Wed, 17 May 2023 04:09:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7wUujZB7LMlm6obeo1+PTkG/Hio4QMUQ/kPvNOpeoYXFLCipz+CEkAjOCqCtfrtpfjYzdT X-Received: by 2002:a17:902:db03:b0:1a6:7b71:e64b with SMTP id m3-20020a170902db0300b001a67b71e64bmr2562076plx.15.1684321754183; Wed, 17 May 2023 04:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684321754; cv=none; d=google.com; s=arc-20160816; b=CCHwCePVZMGH8xwXJSlHbqHR76fn0Ik0TC3T4sOa5ni7C9lu4rhD6gD1itv6CCBG+u UmfVGFL9uE7c6XDD8IOhWS1GKze1tBN4NvSxIhXgu7ZzdiMfMt3jhYdJZQse8P0dy7ZB 1uIcb5c9Q4sNx2ioCmbvttkri78gD/781lBANL7jF2sNDBD39Cy4YWaXs1P2kTp1To3t kJjF/AMNrJS3k/NLKztGo0Gek4AQ8Vm73GoP8WQrVqVahvspQl4cpKF8kNbRTChdG815 JOgWh8XXhS45JCgqW5LEkLaHUY4HIFODXBG2S+gwFuf0qryL3LmpmHmvdk1FKZAuBR4Z cn6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=z1u4x4q1kxPPlUuHTI0HXXhkF97/Qo31wQ1kYk95D2g=; b=buNz5uul67j4WvsmCDaq4d4/j++xof1KiLJ31p4mECFkdclkuUwHxFe3H7n/FQjGOd c304Jtqv5ZJMcQDEcUbEIeiBo+8RtY/hW4G+WrFJM0l9mVLoUmlRqMWInJvK/QzZmZ9q +G+6FU6GHc764vRBSRO5qPQiSIO4+8OSacfYEDq/NgtsxXm6TiZjQJLlvwPnWpt0hUma 2xe/fHFEjJoNpI65roht5xGdmV1uBHczjVNyHliyudh93EQXtK7rBGuq+XA4o1D5yWDd CvzMqHzM2bVb5TWCvvjfWmItUiG0z9QCTeW0z1AaVFfVcTrJ3HnUVwDjDbw4dDZQMYoX 14kg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n5-20020a170902e54500b001a8173f468fsi22812719plf.314.2023.05.17.04.08.59; Wed, 17 May 2023 04:09:14 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231186AbjEQLAv convert rfc822-to-8bit (ORCPT + 99 others); Wed, 17 May 2023 07:00:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230407AbjEQLAj (ORCPT ); Wed, 17 May 2023 07:00:39 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7117A6A77 for ; Wed, 17 May 2023 04:00:13 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-21-rAgZD7axM7GFuHj9YrRhAw-1; Wed, 17 May 2023 11:59:16 +0100 X-MC-Unique: rAgZD7axM7GFuHj9YrRhAw-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 17 May 2023 11:59:14 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Wed, 17 May 2023 11:59:14 +0100 From: David Laight To: "'15330273260@189.cn'" <15330273260@189.cn>, Sui Jingfeng , Li Yi CC: Thomas Zimmermann , Maarten Lankhorst , Maxime Ripard , David Airlie , Daniel Vetter , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , "loongson-kernel@lists.loongnix.cn" Subject: RE: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast Thread-Topic: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast Thread-Index: AQHZiBwkXHI4wBkIl0yfSK4Xtptrs69eSnTg Date: Wed, 17 May 2023 10:59:14 +0000 Message-ID: References: <20230516173026.2990705-1-15330273260@189.cn> In-Reply-To: <20230516173026.2990705-1-15330273260@189.cn> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: 15330273260@189.cn > Sent: 16 May 2023 18:30 > > From: Sui Jingfeng > > Both mode->crtc_htotal and mode->crtc_vtotal are u16 type, > mode->crtc_htotal * mode->crtc_vtotal will results a unsigned type. Nope, u16 gets promoted to 'signed int' and the result of the multiply is also signed. > 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. .... > - int frame_size = mode->crtc_htotal * mode->crtc_vtotal; > + u64 frame_size = mode->crtc_htotal * mode->crtc_vtotal; ... > - framedur_ns = div_u64((u64) frame_size * 1000000, dotclock); > + framedur_ns = div_u64(frame_size * 1000000, dotclock); The (u64) cast is there to extend the value to 64bits, not because the original type is signed. The compiler will detect that the old code is a 32x32 multiply where a 64bit result is needed, that may not be true for the changed code (it would need to track back as far as the u16s). It is not uncommon to force a 64bit result from a multiply by making the constant 64bit. As in: div_u64(frame_size * 1000000ULL, dotclock); David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)