Skip to content

Commit

Permalink
random: round-robin registers as ulong, not u32
Browse files Browse the repository at this point in the history
commit da3951e upstream.

When the interrupt handler does not have a valid cycle counter, it calls
get_reg() to read a register from the irq stack, in round-robin.
Currently it does this assuming that registers are 32-bit. This is
_probably_ the case, and probably all platforms without cycle counters
are in fact 32-bit platforms. But maybe not, and either way, it's not
quite correct. This commit fixes that to deal with `unsigned long`
rather than `u32`.

Cc: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
zx2c4 authored and gregkh committed May 30, 2022
1 parent 5064550 commit c47f215
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -1261,15 +1261,15 @@ int random_online_cpu(unsigned int cpu)
}
#endif

static u32 get_reg(struct fast_pool *f, struct pt_regs *regs)
static unsigned long get_reg(struct fast_pool *f, struct pt_regs *regs)
{
u32 *ptr = (u32 *)regs;
unsigned long *ptr = (unsigned long *)regs;
unsigned int idx;

if (regs == NULL)
return 0;
idx = READ_ONCE(f->reg_idx);
if (idx >= sizeof(struct pt_regs) / sizeof(u32))
if (idx >= sizeof(struct pt_regs) / sizeof(unsigned long))
idx = 0;
ptr += idx++;
WRITE_ONCE(f->reg_idx, idx);
Expand Down

0 comments on commit c47f215

Please sign in to comment.