Skip to content

Commit

Permalink
treewide: use get_random_u32() when possible
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Kees Cook <[email protected]>
Reviewed-by: Yury Norov <[email protected]>
Reviewed-by: Jan Kara <[email protected]> # for ext4
Acked-by: Toke Høiland-Jørgensen <[email protected]> # for sch_cake
Acked-by: Chuck Lever <[email protected]> # for nfsd
Acked-by: Jakub Kicinski <[email protected]>
Acked-by: Mika Westerberg <[email protected]> # for thunderbolt
Acked-by: Darrick J. Wong <[email protected]> # for xfs
Acked-by: Helge Deller <[email protected]> # for parisc
Acked-by: Heiko Carstens <[email protected]> # for s390
Signed-off-by: Jason A. Donenfeld <[email protected]>
  • Loading branch information
zx2c4 committed Oct 11, 2022
1 parent f743f16 commit a251c17
Show file tree
Hide file tree
Showing 71 changed files with 100 additions and 100 deletions.
2 changes: 1 addition & 1 deletion Documentation/networking/filter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ Possible BPF extensions are shown in the following table:
vlan_tci skb_vlan_tag_get(skb)
vlan_avail skb_vlan_tag_present(skb)
vlan_tpid skb->vlan_proto
rand prandom_u32()
rand get_random_u32()
=================================== =================================================

These extensions can also be prefixed with '#'.
Expand Down
2 changes: 1 addition & 1 deletion arch/parisc/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ __get_wchan(struct task_struct *p)

static inline unsigned long brk_rnd(void)
{
return (get_random_int() & BRK_RND_MASK) << PAGE_SHIFT;
return (get_random_u32() & BRK_RND_MASK) << PAGE_SHIFT;
}

unsigned long arch_randomize_brk(struct mm_struct *mm)
Expand Down
4 changes: 2 additions & 2 deletions arch/parisc/kernel/sys_parisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ static unsigned long mmap_rnd(void)
unsigned long rnd = 0;

if (current->flags & PF_RANDOMIZE)
rnd = get_random_int() & MMAP_RND_MASK;
rnd = get_random_u32() & MMAP_RND_MASK;

return rnd << PAGE_SHIFT;
}

unsigned long arch_mmap_rnd(void)
{
return (get_random_int() & MMAP_RND_MASK) << PAGE_SHIFT;
return (get_random_u32() & MMAP_RND_MASK) << PAGE_SHIFT;
}

static unsigned long mmap_legacy_base(void)
Expand Down
2 changes: 1 addition & 1 deletion arch/s390/mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static inline int mmap_is_legacy(struct rlimit *rlim_stack)

unsigned long arch_mmap_rnd(void)
{
return (get_random_int() & MMAP_RND_MASK) << PAGE_SHIFT;
return (get_random_u32() & MMAP_RND_MASK) << PAGE_SHIFT;
}

static unsigned long mmap_base_legacy(unsigned long rnd)
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpu/amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)
va_align.flags = ALIGN_VA_32 | ALIGN_VA_64;

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

if (cpu_has(c, X86_FEATURE_MWAITX))
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpu/drm/i915/i915_gem_gtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ static u64 random_offset(u64 start, u64 end, u64 len, u64 align)
range = round_down(end - len, align) - round_up(start, align);
if (range) {
if (sizeof(unsigned long) == sizeof(u64)) {
addr = get_random_long();
addr = get_random_u64();
} else {
addr = get_random_int();
addr = get_random_u32();
if (range > U32_MAX) {
addr <<= 32;
addr |= get_random_int();
addr |= get_random_u32();
}
}
div64_u64_rem(addr, range, &addr);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/selftests/i915_selftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static int __run_selftests(const char *name,
int err = 0;

while (!i915_selftest.random_seed)
i915_selftest.random_seed = get_random_int();
i915_selftest.random_seed = get_random_u32();

i915_selftest.timeout_jiffies =
i915_selftest.timeout_ms ?
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/tests/drm_buddy_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ static void drm_test_buddy_alloc_limit(struct kunit *test)
static int drm_buddy_init_test(struct kunit *test)
{
while (!random_seed)
random_seed = get_random_int();
random_seed = get_random_u32();

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/tests/drm_mm_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2212,7 +2212,7 @@ static void drm_test_mm_color_evict_range(struct kunit *test)
static int drm_mm_init_test(struct kunit *test)
{
while (!random_seed)
random_seed = get_random_int();
random_seed = get_random_u32();

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/infiniband/hw/cxgb4/cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ static int send_connect(struct c4iw_ep *ep)
&ep->com.remote_addr;
int ret;
enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
u32 isn = (prandom_u32() & ~7UL) - 1;
u32 isn = (get_random_u32() & ~7UL) - 1;
struct net_device *netdev;
u64 params;

Expand Down Expand Up @@ -2469,7 +2469,7 @@ static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
}

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

skb = get_skb(skb, roundup(sizeof(*rpl5), 16), GFP_KERNEL);
rpl5 = __skb_put_zero(skb, roundup(sizeof(*rpl5), 16));
Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/hw/hfi1/tid_rdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ void hfi1_kern_init_ctxt_generations(struct hfi1_ctxtdata *rcd)
int i;

for (i = 0; i < RXE_NUM_TID_FLOWS; i++) {
rcd->flows[i].generation = mask_generation(prandom_u32());
rcd->flows[i].generation = mask_generation(get_random_u32());
kern_set_hw_flow(rcd, KERN_GENERATION_RESERVED, i);
}
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/hw/mlx4/mad.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void __propagate_pkey_ev(struct mlx4_ib_dev *dev, int port_num,
__be64 mlx4_ib_gen_node_guid(void)
{
#define NODE_GUID_HI ((u64) (((u64)IB_OPENIB_OUI) << 40))
return cpu_to_be64(NODE_GUID_HI | prandom_u32());
return cpu_to_be64(NODE_GUID_HI | get_random_u32());
}

__be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/ulp/ipoib/ipoib_cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ static int ipoib_cm_req_handler(struct ib_cm_id *cm_id,
goto err_qp;
}

psn = prandom_u32() & 0xffffff;
psn = get_random_u32() & 0xffffff;
ret = ipoib_cm_modify_rx_qp(dev, cm_id, p->qp, psn);
if (ret)
goto err_modify;
Expand Down
2 changes: 1 addition & 1 deletion drivers/md/raid5-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2994,7 +2994,7 @@ static int r5l_load_log(struct r5l_log *log)
}
create:
if (create_super) {
log->last_cp_seq = prandom_u32();
log->last_cp_seq = get_random_u32();
cp = 0;
r5l_log_write_empty_meta_block(log, cp, log->last_cp_seq);
/*
Expand Down
4 changes: 2 additions & 2 deletions drivers/media/test-drivers/vivid/vivid-touch-cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static void vivid_fill_buff_noise(__s16 *tch_buf, int size)

/* Fill 10% of the values within range -3 and 3, zero the others */
for (i = 0; i < size; i++) {
unsigned int rand = get_random_int();
unsigned int rand = get_random_u32();

if (rand % 10)
tch_buf[i] = 0;
Expand Down Expand Up @@ -272,7 +272,7 @@ void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf)
return;

if (test_pat_idx == 0)
dev->tch_pat_random = get_random_int();
dev->tch_pat_random = get_random_u32();
rand = dev->tch_pat_random;

switch (test_pattern) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/misc/habanalabs/gaudi2/gaudi2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2948,7 +2948,7 @@ static void gaudi2_user_interrupt_setup(struct hl_device *hdev)

static inline int gaudi2_get_non_zero_random_int(void)
{
int rand = get_random_int();
int rand = get_random_u32();

return rand ? rand : 1;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/bonding/bond_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4806,7 +4806,7 @@ static u32 bond_rr_gen_slave_id(struct bonding *bond)

switch (packets_per_slave) {
case 0:
slave_id = prandom_u32();
slave_id = get_random_u32();
break;
case 1:
slave_id = this_cpu_inc_return(*bond->rr_tx_counter);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/broadcom/cnic.c
Original file line number Diff line number Diff line change
Expand Up @@ -4164,7 +4164,7 @@ static int cnic_cm_init_bnx2_hw(struct cnic_dev *dev)
{
u32 seed;

seed = prandom_u32();
seed = get_random_u32();
cnic_ctx_wr(dev, 45, 0, seed);
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ static void chtls_pass_accept_rpl(struct sk_buff *skb,
opt2 |= WND_SCALE_EN_V(WSCALE_OK(tp));
rpl5->opt0 = cpu_to_be64(opt0);
rpl5->opt2 = cpu_to_be32(opt2);
rpl5->iss = cpu_to_be32((prandom_u32() & ~7UL) - 1);
rpl5->iss = cpu_to_be32((get_random_u32() & ~7UL) - 1);
set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
t4_set_arp_err_handler(skb, sk, chtls_accept_rpl_arp_failure);
cxgb4_l2t_send(csk->egress_dev, skb, csk->l2t_entry);
Expand Down
6 changes: 3 additions & 3 deletions drivers/net/ethernet/rocker/rocker_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static int rocker_reg_test(const struct rocker *rocker)
u64 test_reg;
u64 rnd;

rnd = prandom_u32();
rnd = get_random_u32();
rnd >>= 1;
rocker_write32(rocker, TEST_REG, rnd);
test_reg = rocker_read32(rocker, TEST_REG);
Expand All @@ -139,9 +139,9 @@ static int rocker_reg_test(const struct rocker *rocker)
return -EIO;
}

rnd = prandom_u32();
rnd = get_random_u32();
rnd <<= 31;
rnd |= prandom_u32();
rnd |= get_random_u32();
rocker_write64(rocker, TEST_REG64, rnd);
test_reg = rocker_read64(rocker, TEST_REG64);
if (test_reg != rnd * 2) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/wireless/marvell/mwifiex/cfg80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
tx_info->pkt_len = pkt_len;

mwifiex_form_mgmt_frame(skb, buf, len);
*cookie = prandom_u32() | 1;
*cookie = get_random_u32() | 1;

if (ieee80211_is_action(mgmt->frame_control))
skb = mwifiex_clone_skb_for_tx_status(priv,
Expand Down Expand Up @@ -303,7 +303,7 @@ mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
duration);

if (!ret) {
*cookie = prandom_u32() | 1;
*cookie = get_random_u32() | 1;
priv->roc_cfg.cookie = *cookie;
priv->roc_cfg.chan = *chan;

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/microchip/wilc1000/cfg80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ static int mgmt_tx(struct wiphy *wiphy,
const u8 *vendor_ie;
int ret = 0;

*cookie = prandom_u32();
*cookie = get_random_u32();
priv->tx_cookie = *cookie;
mgmt = (const struct ieee80211_mgmt *)buf;

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/quantenna/qtnfmac/cfg80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ qtnf_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
{
struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
const struct ieee80211_mgmt *mgmt_frame = (void *)params->buf;
u32 short_cookie = prandom_u32();
u32 short_cookie = get_random_u32();
u16 flags = 0;
u16 freq;

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/ti/wlcore/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6100,7 +6100,7 @@ static int wl1271_register_hw(struct wl1271 *wl)
wl1271_warning("Fuse mac address is zero. using random mac");
/* Use TI oui and a random nic */
oui_addr = WLCORE_TI_OUI_ADDRESS;
nic_addr = get_random_int();
nic_addr = get_random_u32();
} else {
oui_addr = wl->fuse_oui_addr;
/* fuse has the BD_ADDR, the WLAN addresses are the next two */
Expand Down
2 changes: 1 addition & 1 deletion drivers/nvme/common/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ u32 nvme_auth_get_seqnum(void)

mutex_lock(&nvme_dhchap_mutex);
if (!nvme_dhchap_seqnum)
nvme_dhchap_seqnum = prandom_u32();
nvme_dhchap_seqnum = get_random_u32();
else {
nvme_dhchap_seqnum++;
if (!nvme_dhchap_seqnum)
Expand Down
4 changes: 2 additions & 2 deletions drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static void send_act_open_req(struct cxgbi_sock *csk, struct sk_buff *skb,
} else if (is_t5(lldi->adapter_type)) {
struct cpl_t5_act_open_req *req =
(struct cpl_t5_act_open_req *)skb->head;
u32 isn = (prandom_u32() & ~7UL) - 1;
u32 isn = (get_random_u32() & ~7UL) - 1;

INIT_TP_WR(req, 0);
OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
Expand Down Expand Up @@ -282,7 +282,7 @@ static void send_act_open_req(struct cxgbi_sock *csk, struct sk_buff *skb,
} else {
struct cpl_t6_act_open_req *req =
(struct cpl_t6_act_open_req *)skb->head;
u32 isn = (prandom_u32() & ~7UL) - 1;
u32 isn = (get_random_u32() & ~7UL) - 1;

INIT_TP_WR(req, 0);
OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
Expand Down
2 changes: 1 addition & 1 deletion drivers/target/iscsi/cxgbit/cxgbit_cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ cxgbit_pass_accept_rpl(struct cxgbit_sock *csk, struct cpl_pass_accept_req *req)
opt2 |= CONG_CNTRL_V(CONG_ALG_NEWRENO);

opt2 |= T5_ISS_F;
rpl5->iss = cpu_to_be32((prandom_u32() & ~7UL) - 1);
rpl5->iss = cpu_to_be32((get_random_u32() & ~7UL) - 1);

opt2 |= T5_OPT_2_VALID_F;

Expand Down
2 changes: 1 addition & 1 deletion drivers/thunderbolt/xdomain.c
Original file line number Diff line number Diff line change
Expand Up @@ -2437,7 +2437,7 @@ int tb_xdomain_init(void)
tb_property_add_immediate(xdomain_property_dir, "deviceid", 0x1);
tb_property_add_immediate(xdomain_property_dir, "devicerv", 0x80000100);

xdomain_property_block_gen = prandom_u32();
xdomain_property_block_gen = get_random_u32();
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/video/fbdev/uvesafb.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static int uvesafb_exec(struct uvesafb_ktask *task)
memcpy(&m->id, &uvesafb_cn_id, sizeof(m->id));
m->seq = seq;
m->len = len;
m->ack = prandom_u32();
m->ack = get_random_u32();

/* uvesafb_task structure */
memcpy(m + 1, &task->t, sizeof(task->t));
Expand Down
2 changes: 1 addition & 1 deletion fs/exfat/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ static int exfat_fill_inode(struct inode *inode, struct exfat_dir_entry *info)
inode->i_uid = sbi->options.fs_uid;
inode->i_gid = sbi->options.fs_gid;
inode_inc_iversion(inode);
inode->i_generation = prandom_u32();
inode->i_generation = get_random_u32();

if (info->attr & ATTR_SUBDIR) { /* directory */
inode->i_generation &= ~1;
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/ialloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ struct inode *__ext4_new_inode(struct user_namespace *mnt_userns,
EXT4_GROUP_INFO_IBITMAP_CORRUPT);
goto out;
}
inode->i_generation = prandom_u32();
inode->i_generation = get_random_u32();

/* Precompute checksum seed for inode metadata */
if (ext4_has_metadata_csum(sb)) {
Expand Down
4 changes: 2 additions & 2 deletions fs/ext4/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ static long swap_inode_boot_loader(struct super_block *sb,
inode->i_ctime = inode_bl->i_ctime = current_time(inode);
inode_inc_iversion(inode);

inode->i_generation = prandom_u32();
inode_bl->i_generation = prandom_u32();
inode->i_generation = get_random_u32();
inode_bl->i_generation = get_random_u32();
ext4_reset_inode_seed(inode);
ext4_reset_inode_seed(inode_bl);

Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/mmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ static unsigned int mmp_new_seq(void)
u32 new_seq;

do {
new_seq = prandom_u32();
new_seq = get_random_u32();
} while (new_seq > EXT4_MMP_SEQ_MAX);

return new_seq;
Expand Down
2 changes: 1 addition & 1 deletion fs/f2fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns,
inode->i_blocks = 0;
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
F2FS_I(inode)->i_crtime = inode->i_mtime;
inode->i_generation = prandom_u32();
inode->i_generation = get_random_u32();

if (S_ISDIR(inode->i_mode))
F2FS_I(inode)->i_current_depth = 1;
Expand Down
2 changes: 1 addition & 1 deletion fs/fat/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
inode->i_uid = sbi->options.fs_uid;
inode->i_gid = sbi->options.fs_gid;
inode_inc_iversion(inode);
inode->i_generation = prandom_u32();
inode->i_generation = get_random_u32();

if ((de->attr & ATTR_DIR) && !IS_FREE(de->name)) {
inode->i_generation &= ~1;
Expand Down
4 changes: 2 additions & 2 deletions fs/nfsd/nfs4state.c
Original file line number Diff line number Diff line change
Expand Up @@ -4375,8 +4375,8 @@ nfsd4_init_leases_net(struct nfsd_net *nn)
nn->nfsd4_grace = 90;
nn->somebody_reclaimed = false;
nn->track_reclaim_completes = false;
nn->clverifier_counter = prandom_u32();
nn->clientid_base = prandom_u32();
nn->clverifier_counter = get_random_u32();
nn->clientid_base = get_random_u32();
nn->clientid_counter = nn->clientid_base + 1;
nn->s2s_cp_cl_id = nn->clientid_counter++;

Expand Down
Loading

0 comments on commit a251c17

Please sign in to comment.