|
|
Log in / Subscribe / Register

A tale of two data-corruption bugs

A tale of two data-corruption bugs

Posted May 25, 2015 17:09 UTC (Mon) by josh (subscriber, #17465)
In reply to: A tale of two data-corruption bugs by xtifr
Parent article: A tale of two data-corruption bugs

> Which might not sound that bad until you realize that this has to be done separately, not only for each branch, but for third-party forks as well.

Nope. This is exactly why the Linux kernel has a stated policy of not caring about out-of-tree drivers. Just change the macro to a function, convert all callers in the kernel, and delete the old macro.

> A more reasonable approach might be to create an new static inline with a new name (e.g. sector_divide)

Agreed, changing the name makes it easier to detect callers and avoid reintroducing new callers with that expectation (such as from patches in flight).

> and then either keep the current name for a macro that calls the inline and then does the extra assignment, or add a new macro with an all-caps name, and make the current name into a macro that uses #error to inform people that their code needs to be updated.

No macro needs to exist, nor does the kernel keep around compatibility interfaces that nothing in the kernel uses. Also, macros can't call #error, but there's a simpler solution to produce a compiler error for code that needs updating: just delete the macro, and attempted callers will get a compile time error saying sector_div does not exist.


to post comments

A tale of two data-corruption bugs

Posted May 25, 2015 20:50 UTC (Mon) by jzbiciak (guest, #5246) [Link] (1 responses)

I guess for a function like this, which effectively returns two values (in this case, sector_div is a specialized divmod function), you'd replace it with a static inline that requires you to take the address of the left argument? ie. something like this?

/* Compute bar / baz and bar % baz.  Put bar / baz into bar, and return bar % baz. */
foo = divmod( &bar, baz );

With inlining, the reference/dereference will get optimized away, most certainly, and the required & would make the in-out characteristic of bar more obvious.

I have to admit, the in-out nature of sector_div would not have been apparent to me. I sat up in my chair and shoot my head when I read the bug description in the article.

A tale of two data-corruption bugs

Posted May 25, 2015 21:49 UTC (Mon) by jzbiciak (guest, #5246) [Link]

I have to admit, the in-out nature of sector_div would not have been apparent to me. I sat up in my chair and shoot my head when I read the bug description in the article.

err... I meant to say: I have to admit, the in-out nature of the first parameter to sector_div would not have been apparent to me. I sat up in my chair and shook my head when I read the bug description in the article.


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