"default entropy content of hwrng per mill");
static void drop_current_rng(void);
+static int hwrng_init(struct hwrng *rng);
static void start_khwrngd(void);
static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
complete(&rng->cleanup_done);
}
-static void set_current_rng(struct hwrng *rng)
+static int set_current_rng(struct hwrng *rng)
{
+ int err;
+
BUG_ON(!mutex_is_locked(&rng_mutex));
+
+ err = hwrng_init(rng);
+ if (err)
+ return err;
+
drop_current_rng();
current_rng = rng;
+
+ return 0;
}
static void drop_current_rng(void)
mutex_unlock(&rng_mutex);
}
-static inline int hwrng_init(struct hwrng *rng)
+static int hwrng_init(struct hwrng *rng)
{
if (kref_get_unless_zero(&rng->ref))
goto skip_init;
err = -ENODEV;
list_for_each_entry(rng, &rng_list, list) {
if (strcmp(rng->name, buf) == 0) {
- if (rng == current_rng) {
- err = 0;
- break;
- }
- err = hwrng_init(rng);
- if (err)
- break;
- set_current_rng(rng);
err = 0;
+ if (rng != current_rng)
+ err = set_current_rng(rng);
break;
}
}
old_rng = current_rng;
err = 0;
if (!old_rng) {
- err = hwrng_init(rng);
+ err = set_current_rng(rng);
if (err)
goto out_unlock;
- set_current_rng(rng);
}
list_add_tail(&rng->list, &rng_list);
tail = list_entry(rng_list.prev, struct hwrng, list);
- if (hwrng_init(tail) == 0)
- set_current_rng(tail);
+ set_current_rng(tail);
}
}