Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4117519rwd; Tue, 23 May 2023 03:27:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4lF64dZq6xUwkaT5am8ZLCCjMjx5HEiMzhmVF566QqryOmspBvu8Or7dIa/nxxLuRhcF0I X-Received: by 2002:a05:6a00:14c4:b0:647:b071:20c4 with SMTP id w4-20020a056a0014c400b00647b07120c4mr16254227pfu.1.1684837668670; Tue, 23 May 2023 03:27:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684837668; cv=none; d=google.com; s=arc-20160816; b=LUZESkIK53OlgwaeLpBACsgqjHv7uol4DgcZ+KAITeOovyDWu0OiQ3HWH8TbGDHXH9 0kAW4jyjZDHlAjb5sNKWvX+6t7m+Zbw7xsitZXoyrsBxPg2lKVr25GDG1IJJS6XY3Sz+ G59djagAsHax3hOTY+VKxl6lG1IvUVWwLs8jMacidIfSSfHg12wM3JG6s3n6/r0r/rzo OYHUjZzLrWFE8LEplT9my0hgzglMCEuWCjdzYZmRarNLGDIMyXt/eQ0Wj9Me75fBfFD5 zIe49CVuszgVke/GBPlv+BL804jFYsTprubRzeVak4r5GOMr3wQkOP5kMx+Nkh0pz00p Ga4w== 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 :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:sender:hmm_source_type:hmm_attache_num :hmm_source_ip; bh=9Da33pmaUDXaDVxf2t3fFlBGwE53wiwYn2hxLcPXNVI=; b=FM/wuvbd99d4SU2BXX7/s3hxsufdOqEA4V6fZJN+OFsAdOgqlk+RtmJb50LE3r+E22 Dgfx74VDczQqbxo05GKTMJrWTFOihpnn+WXFNENQ16E9+z/4N7QmRWjpWvArqoIOkNYh vrN+RdvEWNiEkVYQrctRGqj5ST1I0tfG5/AcV+mw6tmapvcV3NXMOHiqtMqbZQ7M4C3g HpgFKAMQzVEJclYCuOsfNMN4uV9ZSnVlLMvsLhJh072GsdTyZ2Nb4e8jYM92q6ov86QE VLDNJyhxnGMnigli5estG95BEOds2L4lHqszwTixEht4bm+zuiZNK8FNdsZVKw+0KF+J iUtg== 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 t68-20020a625f47000000b0064d3894678bsi3425509pfb.64.2023.05.23.03.27.34; Tue, 23 May 2023 03:27:48 -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 S235983AbjEWJzy (ORCPT + 99 others); Tue, 23 May 2023 05:55:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235914AbjEWJzv (ORCPT ); Tue, 23 May 2023 05:55:51 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.103]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 25587FF for ; Tue, 23 May 2023 02:55:43 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.31:57524.1031125115 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id 3F859100213; Tue, 23 May 2023 17:55:40 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xp9j7 with ESMTP id 277733f944394f969e1abbb9ceeb69a8 for david.laight@aculab.com; Tue, 23 May 2023 17:55:42 CST X-Transaction-ID: 277733f944394f969e1abbb9ceeb69a8 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn Message-ID: Date: Tue, 23 May 2023 17:55:39 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast Content-Language: en-US To: David Laight , Jani Nikula , Sui Jingfeng , Li Yi Cc: Thomas Zimmermann , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "loongson-kernel@lists.loongnix.cn" References: <20230516173026.2990705-1-15330273260@189.cn> <871qj8ob7z.fsf@intel.com> <4c9c0897-5e3a-1469-3d87-ff7723ac160c@189.cn> From: Sui Jingfeng <15330273260@189.cn> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,NICE_REPLY_A,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,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 Hi, On 2023/5/23 16:50, David Laight wrote: > From: 15330273260@189.cn <15330273260@189.cn> >> Sent: 23 May 2023 05:27 >> >> On 2023/5/22 19:29, Jani Nikula wrote: >>> In general, do not use unsigned types in arithmethic to avoid negative >>> values, because most people will be tripped over by integer promotion >>> rules, and you'll get negative values anyway. >> >> Here I'm not sure about this, >> >> but there are plenty unsigned types arithmetic in the kernel. > The real problem is (attempted) arithmetic on types smaller than int. > Regardless of whether they are signed or unsigned. It is about sign extend. Yes, you may be right. I might create a wrong patch. But this will not happen in practice, because in general case: mode->crtc_htotal < 0x8fff; mode->crtc_vtotal < 0x8fff; u16 gets promoted to 'signed int' not 'unsigned int'. Sorry  :/ > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales)