Skip to content

Commit

Permalink
cppcheck: (error) Uninitialized variable
Browse files Browse the repository at this point in the history
As of cppcheck 1.82 warnings are issued when using the list_for_each_*
functions with an uninitialized variable.  Functionally, this is fine
but to resolve the warning initialize these variables.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes openzfs#9732
  • Loading branch information
Ubuntu authored and tonyhutter committed Dec 27, 2019
1 parent 564cb85 commit b76be31
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion module/spl/spl-generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ static void __init
spl_random_init(void)
{
uint64_t s[2];
int i;
int i = 0;

get_random_bytes(s, sizeof (s));

Expand Down
13 changes: 7 additions & 6 deletions module/spl/spl-kmem-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ static spl_kmem_slab_t *
spl_slab_alloc(spl_kmem_cache_t *skc, int flags)
{
spl_kmem_slab_t *sks;
spl_kmem_obj_t *sko, *n;
spl_kmem_obj_t *sko;
void *base, *obj;
uint32_t obj_size, offslab_size = 0;
int i, rc = 0;
Expand Down Expand Up @@ -356,6 +356,7 @@ spl_slab_alloc(spl_kmem_cache_t *skc, int flags)

out:
if (rc) {
spl_kmem_obj_t *n = NULL;
if (skc->skc_flags & KMC_OFFSLAB)
list_for_each_entry_safe(sko,
n, &sks->sks_free_list, sko_list) {
Expand Down Expand Up @@ -405,8 +406,8 @@ spl_slab_free(spl_kmem_slab_t *sks,
static void
spl_slab_reclaim(spl_kmem_cache_t *skc)
{
spl_kmem_slab_t *sks, *m;
spl_kmem_obj_t *sko, *n;
spl_kmem_slab_t *sks = NULL, *m = NULL;
spl_kmem_obj_t *sko = NULL, *n = NULL;
LIST_HEAD(sks_list);
LIST_HEAD(sko_list);
uint32_t size = 0;
Expand Down Expand Up @@ -802,7 +803,7 @@ spl_magazine_free(spl_kmem_magazine_t *skm)
static int
spl_magazine_create(spl_kmem_cache_t *skc)
{
int i;
int i = 0;

if (skc->skc_flags & KMC_NOMAGAZINE)
return (0);
Expand Down Expand Up @@ -833,7 +834,7 @@ static void
spl_magazine_destroy(spl_kmem_cache_t *skc)
{
spl_kmem_magazine_t *skm;
int i;
int i = 0;

if (skc->skc_flags & KMC_NOMAGAZINE)
return;
Expand Down Expand Up @@ -1617,7 +1618,7 @@ static spl_shrinker_t
__spl_kmem_cache_generic_shrinker(struct shrinker *shrink,
struct shrink_control *sc)
{
spl_kmem_cache_t *skc;
spl_kmem_cache_t *skc = NULL;
int alloc = 0;

/*
Expand Down
4 changes: 2 additions & 2 deletions module/spl/spl-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ kmem_del_init(spinlock_t *lock, struct hlist_head *table,
int bits, const void *addr)
{
struct hlist_head *head;
struct hlist_node *node;
struct hlist_node *node = NULL;
struct kmem_debug *p;
unsigned long flags;

Expand Down Expand Up @@ -500,7 +500,7 @@ static void
spl_kmem_fini_tracking(struct list_head *list, spinlock_t *lock)
{
unsigned long flags;
kmem_debug_t *kd;
kmem_debug_t *kd = NULL;
char str[17];

spin_lock_irqsave(lock, flags);
Expand Down
6 changes: 3 additions & 3 deletions module/spl/spl-kstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ static struct seq_operations kstat_seq_ops = {
static kstat_module_t *
kstat_find_module(char *name)
{
kstat_module_t *module;
kstat_module_t *module = NULL;

list_for_each_entry(module, &kstat_module_list, ksm_module_list) {
if (strncmp(name, module->ksm_name, KSTAT_STRLEN) == 0)
Expand Down Expand Up @@ -624,7 +624,7 @@ static int
kstat_detect_collision(kstat_proc_entry_t *kpep)
{
kstat_module_t *module;
kstat_proc_entry_t *tmp;
kstat_proc_entry_t *tmp = NULL;
char *parent;
char *cp;

Expand Down Expand Up @@ -659,7 +659,7 @@ kstat_proc_entry_install(kstat_proc_entry_t *kpep, mode_t mode,
const struct file_operations *file_ops, void *data)
{
kstat_module_t *module;
kstat_proc_entry_t *tmp;
kstat_proc_entry_t *tmp = NULL;

ASSERT(kpep);

Expand Down
4 changes: 2 additions & 2 deletions module/spl/spl-proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ proc_doslab(struct ctl_table *table, int write,
int rc = 0;
unsigned long min = 0, max = ~0, val = 0, mask;
spl_ctl_table dummy = *table;
spl_kmem_cache_t *skc;
spl_kmem_cache_t *skc = NULL;

dummy.data = &val;
dummy.proc_handler = &proc_dointvec;
Expand Down Expand Up @@ -249,7 +249,7 @@ static int
taskq_seq_show_impl(struct seq_file *f, void *p, boolean_t allflag)
{
taskq_t *tq = p;
taskq_thread_t *tqt;
taskq_thread_t *tqt = NULL;
spl_wait_queue_entry_t *wq;
struct task_struct *tsk;
taskq_ent_t *tqe;
Expand Down
12 changes: 6 additions & 6 deletions module/spl/spl-taskq.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ task_km_flags(uint_t flags)
static int
taskq_find_by_name(const char *name)
{
struct list_head *tql;
struct list_head *tql = NULL;
taskq_t *tq;

list_for_each_prev(tql, &tq_list) {
Expand Down Expand Up @@ -211,7 +211,7 @@ task_expire_impl(taskq_ent_t *t)
{
taskq_ent_t *w;
taskq_t *tq = t->tqent_taskq;
struct list_head *l;
struct list_head *l = NULL;
unsigned long flags;

spin_lock_irqsave_nested(&tq->tq_lock, flags, tq->tq_lock_class);
Expand Down Expand Up @@ -298,7 +298,7 @@ static void
taskq_insert_in_order(taskq_t *tq, taskq_thread_t *tqt)
{
taskq_thread_t *w;
struct list_head *l;
struct list_head *l = NULL;

ASSERT(tq);
ASSERT(tqt);
Expand All @@ -321,7 +321,7 @@ taskq_insert_in_order(taskq_t *tq, taskq_thread_t *tqt)
static taskq_ent_t *
taskq_find_list(taskq_t *tq, struct list_head *lh, taskqid_t id)
{
struct list_head *l;
struct list_head *l = NULL;
taskq_ent_t *t;

list_for_each(l, lh) {
Expand All @@ -347,7 +347,7 @@ static taskq_ent_t *
taskq_find(taskq_t *tq, taskqid_t id)
{
taskq_thread_t *tqt;
struct list_head *l;
struct list_head *l = NULL;
taskq_ent_t *t;

t = taskq_find_list(tq, &tq->tq_delay_list, id);
Expand Down Expand Up @@ -1198,7 +1198,7 @@ param_set_taskq_kick(const char *val, struct kernel_param *kp)
#endif
{
int ret;
taskq_t *tq;
taskq_t *tq = NULL;
taskq_ent_t *t;
unsigned long flags;

Expand Down
2 changes: 1 addition & 1 deletion module/spl/spl-tsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static tsd_hash_table_t *tsd_hash_table = NULL;
static tsd_hash_entry_t *
tsd_hash_search(tsd_hash_table_t *table, uint_t key, pid_t pid)
{
struct hlist_node *node;
struct hlist_node *node = NULL;
tsd_hash_entry_t *entry;
tsd_hash_bin_t *bin;
ulong_t hash;
Expand Down
2 changes: 1 addition & 1 deletion module/spl/spl-vmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ EXPORT_SYMBOL(zio_arena);
size_t
vmem_size(vmem_t *vmp, int typemask)
{
spl_kmem_cache_t *skc;
spl_kmem_cache_t *skc = NULL;
size_t alloc = VMEM_FLOOR_SIZE;

if ((typemask & VMEM_ALLOC) && (typemask & VMEM_FREE))
Expand Down

0 comments on commit b76be31

Please sign in to comment.