|
358 | 358 |
|
359 | 359 | /* #define ADD_INTERRUPT_BENCH */ |
360 | 360 |
|
361 | | -/* |
362 | | - * To allow fractional bits to be tracked, the entropy_count field is |
363 | | - * denominated in units of 1/8th bits. |
364 | | - * |
365 | | - * 2*(POOL_ENTROPY_SHIFT + poolbitshift) must <= 31, or the multiply in |
366 | | - * credit_entropy_bits() needs to be 64 bits wide. |
367 | | - */ |
368 | | -#define POOL_ENTROPY_SHIFT 3 |
369 | | -#define POOL_ENTROPY_BITS() (input_pool.entropy_count >> POOL_ENTROPY_SHIFT) |
370 | | - |
371 | 361 | /* |
372 | 362 | * If the entropy count falls under this number of bits, then we |
373 | 363 | * should wake up processes which are selecting or polling on write |
@@ -425,8 +415,13 @@ enum poolinfo { |
425 | 415 | POOL_WORDMASK = POOL_WORDS - 1, |
426 | 416 | POOL_BYTES = POOL_WORDS * sizeof(u32), |
427 | 417 | POOL_BITS = POOL_BYTES * 8, |
428 | | - POOL_BITSHIFT = ilog2(POOL_WORDS) + 5, |
429 | | - POOL_FRACBITS = POOL_WORDS << (POOL_ENTROPY_SHIFT + 5), |
| 418 | + POOL_BITSHIFT = ilog2(POOL_BITS), |
| 419 | + |
| 420 | + /* To allow fractional bits to be tracked, the entropy_count field is |
| 421 | + * denominated in units of 1/8th bits. */ |
| 422 | + POOL_ENTROPY_SHIFT = 3, |
| 423 | +#define POOL_ENTROPY_BITS() (input_pool.entropy_count >> POOL_ENTROPY_SHIFT) |
| 424 | + POOL_FRACBITS = POOL_BITS << POOL_ENTROPY_SHIFT, |
430 | 425 |
|
431 | 426 | /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */ |
432 | 427 | POOL_TAP1 = 104, |
@@ -652,6 +647,9 @@ static void credit_entropy_bits(int nbits) |
652 | 647 | int entropy_count, entropy_bits, orig; |
653 | 648 | int nfrac = nbits << POOL_ENTROPY_SHIFT; |
654 | 649 |
|
| 650 | + /* Ensure that the multiplication can avoid being 64 bits wide. */ |
| 651 | + BUILD_BUG_ON(2 * (POOL_ENTROPY_SHIFT + POOL_BITSHIFT) > 31); |
| 652 | + |
655 | 653 | if (!nbits) |
656 | 654 | return; |
657 | 655 |
|
@@ -687,13 +685,13 @@ static void credit_entropy_bits(int nbits) |
687 | 685 | /* The +2 corresponds to the /4 in the denominator */ |
688 | 686 |
|
689 | 687 | do { |
690 | | - unsigned int anfrac = min(pnfrac, POOL_FRACBITS/2); |
| 688 | + unsigned int anfrac = min(pnfrac, POOL_FRACBITS / 2); |
691 | 689 | unsigned int add = |
692 | | - ((POOL_FRACBITS - entropy_count)*anfrac*3) >> s; |
| 690 | + ((POOL_FRACBITS - entropy_count) * anfrac * 3) >> s; |
693 | 691 |
|
694 | 692 | entropy_count += add; |
695 | 693 | pnfrac -= anfrac; |
696 | | - } while (unlikely(entropy_count < POOL_FRACBITS-2 && pnfrac)); |
| 694 | + } while (unlikely(entropy_count < POOL_FRACBITS - 2 && pnfrac)); |
697 | 695 | } |
698 | 696 |
|
699 | 697 | if (WARN_ON(entropy_count < 0)) { |
|
0 commit comments