|
|
Log in / Subscribe / Register

Fixing sector_div

Fixing sector_div

Posted May 25, 2015 14:06 UTC (Mon) by cesarb (subscriber, #6266)
In reply to: Fixing sector_div by jreiser
Parent article: A tale of two data-corruption bugs

> The best fix from the viewpoint of safety and reliability is two new static functions sector_quo and sector_rem, along with changing the definition of macro sector_div so that its expansion causes a compile-time error which refers the programmer to sector_quo and sector_rem.

The whole point of that macro is to avoid doing the same division twice. Replacing it with a single macro with a different calling convention would be acceptable, replacing it with two separate operations would be a harder sell.

> There must be an audit to detect and evaluate all similar instances: any macro with arguments that is not equivalent to the obvious C-language function of those same arguments.

They're quite common in the kernel; the spin_lock_irqsave/irqrestore() pair is a popular example, and nobody ever gets confused by it. The problem is not "pass by reference" arguments; the problem is using the same argument for both an input and an output. In the spin_lock example, the argument to the spin_lock_irqsave() macro is always an output, and the argument to the spin_lock_irqrestore() macro is always an input.


The LWN site is currently under high scraper load, so comment display has been suppressed for anonymous users. If you are a human, you may read the comments by clicking the button below:

Note: you can avoid this step in the future by logging into your LWN account.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds