Re: [syzbot] [mtd?] divide error in block2mtd_setup2

Pei Xiao <[email protected]>
Newsgroups org.infradead.lists.linux-mtd,org.kernel.vger.linux-kernel
Message-ID <[email protected]>

在 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


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.