Skip to content

Commit 3f649ab

Browse files
committed
treewide: Remove uninitialized_var() usage
Using uninitialized_var() is dangerous as it papers over real bugs[1] (or can in the future), and suppresses unrelated compiler warnings (e.g. "unused variable"). If the compiler thinks it is uninitialized, either simply initialize the variable or make compiler changes. In preparation for removing[2] the[3] macro[4], remove all remaining needless uses with the following script: git grep '\buninitialized_var\b' | cut -d: -f1 | sort -u | \ xargs perl -pi -e \ 's/\buninitialized_var\(([^\)]+)\)/\1/g; s:\s*/\* (GCC be quiet|to make compiler happy) \*/$::g;' drivers/video/fbdev/riva/riva_hw.c was manually tweaked to avoid pathological white-space. No outstanding warnings were found building allmodconfig with GCC 9.3.0 for x86_64, i386, arm64, arm, powerpc, powerpc64le, s390x, mips, sparc64, alpha, and m68k. [1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/ [2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/ [3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/ [4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/ Reviewed-by: Leon Romanovsky <leonro@mellanox.com> # drivers/infiniband and mlx4/mlx5 Acked-by: Jason Gunthorpe <jgg@mellanox.com> # IB Acked-by: Kalle Valo <kvalo@codeaurora.org> # wireless drivers Reviewed-by: Chao Yu <yuchao0@huawei.com> # erofs Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent d8b44b5 commit 3f649ab

File tree

179 files changed

+278
-279
lines changed

Some content is hidden

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

179 files changed

+278
-279
lines changed

arch/arm/mach-sa1100/assabet.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ static void __init map_sa1100_gpio_regs( void )
652652
*/
653653
static void __init get_assabet_scr(void)
654654
{
655-
unsigned long uninitialized_var(scr), i;
655+
unsigned long scr, i;
656656

657657
GPDR |= 0x3fc; /* Configure GPIO 9:2 as outputs */
658658
GPSR = 0x3fc; /* Write 0xFF to GPIO 9:2 */

arch/arm/mm/alignment.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ static int alignment_get_thumb(struct pt_regs *regs, u16 *ip, u16 *inst)
799799
static int
800800
do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
801801
{
802-
union offset_union uninitialized_var(offset);
802+
union offset_union offset;
803803
unsigned long instrptr;
804804
int (*handler)(unsigned long addr, u32 instr, struct pt_regs *regs);
805805
unsigned int type;

arch/ia64/kernel/process.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static void
445445
do_copy_task_regs (struct task_struct *task, struct unw_frame_info *info, void *arg)
446446
{
447447
unsigned long mask, sp, nat_bits = 0, ar_rnat, urbs_end, cfm;
448-
unsigned long uninitialized_var(ip); /* GCC be quiet */
448+
unsigned long ip;
449449
elf_greg_t *dst = arg;
450450
struct pt_regs *pt;
451451
char nat;

arch/ia64/mm/discontig.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static void *per_cpu_node_setup(void *cpu_data, int node)
180180
void __init setup_per_cpu_areas(void)
181181
{
182182
struct pcpu_alloc_info *ai;
183-
struct pcpu_group_info *uninitialized_var(gi);
183+
struct pcpu_group_info *gi;
184184
unsigned int *cpu_map;
185185
void *base;
186186
unsigned long base_offset;

arch/ia64/mm/tlb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ EXPORT_SYMBOL(flush_tlb_range);
369369

370370
void ia64_tlb_init(void)
371371
{
372-
ia64_ptce_info_t uninitialized_var(ptce_info); /* GCC be quiet */
372+
ia64_ptce_info_t ptce_info;
373373
u64 tr_pgbits;
374374
long status;
375375
pal_vm_info_1_u_t vm_info_1;

arch/mips/lib/dump_tlb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void dump_tlb(int first, int last)
7979
unsigned int pagemask, guestctl1 = 0, c0, c1, i;
8080
unsigned long asidmask = cpu_asid_mask(&current_cpu_data);
8181
int asidwidth = DIV_ROUND_UP(ilog2(asidmask) + 1, 4);
82-
unsigned long uninitialized_var(s_mmid);
82+
unsigned long s_mmid;
8383
#ifdef CONFIG_32BIT
8484
bool xpa = cpu_has_xpa && (read_c0_pagegrain() & PG_ELPA);
8585
int pwidth = xpa ? 11 : 8;

arch/mips/mm/init.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void setup_zero_pages(void)
8383
static void *__kmap_pgprot(struct page *page, unsigned long addr, pgprot_t prot)
8484
{
8585
enum fixed_addresses idx;
86-
unsigned int uninitialized_var(old_mmid);
86+
unsigned int old_mmid;
8787
unsigned long vaddr, flags, entrylo;
8888
unsigned long old_ctx;
8989
pte_t pte;

arch/mips/mm/tlb-r4k.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
119119
if (size <= (current_cpu_data.tlbsizeftlbsets ?
120120
current_cpu_data.tlbsize / 8 :
121121
current_cpu_data.tlbsize / 2)) {
122-
unsigned long old_entryhi, uninitialized_var(old_mmid);
122+
unsigned long old_entryhi, old_mmid;
123123
int newpid = cpu_asid(cpu, mm);
124124

125125
old_entryhi = read_c0_entryhi();
@@ -213,7 +213,7 @@ void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
213213
int cpu = smp_processor_id();
214214

215215
if (cpu_context(cpu, vma->vm_mm) != 0) {
216-
unsigned long uninitialized_var(old_mmid);
216+
unsigned long old_mmid;
217217
unsigned long flags, old_entryhi;
218218
int idx;
219219

@@ -382,7 +382,7 @@ void add_wired_entry(unsigned long entrylo0, unsigned long entrylo1,
382382
#ifdef CONFIG_XPA
383383
panic("Broken for XPA kernels");
384384
#else
385-
unsigned int uninitialized_var(old_mmid);
385+
unsigned int old_mmid;
386386
unsigned long flags;
387387
unsigned long wired;
388388
unsigned long old_pagemask;

arch/powerpc/kvm/book3s_64_mmu_radix.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ unsigned long __kvmhv_copy_tofrom_guest_radix(int lpid, int pid,
3333
gva_t eaddr, void *to, void *from,
3434
unsigned long n)
3535
{
36-
int uninitialized_var(old_pid), old_lpid;
36+
int old_pid, old_lpid;
3737
unsigned long quadrant, ret = n;
3838
bool is_load = !!to;
3939

arch/powerpc/kvm/powerpc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ static inline u32 dp_to_sp(u64 fprd)
11101110
static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu)
11111111
{
11121112
struct kvm_run *run = vcpu->run;
1113-
u64 uninitialized_var(gpr);
1113+
u64 gpr;
11141114

11151115
if (run->mmio.len > sizeof(gpr)) {
11161116
printk(KERN_ERR "bad MMIO length: %d\n", run->mmio.len);

arch/powerpc/platforms/52xx/mpc52xx_pic.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static int mpc52xx_irqhost_map(struct irq_domain *h, unsigned int virq,
340340
{
341341
int l1irq;
342342
int l2irq;
343-
struct irq_chip *uninitialized_var(irqchip);
343+
struct irq_chip *irqchip;
344344
void *hndlr;
345345
int type;
346346
u32 reg;

arch/s390/kernel/smp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static int pcpu_sigp_retry(struct pcpu *pcpu, u8 order, u32 parm)
146146

147147
static inline int pcpu_stopped(struct pcpu *pcpu)
148148
{
149-
u32 uninitialized_var(status);
149+
u32 status;
150150

151151
if (__pcpu_sigp(pcpu->address, SIGP_SENSE,
152152
0, &status) != SIGP_CC_STATUS_STORED)

arch/x86/kernel/quirks.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void ich_force_hpet_resume(void)
9595
static void ich_force_enable_hpet(struct pci_dev *dev)
9696
{
9797
u32 val;
98-
u32 uninitialized_var(rcba);
98+
u32 rcba;
9999
int err = 0;
100100

101101
if (hpet_address || force_hpet_address)
@@ -185,7 +185,7 @@ static void hpet_print_force_info(void)
185185
static void old_ich_force_hpet_resume(void)
186186
{
187187
u32 val;
188-
u32 uninitialized_var(gen_cntl);
188+
u32 gen_cntl;
189189

190190
if (!force_hpet_address || !cached_dev)
191191
return;
@@ -207,7 +207,7 @@ static void old_ich_force_hpet_resume(void)
207207
static void old_ich_force_enable_hpet(struct pci_dev *dev)
208208
{
209209
u32 val;
210-
u32 uninitialized_var(gen_cntl);
210+
u32 gen_cntl;
211211

212212
if (hpet_address || force_hpet_address)
213213
return;
@@ -298,7 +298,7 @@ static void vt8237_force_hpet_resume(void)
298298

299299
static void vt8237_force_enable_hpet(struct pci_dev *dev)
300300
{
301-
u32 uninitialized_var(val);
301+
u32 val;
302302

303303
if (hpet_address || force_hpet_address)
304304
return;
@@ -429,7 +429,7 @@ static void nvidia_force_hpet_resume(void)
429429

430430
static void nvidia_force_enable_hpet(struct pci_dev *dev)
431431
{
432-
u32 uninitialized_var(val);
432+
u32 val;
433433

434434
if (hpet_address || force_hpet_address)
435435
return;

arch/x86/kvm/mmu/mmu.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,7 @@ static int kvm_age_rmapp(struct kvm *kvm, struct kvm_rmap_head *rmap_head,
19861986
unsigned long data)
19871987
{
19881988
u64 *sptep;
1989-
struct rmap_iterator uninitialized_var(iter);
1989+
struct rmap_iterator iter;
19901990
int young = 0;
19911991

19921992
for_each_rmap_spte(rmap_head, &iter, sptep)

arch/x86/kvm/mmu/paging_tmpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
314314
{
315315
int ret;
316316
pt_element_t pte;
317-
pt_element_t __user *uninitialized_var(ptep_user);
317+
pt_element_t __user *ptep_user;
318318
gfn_t table_gfn;
319319
u64 pt_access, pte_access;
320320
unsigned index, accessed_dirty, pte_pkey;

arch/x86/kvm/x86.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -9927,7 +9927,7 @@ void kvm_arch_sync_events(struct kvm *kvm)
99279927
int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size)
99289928
{
99299929
int i, r;
9930-
unsigned long hva, uninitialized_var(old_npages);
9930+
unsigned long hva, old_npages;
99319931
struct kvm_memslots *slots = kvm_memslots(kvm);
99329932
struct kvm_memory_slot *slot;
99339933

block/blk-merge.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio,
473473
struct scatterlist *sglist,
474474
struct scatterlist **sg)
475475
{
476-
struct bio_vec uninitialized_var(bvec), bvprv = { NULL };
476+
struct bio_vec bvec, bvprv = { NULL };
477477
struct bvec_iter iter;
478478
int nsegs = 0;
479479
bool new_bio = false;

drivers/acpi/acpi_pad.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static void round_robin_cpu(unsigned int tsk_index)
8888
cpumask_var_t tmp;
8989
int cpu;
9090
unsigned long min_weight = -1;
91-
unsigned long uninitialized_var(preferred_cpu);
91+
unsigned long preferred_cpu;
9292

9393
if (!alloc_cpumask_var(&tmp, GFP_KERNEL))
9494
return;

drivers/ata/libata-scsi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static ssize_t ata_scsi_park_show(struct device *device,
9393
struct ata_link *link;
9494
struct ata_device *dev;
9595
unsigned long now;
96-
unsigned int uninitialized_var(msecs);
96+
unsigned int msecs;
9797
int rc = 0;
9898

9999
ap = ata_shost_to_port(sdev->host);

drivers/atm/zatm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ static int open_tx_first(struct atm_vcc *vcc)
940940
vcc->qos.txtp.max_pcr >= ATM_OC3_PCR);
941941
if (unlimited && zatm_dev->ubr != -1) zatm_vcc->shaper = zatm_dev->ubr;
942942
else {
943-
int uninitialized_var(pcr);
943+
int pcr;
944944

945945
if (unlimited) vcc->qos.txtp.max_sdu = ATM_MAX_AAL5_PDU;
946946
if ((zatm_vcc->shaper = alloc_shaper(vcc->dev,&pcr,

drivers/block/drbd/drbd_nl.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -3423,7 +3423,7 @@ int drbd_adm_dump_devices(struct sk_buff *skb, struct netlink_callback *cb)
34233423
{
34243424
struct nlattr *resource_filter;
34253425
struct drbd_resource *resource;
3426-
struct drbd_device *uninitialized_var(device);
3426+
struct drbd_device *device;
34273427
int minor, err, retcode;
34283428
struct drbd_genlmsghdr *dh;
34293429
struct device_info device_info;
@@ -3512,7 +3512,7 @@ int drbd_adm_dump_connections(struct sk_buff *skb, struct netlink_callback *cb)
35123512
{
35133513
struct nlattr *resource_filter;
35143514
struct drbd_resource *resource = NULL, *next_resource;
3515-
struct drbd_connection *uninitialized_var(connection);
3515+
struct drbd_connection *connection;
35163516
int err = 0, retcode;
35173517
struct drbd_genlmsghdr *dh;
35183518
struct connection_info connection_info;
@@ -3674,7 +3674,7 @@ int drbd_adm_dump_peer_devices(struct sk_buff *skb, struct netlink_callback *cb)
36743674
{
36753675
struct nlattr *resource_filter;
36763676
struct drbd_resource *resource;
3677-
struct drbd_device *uninitialized_var(device);
3677+
struct drbd_device *device;
36783678
struct drbd_peer_device *peer_device = NULL;
36793679
int minor, err, retcode;
36803680
struct drbd_genlmsghdr *dh;

drivers/block/rbd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,7 @@ static int rbd_object_map_update_finish(struct rbd_obj_request *obj_req,
19931993
struct rbd_device *rbd_dev = obj_req->img_request->rbd_dev;
19941994
struct ceph_osd_data *osd_data;
19951995
u64 objno;
1996-
u8 state, new_state, uninitialized_var(current_state);
1996+
u8 state, new_state, current_state;
19971997
bool has_current_state;
19981998
void *p;
19991999

drivers/clk/clk-gate.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static void clk_gate_endisable(struct clk_hw *hw, int enable)
5656
{
5757
struct clk_gate *gate = to_clk_gate(hw);
5858
int set = gate->flags & CLK_GATE_SET_TO_DISABLE ? 1 : 0;
59-
unsigned long uninitialized_var(flags);
59+
unsigned long flags;
6060
u32 reg;
6161

6262
set ^= enable;

drivers/firewire/ohci.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ static void context_tasklet(unsigned long data)
10991099
static int context_add_buffer(struct context *ctx)
11001100
{
11011101
struct descriptor_buffer *desc;
1102-
dma_addr_t uninitialized_var(bus_addr);
1102+
dma_addr_t bus_addr;
11031103
int offset;
11041104

11051105
/*
@@ -1289,7 +1289,7 @@ static int at_context_queue_packet(struct context *ctx,
12891289
struct fw_packet *packet)
12901290
{
12911291
struct fw_ohci *ohci = ctx->ohci;
1292-
dma_addr_t d_bus, uninitialized_var(payload_bus);
1292+
dma_addr_t d_bus, payload_bus;
12931293
struct driver_data *driver_data;
12941294
struct descriptor *d, *last;
12951295
__le32 *header;
@@ -2445,7 +2445,7 @@ static int ohci_set_config_rom(struct fw_card *card,
24452445
{
24462446
struct fw_ohci *ohci;
24472447
__be32 *next_config_rom;
2448-
dma_addr_t uninitialized_var(next_config_rom_bus);
2448+
dma_addr_t next_config_rom_bus;
24492449

24502450
ohci = fw_ohci(card);
24512451

@@ -2933,10 +2933,10 @@ static struct fw_iso_context *ohci_allocate_iso_context(struct fw_card *card,
29332933
int type, int channel, size_t header_size)
29342934
{
29352935
struct fw_ohci *ohci = fw_ohci(card);
2936-
struct iso_context *uninitialized_var(ctx);
2937-
descriptor_callback_t uninitialized_var(callback);
2938-
u64 *uninitialized_var(channels);
2939-
u32 *uninitialized_var(mask), uninitialized_var(regs);
2936+
struct iso_context *ctx;
2937+
descriptor_callback_t callback;
2938+
u64 *channels;
2939+
u32 *mask, regs;
29402940
int index, ret = -EBUSY;
29412941

29422942
spin_lock_irq(&ohci->lock);

drivers/gpu/drm/bridge/sil-sii8620.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ static void sii8620_set_auto_zone(struct sii8620 *ctx)
986986

987987
static void sii8620_stop_video(struct sii8620 *ctx)
988988
{
989-
u8 uninitialized_var(val);
989+
u8 val;
990990

991991
sii8620_write_seq_static(ctx,
992992
REG_TPI_INTR_EN, 0,

drivers/gpu/drm/drm_edid.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3051,7 +3051,7 @@ static int drm_cvt_modes(struct drm_connector *connector,
30513051
const u8 empty[3] = { 0, 0, 0 };
30523052

30533053
for (i = 0; i < 4; i++) {
3054-
int uninitialized_var(width), height;
3054+
int width, height;
30553055
cvt = &(timing->data.other_data.data.cvt[i]);
30563056

30573057
if (!memcmp(cvt->code, empty, 3))

drivers/gpu/drm/exynos/exynos_drm_dsi.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,9 @@ static unsigned long exynos_dsi_pll_find_pms(struct exynos_dsi *dsi,
547547
unsigned long best_freq = 0;
548548
u32 min_delta = 0xffffffff;
549549
u8 p_min, p_max;
550-
u8 _p, uninitialized_var(best_p);
551-
u16 _m, uninitialized_var(best_m);
552-
u8 _s, uninitialized_var(best_s);
550+
u8 _p, best_p;
551+
u16 _m, best_m;
552+
u8 _s, best_s;
553553

554554
p_min = DIV_ROUND_UP(fin, (12 * MHZ));
555555
p_max = fin / (6 * MHZ);

drivers/gpu/drm/i915/display/intel_fbc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ static int intel_fbc_alloc_cfb(struct drm_i915_private *dev_priv,
474474
unsigned int size, unsigned int fb_cpp)
475475
{
476476
struct intel_fbc *fbc = &dev_priv->fbc;
477-
struct drm_mm_node *uninitialized_var(compressed_llb);
477+
struct drm_mm_node *compressed_llb;
478478
int ret;
479479

480480
drm_WARN_ON(&dev_priv->drm,

drivers/gpu/drm/i915/gt/intel_lrc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ static struct i915_request *
11031103
__unwind_incomplete_requests(struct intel_engine_cs *engine)
11041104
{
11051105
struct i915_request *rq, *rn, *active = NULL;
1106-
struct list_head *uninitialized_var(pl);
1106+
struct list_head *pl;
11071107
int prio = I915_PRIORITY_INVALID;
11081108

11091109
lockdep_assert_held(&engine->active.lock);

drivers/gpu/drm/i915/intel_uncore.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,7 @@ int __intel_wait_for_register_fw(struct intel_uncore *uncore,
19911991
unsigned int slow_timeout_ms,
19921992
u32 *out_value)
19931993
{
1994-
u32 uninitialized_var(reg_value);
1994+
u32 reg_value;
19951995
#define done (((reg_value = intel_uncore_read_fw(uncore, reg)) & mask) == value)
19961996
int ret;
19971997

drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ dw_mipi_dsi_get_lane_mbps(void *priv_data, const struct drm_display_mode *mode,
517517
unsigned long best_freq = 0;
518518
unsigned long fvco_min, fvco_max, fin, fout;
519519
unsigned int min_prediv, max_prediv;
520-
unsigned int _prediv, uninitialized_var(best_prediv);
521-
unsigned long _fbdiv, uninitialized_var(best_fbdiv);
520+
unsigned int _prediv, best_prediv;
521+
unsigned long _fbdiv, best_fbdiv;
522522
unsigned long min_delta = ULONG_MAX;
523523

524524
dsi->format = format;

drivers/i2c/busses/i2c-rk3x.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static void rk3x_i2c_handle_read(struct rk3x_i2c *i2c, unsigned int ipd)
415415
{
416416
unsigned int i;
417417
unsigned int len = i2c->msg->len - i2c->processed;
418-
u32 uninitialized_var(val);
418+
u32 val;
419419
u8 byte;
420420

421421
/* we only care for MBRF here. */

0 commit comments

Comments
 (0)