[syzbot] [mtd?] divide error in block2mtd_setup2

Pei Xiao xiaopei01 at kylinos.cn
Tue Aug 11 18:45:44 PDT 2026



在 2026/8/12 02:19, Jörn Engel 写道:
> On Tue, Aug 11, 2026 at 11:02:53AM +0800, Pei Xiao wrote:
>>>
>> Thank you for your reply. I am waiting for a reply on whether the cast
>> on 'long' needs to be removed. Once that is confirmed, I would be happy
>> to do it. Thank you.
> 
> It doesn't need to be removed, but it should be removed.  Any
> unnecessary code should be removed in general and unnecessary casts in
> particular should.
> 
> One of better parts of the C language is that casts are hardly ever
> necessary.  Which means that any remaining necessary casts should
> immediately draw attention of the reader - something tricky and
> potentially dangerous is going on here.
> 
> But you stop paying attention when things become too common.  Which
> means that unnecessary casts are not just noise, they actively do harm.
> 
> 
> In this particular case, we can simply test whether the cast makes any
> difference:
> 
> #include <assert.h>
> #include <stdio.h>
> 
> int main(void)
> {
> 	for (int i=0; i<=1<<16; i++) {
> 		for (int k=1; k<=1<<16; k++) {
> 			long long size = (long long)i << 32;
> 			int erase_size = k;
> 
> 			long long a = size % erase_size;
> 			long long b = (long)size % erase_size;
> 			assert(a==b);
> 		}
> 	}
> }
Great test! You're truly professional, and I've learned a lot. I'll send
the v2 patch. Thank you for your guidance.

Pei.
> 
> Compile with optimizations and the compiler decides to remove the loop.
> Unless you suspect a compiler bug, I guess that settles the question. ;)
> 
> Jörn
> 
> --
> Semper ubi sub ubi ubique.
> -- latin pun




More information about the linux-mtd mailing list