mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-02 15:18:19 +00:00
random: use lockless method of accessing and updating f->reg_idx
Linus pointed out that there is a much more efficient way of avoiding
the problem that we were trying to address in commit 9dfa7bba35
:
"fix race in drivers/char/random.c:get_reg()".
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
parent
9dfa7bba35
commit
92e75428ff
1 changed files with 6 additions and 6 deletions
|
@ -1097,15 +1097,15 @@ static void add_interrupt_bench(cycles_t start)
|
||||||
static __u32 get_reg(struct fast_pool *f, struct pt_regs *regs)
|
static __u32 get_reg(struct fast_pool *f, struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
__u32 *ptr = (__u32 *) regs;
|
__u32 *ptr = (__u32 *) regs;
|
||||||
unsigned long flags;
|
unsigned int idx;
|
||||||
|
|
||||||
if (regs == NULL)
|
if (regs == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
local_irq_save(flags);
|
idx = READ_ONCE(f->reg_idx);
|
||||||
if (f->reg_idx >= sizeof(struct pt_regs) / sizeof(__u32))
|
if (idx >= sizeof(struct pt_regs) / sizeof(__u32))
|
||||||
f->reg_idx = 0;
|
idx = 0;
|
||||||
ptr += f->reg_idx++;
|
ptr += idx++;
|
||||||
local_irq_restore(flags);
|
WRITE_ONCE(f->reg_idx, idx);
|
||||||
return *ptr;
|
return *ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue