mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-26 12:12:13 +03:00
Linux SPL module init: Handle memory allocation failures correctly
Upon inspection of our code, I noticed that we assume that __alloc_percpu() cannot fail, and while it probably never has failed in practice, technically, it can fail, so we should handle that. Additionally, we incorrectly assume that `taskq_create()` in spl_kmem_cache_init() cannot fail. The same remark applies to it. Lastly, `spl-init()` failures should always return negative error values, but in some places, we are returning positive 1, which is incorrect. We change those values to their correct error codes. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu> Closes #13847
This commit is contained in:
@@ -705,7 +705,7 @@ spl_kvmem_init(void)
|
||||
* initialize each of the per-cpu seeds so that the sequences generated on each
|
||||
* CPU are guaranteed to never overlap in practice.
|
||||
*/
|
||||
static void __init
|
||||
static int __init
|
||||
spl_random_init(void)
|
||||
{
|
||||
uint64_t s[2];
|
||||
@@ -714,6 +714,9 @@ spl_random_init(void)
|
||||
spl_pseudo_entropy = __alloc_percpu(2 * sizeof (uint64_t),
|
||||
sizeof (uint64_t));
|
||||
|
||||
if (!spl_pseudo_entropy)
|
||||
return (-ENOMEM);
|
||||
|
||||
get_random_bytes(s, sizeof (s));
|
||||
|
||||
if (s[0] == 0 && s[1] == 0) {
|
||||
@@ -737,6 +740,8 @@ spl_random_init(void)
|
||||
wordp[0] = s[0];
|
||||
wordp[1] = s[1];
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -757,7 +762,8 @@ spl_init(void)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
spl_random_init();
|
||||
if ((rc = spl_random_init()))
|
||||
goto out0;
|
||||
|
||||
if ((rc = spl_kvmem_init()))
|
||||
goto out1;
|
||||
@@ -800,6 +806,8 @@ out3:
|
||||
out2:
|
||||
spl_kvmem_fini();
|
||||
out1:
|
||||
spl_random_fini();
|
||||
out0:
|
||||
return (rc);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user