Re: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-23 Thread Sui Jingfeng
Hi, On 2023/5/23 16:50, David Laight wrote: From: 15330273...@189.cn <15330273...@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

RE: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-23 Thread David Laight
From: 15330273...@189.cn <15330273...@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

Re: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-23 Thread Sui Jingfeng
Hi, On 2023/5/23 12:26, Sui Jingfeng wrote: Hi, 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 sure abo

Re: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-22 Thread Sui Jingfeng
Hi, 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 sure about this, but there are plenty unsigned types

Re: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-22 Thread Sui Jingfeng
Hi, On 2023/5/22 23:01, Jani Nikula wrote: On Mon, 22 May 2023, Sui Jingfeng <15330273...@189.cn> wrote: Hi, On 2023/5/22 20:13, Jani Nikula wrote: On Mon, 22 May 2023, Sui Jingfeng <15330273...@189.cn> wrote: Hi, On 2023/5/22 19:29, Jani Nikula wrote: On Thu, 18 May 2023, Sui Jingfeng <15

Re: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-22 Thread Jani Nikula
On Mon, 22 May 2023, Sui Jingfeng <15330273...@189.cn> wrote: > Hi, > > On 2023/5/22 20:13, Jani Nikula wrote: >> On Mon, 22 May 2023, Sui Jingfeng <15330273...@189.cn> wrote: >>> Hi, >>> >>> On 2023/5/22 19:29, Jani Nikula wrote: On Thu, 18 May 2023, Sui Jingfeng <15330273...@189.cn> wrote: >

Re: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-22 Thread Sui Jingfeng
Hi, On 2023/5/22 20:13, Jani Nikula wrote: On Mon, 22 May 2023, Sui Jingfeng <15330273...@189.cn> wrote: Hi, On 2023/5/22 19:29, Jani Nikula wrote: On Thu, 18 May 2023, Sui Jingfeng <15330273...@189.cn> wrote: On 2023/5/17 18:59, David Laight wrote: From: 15330273...@189.cn Sent: 16 May 20

Re: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-22 Thread Jani Nikula
On Mon, 22 May 2023, Sui Jingfeng <15330273...@189.cn> wrote: > Hi, > > On 2023/5/22 19:29, Jani Nikula wrote: >> On Thu, 18 May 2023, Sui Jingfeng <15330273...@189.cn> wrote: >>> On 2023/5/17 18:59, David Laight wrote: From: 15330273...@189.cn > Sent: 16 May 2023 18:30 > > From: S

RE: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-22 Thread David Laight
From: 15330273...@189.cn <15330273...@189.cn> > Sent: 22 May 2023 12:56 ... > > I'll bet most people will be surprised to see what this prints: > > > > #include > > #include > > > > int main(void) > > { > > uint16_t x = 0x; > > uint16_t y = 0x; > > uint64_t z = x * y; > > > >

Re: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-22 Thread Sui Jingfeng
Hi, On 2023/5/22 19:29, Jani Nikula wrote: On Thu, 18 May 2023, Sui Jingfeng <15330273...@189.cn> wrote: On 2023/5/17 18:59, David Laight wrote: From: 15330273...@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

Re: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-22 Thread Jani Nikula
On Thu, 18 May 2023, Sui Jingfeng <15330273...@189.cn> wrote: > On 2023/5/17 18:59, David Laight wrote: >> From: 15330273...@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 wi

Re: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-17 Thread Sui Jingfeng
On 2023/5/17 18:59, David Laight wrote: From: 15330273...@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

RE: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-17 Thread David Laight
From: 15330273...@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.

[PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-16 Thread Sui Jingfeng
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. 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 ne

Re: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-16 Thread Sui Jingfeng
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

Re: [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast

2023-05-16 Thread Thomas Zimmermann
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 typ