Skip to contentSkip to conversation

replace for loop with array initializer

PATCH In review Salah Triki 3 participants 3 messages Jul 12, 2021 – Jul 14, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 replace for loop with array initializer

Replace for loop with array initializer in order to make code more clean.

---
 drivers/net/wan/farsync.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/net/wan/farsync.c +1 -5
index b3466e084e84..a90d3b9a8170 100644
@@ -567,7 +567,7 @@ static void fst_process_int_work_q(struct tasklet_struct *unused);
 static DECLARE_TASKLET(fst_tx_task, fst_process_tx_work_q);
 static DECLARE_TASKLET(fst_int_task, fst_process_int_work_q);
 
-static struct fst_card_info *fst_card_array[FST_MAX_CARDS];
+static struct fst_card_info *fst_card_array[FST_MAX_CARDS] = { [0 ... FST_MAX_CARDS-1] = NULL };
 static DEFINE_SPINLOCK(fst_work_q_lock);
 static u64 fst_work_txq;
 static u64 fst_work_intq;
@@ -2565,10 +2565,6 @@ static struct pci_driver fst_driver = {
 static int __init
 fst_init(void)
 {
-	int i;
-
-	for (i = 0; i < FST_MAX_CARDS; i++)
-		fst_card_array[i] = NULL;
 	return pci_register_driver(&fst_driver);
 }
 
Signature · 1 line
2.25.1
#1 lore raw

drivers/net/wan/farsync.c static void fst_process_int_work_q(struct tasklet_struct *unused); · line 570

Quoted 10 lines · On Mon, 12 Jul 2021 20:24:50 +0100 Salah Triki <[email protected]> wrote:
drivers/net/wan/farsync.c +1 -1
index b3466e084e84..a90d3b9a8170 100644
@@ -567,7 +567,7 @@ static void fst_process_int_work_q(struct tasklet_struct *unused);
 static DECLARE_TASKLET(fst_tx_task, fst_process_tx_work_q);
 static DECLARE_TASKLET(fst_int_task, fst_process_int_work_q);
 
-static struct fst_card_info *fst_card_array[FST_MAX_CARDS];
+static struct fst_card_info *fst_card_array[FST_MAX_CARDS] = { [0 ... FST_MAX_CARDS-1] = NULL };

Why bother, the default initialization in C is 0 (ie. NULL).
In fact, checkpatch should complain about useless array initialization for this.

#2 lore raw
Quoted 2 lines · Stephen Hemminger

drivers/net/wan/farsync.c

Quoted 1 line · On Mon, 12 Jul 2021 20:24:50 +0100 Salah Triki <[email protected]> wrote:
drivers/net/wan/farsync.c +0 -0

[]

Quoted 4 lines
Quoted 1 line

+static struct fst_card_info *fst_card_array[FST_MAX_CARDS] = { [0 ... FST_MAX_CARDS-1] = NULL };

Why bother, the default initialization in C is 0 (ie. NULL).
In fact, checkpatch should complain about useless array initialization for this.

I'll look out for your patch to checkpatch.