Messages in this thread | | | Date | Mon, 5 Dec 2022 14:30:17 +0100 | From | "Jason A. Donenfeld" <> | Subject | Re: [PATCH v2 2/3] hwrng: add Rockchip SoC hwrng driver |
| |
On Mon, Dec 05, 2022 at 02:13:45PM +0100, Jason A. Donenfeld wrote: > If your intention is "90%", this should be 921 or 922, because the > quality knob is out of 1024, not 1000. > > Herbert - this seems like a fairly common pitfall I've seen all over the > place. It might be worth making a mental memo to reject or ask questions > about numbers that seem "too round", when you look at these sorts of > patches.
Or alternatively we could introduce a cheesy macro like:
#define HWRNG_PERCENTAGE(p) ((p) * 1024 / 100)
and then enforce that everyone use that. But that's a bit wacky too, in the sense of - why is anybody using a non-obvious percentage in the first place. Like if you see "512" (or better, "1024 / 2"), okay fine, it's a device that guarantees 50%, which seems like a common enough physical thing. But if we see "HWRNG_PERCENTAGE(90)", the first question is why? What causes that? Seems very weird. And it's probably wrong.
But if it *is* right, that deserves a big comment with explanation, where the calculation for that "921" literal can be explained in full, or, better, evaluated as a constant expression in terms of hardware constants -- something like HW_CLOCKRATE/FROBNICATOR_INTENSITY*1024/TURBOENCABULATION_MODE_WEIGHT, and then it all makes sense.
So maybe rather than a macro or accepting barebones "921" values, if the value isn't 1024 (0), then it needs a comment + an expression computing the value.
Seem reasonable?
Jason
| |