Skip to content

Commit a251c17

Browse files
committed
treewide: use get_random_u32() when possible
The prandom_u32() function has been a deprecated inline wrapper around get_random_u32() for several releases now, and compiles down to the exact same code. Replace the deprecated wrapper with a direct call to the real function. The same also applies to get_random_int(), which is just a wrapper around get_random_u32(). This was done as a basic find and replace. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: Yury Norov <yury.norov@gmail.com> Reviewed-by: Jan Kara <jack@suse.cz> # for ext4 Acked-by: Toke Høiland-Jørgensen <toke@toke.dk> # for sch_cake Acked-by: Chuck Lever <chuck.lever@oracle.com> # for nfsd Acked-by: Jakub Kicinski <kuba@kernel.org> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com> # for thunderbolt Acked-by: Darrick J. Wong <djwong@kernel.org> # for xfs Acked-by: Helge Deller <deller@gmx.de> # for parisc Acked-by: Heiko Carstens <hca@linux.ibm.com> # for s390 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent f743f16 commit a251c17

File tree

71 files changed

+100
-100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+100
-100
lines changed

Documentation/networking/filter.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ Possible BPF extensions are shown in the following table:
305305
vlan_tci skb_vlan_tag_get(skb)
306306
vlan_avail skb_vlan_tag_present(skb)
307307
vlan_tpid skb->vlan_proto
308-
rand prandom_u32()
308+
rand get_random_u32()
309309
=================================== =================================================
310310

311311
These extensions can also be prefixed with '#'.

arch/parisc/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ __get_wchan(struct task_struct *p)
288288

289289
static inline unsigned long brk_rnd(void)
290290
{
291-
return (get_random_int() & BRK_RND_MASK) << PAGE_SHIFT;
291+
return (get_random_u32() & BRK_RND_MASK) << PAGE_SHIFT;
292292
}
293293

294294
unsigned long arch_randomize_brk(struct mm_struct *mm)

arch/parisc/kernel/sys_parisc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,14 @@ static unsigned long mmap_rnd(void)
239239
unsigned long rnd = 0;
240240

241241
if (current->flags & PF_RANDOMIZE)
242-
rnd = get_random_int() & MMAP_RND_MASK;
242+
rnd = get_random_u32() & MMAP_RND_MASK;
243243

244244
return rnd << PAGE_SHIFT;
245245
}
246246

247247
unsigned long arch_mmap_rnd(void)
248248
{
249-
return (get_random_int() & MMAP_RND_MASK) << PAGE_SHIFT;
249+
return (get_random_u32() & MMAP_RND_MASK) << PAGE_SHIFT;
250250
}
251251

252252
static unsigned long mmap_legacy_base(void)

arch/s390/mm/mmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static inline int mmap_is_legacy(struct rlimit *rlim_stack)
3737

3838
unsigned long arch_mmap_rnd(void)
3939
{
40-
return (get_random_int() & MMAP_RND_MASK) << PAGE_SHIFT;
40+
return (get_random_u32() & MMAP_RND_MASK) << PAGE_SHIFT;
4141
}
4242

4343
static unsigned long mmap_base_legacy(unsigned long rnd)

arch/x86/kernel/cpu/amd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)
503503
va_align.flags = ALIGN_VA_32 | ALIGN_VA_64;
504504

505505
/* A random value per boot for bit slice [12:upper_bit) */
506-
va_align.bits = get_random_int() & va_align.mask;
506+
va_align.bits = get_random_u32() & va_align.mask;
507507
}
508508

509509
if (cpu_has(c, X86_FEATURE_MWAITX))

drivers/gpu/drm/i915/i915_gem_gtt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ static u64 random_offset(u64 start, u64 end, u64 len, u64 align)
137137
range = round_down(end - len, align) - round_up(start, align);
138138
if (range) {
139139
if (sizeof(unsigned long) == sizeof(u64)) {
140-
addr = get_random_long();
140+
addr = get_random_u64();
141141
} else {
142-
addr = get_random_int();
142+
addr = get_random_u32();
143143
if (range > U32_MAX) {
144144
addr <<= 32;
145-
addr |= get_random_int();
145+
addr |= get_random_u32();
146146
}
147147
}
148148
div64_u64_rem(addr, range, &addr);

drivers/gpu/drm/i915/selftests/i915_selftest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static int __run_selftests(const char *name,
135135
int err = 0;
136136

137137
while (!i915_selftest.random_seed)
138-
i915_selftest.random_seed = get_random_int();
138+
i915_selftest.random_seed = get_random_u32();
139139

140140
i915_selftest.timeout_jiffies =
141141
i915_selftest.timeout_ms ?

drivers/gpu/drm/tests/drm_buddy_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ static void drm_test_buddy_alloc_limit(struct kunit *test)
729729
static int drm_buddy_init_test(struct kunit *test)
730730
{
731731
while (!random_seed)
732-
random_seed = get_random_int();
732+
random_seed = get_random_u32();
733733

734734
return 0;
735735
}

drivers/gpu/drm/tests/drm_mm_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2212,7 +2212,7 @@ static void drm_test_mm_color_evict_range(struct kunit *test)
22122212
static int drm_mm_init_test(struct kunit *test)
22132213
{
22142214
while (!random_seed)
2215-
random_seed = get_random_int();
2215+
random_seed = get_random_u32();
22162216

22172217
return 0;
22182218
}

drivers/infiniband/hw/cxgb4/cm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ static int send_connect(struct c4iw_ep *ep)
734734
&ep->com.remote_addr;
735735
int ret;
736736
enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
737-
u32 isn = (prandom_u32() & ~7UL) - 1;
737+
u32 isn = (get_random_u32() & ~7UL) - 1;
738738
struct net_device *netdev;
739739
u64 params;
740740

@@ -2469,7 +2469,7 @@ static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
24692469
}
24702470

24712471
if (!is_t4(adapter_type)) {
2472-
u32 isn = (prandom_u32() & ~7UL) - 1;
2472+
u32 isn = (get_random_u32() & ~7UL) - 1;
24732473

24742474
skb = get_skb(skb, roundup(sizeof(*rpl5), 16), GFP_KERNEL);
24752475
rpl5 = __skb_put_zero(skb, roundup(sizeof(*rpl5), 16));

0 commit comments

Comments
 (0)