Skip to content

Commit

Permalink
treewide: Remove uninitialized_var() usage
Browse files Browse the repository at this point in the history
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/[email protected]/
[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 <[email protected]> # drivers/infiniband and mlx4/mlx5
Acked-by: Jason Gunthorpe <[email protected]> # IB
Acked-by: Kalle Valo <[email protected]> # wireless drivers
Reviewed-by: Chao Yu <[email protected]> # erofs
Signed-off-by: Kees Cook <[email protected]>
  • Loading branch information
kees committed Jul 16, 2020
1 parent d8b44b5 commit 3f649ab
Show file tree
Hide file tree
Showing 179 changed files with 278 additions and 279 deletions.
2 changes: 1 addition & 1 deletion arch/arm/mach-sa1100/assabet.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ static void __init map_sa1100_gpio_regs( void )
*/
static void __init get_assabet_scr(void)
{
unsigned long uninitialized_var(scr), i;
unsigned long scr, i;

GPDR |= 0x3fc; /* Configure GPIO 9:2 as outputs */
GPSR = 0x3fc; /* Write 0xFF to GPIO 9:2 */
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/mm/alignment.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ static int alignment_get_thumb(struct pt_regs *regs, u16 *ip, u16 *inst)
static int
do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
{
union offset_union uninitialized_var(offset);
union offset_union offset;
unsigned long instrptr;
int (*handler)(unsigned long addr, u32 instr, struct pt_regs *regs);
unsigned int type;
Expand Down
2 changes: 1 addition & 1 deletion arch/ia64/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ static void
do_copy_task_regs (struct task_struct *task, struct unw_frame_info *info, void *arg)
{
unsigned long mask, sp, nat_bits = 0, ar_rnat, urbs_end, cfm;
unsigned long uninitialized_var(ip); /* GCC be quiet */
unsigned long ip;
elf_greg_t *dst = arg;
struct pt_regs *pt;
char nat;
Expand Down
2 changes: 1 addition & 1 deletion arch/ia64/mm/discontig.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static void *per_cpu_node_setup(void *cpu_data, int node)
void __init setup_per_cpu_areas(void)
{
struct pcpu_alloc_info *ai;
struct pcpu_group_info *uninitialized_var(gi);
struct pcpu_group_info *gi;
unsigned int *cpu_map;
void *base;
unsigned long base_offset;
Expand Down
2 changes: 1 addition & 1 deletion arch/ia64/mm/tlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ EXPORT_SYMBOL(flush_tlb_range);

void ia64_tlb_init(void)
{
ia64_ptce_info_t uninitialized_var(ptce_info); /* GCC be quiet */
ia64_ptce_info_t ptce_info;
u64 tr_pgbits;
long status;
pal_vm_info_1_u_t vm_info_1;
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/lib/dump_tlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void dump_tlb(int first, int last)
unsigned int pagemask, guestctl1 = 0, c0, c1, i;
unsigned long asidmask = cpu_asid_mask(&current_cpu_data);
int asidwidth = DIV_ROUND_UP(ilog2(asidmask) + 1, 4);
unsigned long uninitialized_var(s_mmid);
unsigned long s_mmid;
#ifdef CONFIG_32BIT
bool xpa = cpu_has_xpa && (read_c0_pagegrain() & PG_ELPA);
int pwidth = xpa ? 11 : 8;
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/mm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void setup_zero_pages(void)
static void *__kmap_pgprot(struct page *page, unsigned long addr, pgprot_t prot)
{
enum fixed_addresses idx;
unsigned int uninitialized_var(old_mmid);
unsigned int old_mmid;
unsigned long vaddr, flags, entrylo;
unsigned long old_ctx;
pte_t pte;
Expand Down
6 changes: 3 additions & 3 deletions arch/mips/mm/tlb-r4k.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
if (size <= (current_cpu_data.tlbsizeftlbsets ?
current_cpu_data.tlbsize / 8 :
current_cpu_data.tlbsize / 2)) {
unsigned long old_entryhi, uninitialized_var(old_mmid);
unsigned long old_entryhi, old_mmid;
int newpid = cpu_asid(cpu, mm);

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

if (cpu_context(cpu, vma->vm_mm) != 0) {
unsigned long uninitialized_var(old_mmid);
unsigned long old_mmid;
unsigned long flags, old_entryhi;
int idx;

Expand Down Expand Up @@ -382,7 +382,7 @@ void add_wired_entry(unsigned long entrylo0, unsigned long entrylo1,
#ifdef CONFIG_XPA
panic("Broken for XPA kernels");
#else
unsigned int uninitialized_var(old_mmid);
unsigned int old_mmid;
unsigned long flags;
unsigned long wired;
unsigned long old_pagemask;
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/kvm/book3s_64_mmu_radix.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ unsigned long __kvmhv_copy_tofrom_guest_radix(int lpid, int pid,
gva_t eaddr, void *to, void *from,
unsigned long n)
{
int uninitialized_var(old_pid), old_lpid;
int old_pid, old_lpid;
unsigned long quadrant, ret = n;
bool is_load = !!to;

Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/kvm/powerpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ static inline u32 dp_to_sp(u64 fprd)
static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu)
{
struct kvm_run *run = vcpu->run;
u64 uninitialized_var(gpr);
u64 gpr;

if (run->mmio.len > sizeof(gpr)) {
printk(KERN_ERR "bad MMIO length: %d\n", run->mmio.len);
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/52xx/mpc52xx_pic.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static int mpc52xx_irqhost_map(struct irq_domain *h, unsigned int virq,
{
int l1irq;
int l2irq;
struct irq_chip *uninitialized_var(irqchip);
struct irq_chip *irqchip;
void *hndlr;
int type;
u32 reg;
Expand Down
2 changes: 1 addition & 1 deletion arch/s390/kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static int pcpu_sigp_retry(struct pcpu *pcpu, u8 order, u32 parm)

static inline int pcpu_stopped(struct pcpu *pcpu)
{
u32 uninitialized_var(status);
u32 status;

if (__pcpu_sigp(pcpu->address, SIGP_SENSE,
0, &status) != SIGP_CC_STATUS_STORED)
Expand Down
10 changes: 5 additions & 5 deletions arch/x86/kernel/quirks.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static void ich_force_hpet_resume(void)
static void ich_force_enable_hpet(struct pci_dev *dev)
{
u32 val;
u32 uninitialized_var(rcba);
u32 rcba;
int err = 0;

if (hpet_address || force_hpet_address)
Expand Down Expand Up @@ -185,7 +185,7 @@ static void hpet_print_force_info(void)
static void old_ich_force_hpet_resume(void)
{
u32 val;
u32 uninitialized_var(gen_cntl);
u32 gen_cntl;

if (!force_hpet_address || !cached_dev)
return;
Expand All @@ -207,7 +207,7 @@ static void old_ich_force_hpet_resume(void)
static void old_ich_force_enable_hpet(struct pci_dev *dev)
{
u32 val;
u32 uninitialized_var(gen_cntl);
u32 gen_cntl;

if (hpet_address || force_hpet_address)
return;
Expand Down Expand Up @@ -298,7 +298,7 @@ static void vt8237_force_hpet_resume(void)

static void vt8237_force_enable_hpet(struct pci_dev *dev)
{
u32 uninitialized_var(val);
u32 val;

if (hpet_address || force_hpet_address)
return;
Expand Down Expand Up @@ -429,7 +429,7 @@ static void nvidia_force_hpet_resume(void)

static void nvidia_force_enable_hpet(struct pci_dev *dev)
{
u32 uninitialized_var(val);
u32 val;

if (hpet_address || force_hpet_address)
return;
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kvm/mmu/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ static int kvm_age_rmapp(struct kvm *kvm, struct kvm_rmap_head *rmap_head,
unsigned long data)
{
u64 *sptep;
struct rmap_iterator uninitialized_var(iter);
struct rmap_iterator iter;
int young = 0;

for_each_rmap_spte(rmap_head, &iter, sptep)
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kvm/mmu/paging_tmpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
{
int ret;
pt_element_t pte;
pt_element_t __user *uninitialized_var(ptep_user);
pt_element_t __user *ptep_user;
gfn_t table_gfn;
u64 pt_access, pte_access;
unsigned index, accessed_dirty, pte_pkey;
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -9927,7 +9927,7 @@ void kvm_arch_sync_events(struct kvm *kvm)
int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size)
{
int i, r;
unsigned long hva, uninitialized_var(old_npages);
unsigned long hva, old_npages;
struct kvm_memslots *slots = kvm_memslots(kvm);
struct kvm_memory_slot *slot;

Expand Down
2 changes: 1 addition & 1 deletion block/blk-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio,
struct scatterlist *sglist,
struct scatterlist **sg)
{
struct bio_vec uninitialized_var(bvec), bvprv = { NULL };
struct bio_vec bvec, bvprv = { NULL };
struct bvec_iter iter;
int nsegs = 0;
bool new_bio = false;
Expand Down
2 changes: 1 addition & 1 deletion drivers/acpi/acpi_pad.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static void round_robin_cpu(unsigned int tsk_index)
cpumask_var_t tmp;
int cpu;
unsigned long min_weight = -1;
unsigned long uninitialized_var(preferred_cpu);
unsigned long preferred_cpu;

if (!alloc_cpumask_var(&tmp, GFP_KERNEL))
return;
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/libata-scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static ssize_t ata_scsi_park_show(struct device *device,
struct ata_link *link;
struct ata_device *dev;
unsigned long now;
unsigned int uninitialized_var(msecs);
unsigned int msecs;
int rc = 0;

ap = ata_shost_to_port(sdev->host);
Expand Down
2 changes: 1 addition & 1 deletion drivers/atm/zatm.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ static int open_tx_first(struct atm_vcc *vcc)
vcc->qos.txtp.max_pcr >= ATM_OC3_PCR);
if (unlimited && zatm_dev->ubr != -1) zatm_vcc->shaper = zatm_dev->ubr;
else {
int uninitialized_var(pcr);
int pcr;

if (unlimited) vcc->qos.txtp.max_sdu = ATM_MAX_AAL5_PDU;
if ((zatm_vcc->shaper = alloc_shaper(vcc->dev,&pcr,
Expand Down
6 changes: 3 additions & 3 deletions drivers/block/drbd/drbd_nl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3423,7 +3423,7 @@ int drbd_adm_dump_devices(struct sk_buff *skb, struct netlink_callback *cb)
{
struct nlattr *resource_filter;
struct drbd_resource *resource;
struct drbd_device *uninitialized_var(device);
struct drbd_device *device;
int minor, err, retcode;
struct drbd_genlmsghdr *dh;
struct device_info device_info;
Expand Down Expand Up @@ -3512,7 +3512,7 @@ int drbd_adm_dump_connections(struct sk_buff *skb, struct netlink_callback *cb)
{
struct nlattr *resource_filter;
struct drbd_resource *resource = NULL, *next_resource;
struct drbd_connection *uninitialized_var(connection);
struct drbd_connection *connection;
int err = 0, retcode;
struct drbd_genlmsghdr *dh;
struct connection_info connection_info;
Expand Down Expand Up @@ -3674,7 +3674,7 @@ int drbd_adm_dump_peer_devices(struct sk_buff *skb, struct netlink_callback *cb)
{
struct nlattr *resource_filter;
struct drbd_resource *resource;
struct drbd_device *uninitialized_var(device);
struct drbd_device *device;
struct drbd_peer_device *peer_device = NULL;
int minor, err, retcode;
struct drbd_genlmsghdr *dh;
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,7 @@ static int rbd_object_map_update_finish(struct rbd_obj_request *obj_req,
struct rbd_device *rbd_dev = obj_req->img_request->rbd_dev;
struct ceph_osd_data *osd_data;
u64 objno;
u8 state, new_state, uninitialized_var(current_state);
u8 state, new_state, current_state;
bool has_current_state;
void *p;

Expand Down
2 changes: 1 addition & 1 deletion drivers/clk/clk-gate.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static void clk_gate_endisable(struct clk_hw *hw, int enable)
{
struct clk_gate *gate = to_clk_gate(hw);
int set = gate->flags & CLK_GATE_SET_TO_DISABLE ? 1 : 0;
unsigned long uninitialized_var(flags);
unsigned long flags;
u32 reg;

set ^= enable;
Expand Down
14 changes: 7 additions & 7 deletions drivers/firewire/ohci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ static void context_tasklet(unsigned long data)
static int context_add_buffer(struct context *ctx)
{
struct descriptor_buffer *desc;
dma_addr_t uninitialized_var(bus_addr);
dma_addr_t bus_addr;
int offset;

/*
Expand Down Expand Up @@ -1289,7 +1289,7 @@ static int at_context_queue_packet(struct context *ctx,
struct fw_packet *packet)
{
struct fw_ohci *ohci = ctx->ohci;
dma_addr_t d_bus, uninitialized_var(payload_bus);
dma_addr_t d_bus, payload_bus;
struct driver_data *driver_data;
struct descriptor *d, *last;
__le32 *header;
Expand Down Expand Up @@ -2445,7 +2445,7 @@ static int ohci_set_config_rom(struct fw_card *card,
{
struct fw_ohci *ohci;
__be32 *next_config_rom;
dma_addr_t uninitialized_var(next_config_rom_bus);
dma_addr_t next_config_rom_bus;

ohci = fw_ohci(card);

Expand Down Expand Up @@ -2933,10 +2933,10 @@ static struct fw_iso_context *ohci_allocate_iso_context(struct fw_card *card,
int type, int channel, size_t header_size)
{
struct fw_ohci *ohci = fw_ohci(card);
struct iso_context *uninitialized_var(ctx);
descriptor_callback_t uninitialized_var(callback);
u64 *uninitialized_var(channels);
u32 *uninitialized_var(mask), uninitialized_var(regs);
struct iso_context *ctx;
descriptor_callback_t callback;
u64 *channels;
u32 *mask, regs;
int index, ret = -EBUSY;

spin_lock_irq(&ohci->lock);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/bridge/sil-sii8620.c
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ static void sii8620_set_auto_zone(struct sii8620 *ctx)

static void sii8620_stop_video(struct sii8620 *ctx)
{
u8 uninitialized_var(val);
u8 val;

sii8620_write_seq_static(ctx,
REG_TPI_INTR_EN, 0,
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/drm_edid.c
Original file line number Diff line number Diff line change
Expand Up @@ -3051,7 +3051,7 @@ static int drm_cvt_modes(struct drm_connector *connector,
const u8 empty[3] = { 0, 0, 0 };

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

if (!memcmp(cvt->code, empty, 3))
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpu/drm/exynos/exynos_drm_dsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,9 @@ static unsigned long exynos_dsi_pll_find_pms(struct exynos_dsi *dsi,
unsigned long best_freq = 0;
u32 min_delta = 0xffffffff;
u8 p_min, p_max;
u8 _p, uninitialized_var(best_p);
u16 _m, uninitialized_var(best_m);
u8 _s, uninitialized_var(best_s);
u8 _p, best_p;
u16 _m, best_m;
u8 _s, best_s;

p_min = DIV_ROUND_UP(fin, (12 * MHZ));
p_max = fin / (6 * MHZ);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/display/intel_fbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ static int intel_fbc_alloc_cfb(struct drm_i915_private *dev_priv,
unsigned int size, unsigned int fb_cpp)
{
struct intel_fbc *fbc = &dev_priv->fbc;
struct drm_mm_node *uninitialized_var(compressed_llb);
struct drm_mm_node *compressed_llb;
int ret;

drm_WARN_ON(&dev_priv->drm,
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/gt/intel_lrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ static struct i915_request *
__unwind_incomplete_requests(struct intel_engine_cs *engine)
{
struct i915_request *rq, *rn, *active = NULL;
struct list_head *uninitialized_var(pl);
struct list_head *pl;
int prio = I915_PRIORITY_INVALID;

lockdep_assert_held(&engine->active.lock);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/intel_uncore.c
Original file line number Diff line number Diff line change
Expand Up @@ -1991,7 +1991,7 @@ int __intel_wait_for_register_fw(struct intel_uncore *uncore,
unsigned int slow_timeout_ms,
u32 *out_value)
{
u32 uninitialized_var(reg_value);
u32 reg_value;
#define done (((reg_value = intel_uncore_read_fw(uncore, reg)) & mask) == value)
int ret;

Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,8 @@ dw_mipi_dsi_get_lane_mbps(void *priv_data, const struct drm_display_mode *mode,
unsigned long best_freq = 0;
unsigned long fvco_min, fvco_max, fin, fout;
unsigned int min_prediv, max_prediv;
unsigned int _prediv, uninitialized_var(best_prediv);
unsigned long _fbdiv, uninitialized_var(best_fbdiv);
unsigned int _prediv, best_prediv;
unsigned long _fbdiv, best_fbdiv;
unsigned long min_delta = ULONG_MAX;

dsi->format = format;
Expand Down
2 changes: 1 addition & 1 deletion drivers/i2c/busses/i2c-rk3x.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ static void rk3x_i2c_handle_read(struct rk3x_i2c *i2c, unsigned int ipd)
{
unsigned int i;
unsigned int len = i2c->msg->len - i2c->processed;
u32 uninitialized_var(val);
u32 val;
u8 byte;

/* we only care for MBRF here. */
Expand Down
Loading

0 comments on commit 3f649ab

Please sign in to comment.