diff mbox series

[20/22,v3] ray_cs: Improve card_status[]

Message ID 6cae7be8-0329-7b0f-9a61-695f3d0cceb4@stuerz.xyz
State Superseded
Headers show
Series None | expand

Commit Message

Benjamin Stürz March 28, 2022, 7:54 p.m. UTC
On 28.03.22 21:23, Joe Perches wrote:
> On Mon, 2022-03-28 at 20:21 +0200, Benjamin Stürz wrote:
>> Replace comments with C99's designated initializers.
> []
>> diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
> []
>> @@ -2529,20 +2529,23 @@ static void clear_interrupt(ray_dev_t *local)
>>  #define MAXDATA (PAGE_SIZE - 80)
>>
>>  static const char *card_status[] = {
>> -	"Card inserted - uninitialized",	/* 0 */
>> -	"Card not downloaded",			/* 1 */
>> -	"Waiting for download parameters",	/* 2 */
>> -	"Card doing acquisition",		/* 3 */
>> -	"Acquisition complete",			/* 4 */
>> -	"Authentication complete",		/* 5 */
>> -	"Association complete",			/* 6 */
>> -	"???", "???", "???", "???",		/* 7 8 9 10 undefined */
>> -	"Card init error",			/* 11 */
>> -	"Download parameters error",		/* 12 */
>> -	"???",					/* 13 */
>> -	"Acquisition failed",			/* 14 */
>> -	"Authentication refused",		/* 15 */
>> -	"Association failed"			/* 16 */
>> +	[0]  = "Card inserted - uninitialized",
> 
> If you are going to do this at all, please use the #defines
> in drivers/net/wireless/rayctl.h
> 
> 	[CARD_INSERTED] = "Card inserted - uninitialized",
> 	[CARD_AWAITING_PARAM] = "Card not downloaded",
> 
> etc...
> 
> $ git grep -w -P 'CARD_\w+' drivers/net/wireless/rayctl.h
> drivers/net/wireless/rayctl.h:#define CARD_INSERTED       (0)
> drivers/net/wireless/rayctl.h:#define CARD_AWAITING_PARAM (1)
> drivers/net/wireless/rayctl.h:#define CARD_INIT_ERROR     (11)
> drivers/net/wireless/rayctl.h:#define CARD_DL_PARAM       (2)
> drivers/net/wireless/rayctl.h:#define CARD_DL_PARAM_ERROR (12)
> drivers/net/wireless/rayctl.h:#define CARD_DOING_ACQ      (3)
> drivers/net/wireless/rayctl.h:#define CARD_ACQ_COMPLETE   (4)
> drivers/net/wireless/rayctl.h:#define CARD_ACQ_FAILED     (14)
> drivers/net/wireless/rayctl.h:#define CARD_AUTH_COMPLETE  (5)
> drivers/net/wireless/rayctl.h:#define CARD_AUTH_REFUSED   (15)
> drivers/net/wireless/rayctl.h:#define CARD_ASSOC_COMPLETE (6)
> drivers/net/wireless/rayctl.h:#define CARD_ASSOC_FAILED   (16)
> 
>> +	[1]  = "Card not downloaded",
>> +	[2]  = "Waiting for download parameters",
>> +	[3]  = "Card doing acquisition",
>> +	[4]  = "Acquisition complete",
>> +	[5]  = "Authentication complete",
>> +	[6]  = "Association complete",
>> +	[7]  = "???",
>> +	[8]  = "???",
>> +	[9]  = "???",
>> +	[10] = "???",
>> +	[11] = "Card init error",
>> +	[12] = "Download parameters error",
>> +	[13] = "???",
>> +	[14] = "Acquisition failed",
>> +	[15] = "Authentication refused",
>> +	[16] = "Association failed"
>>  };
>>
>>  static const char *nettype[] = { "Adhoc", "Infra " };
> 
> 


- Make card_status[] const, because it should never be modified
- Replace comments with C99's designated initializers to improve
  readability and maintainability

Signed-off-by: Benjamin Stürz <benni@stuerz.xyz>
---
 drivers/net/wireless/ray_cs.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

Comments

Kalle Valo April 6, 2022, 11:31 a.m. UTC | #1
Benjamin Stürz <benni@stuerz.xyz> wrote:

> On 28.03.22 21:23, Joe Perches wrote:
> > On Mon, 2022-03-28 at 20:21 +0200, Benjamin Stürz wrote:
> >> Replace comments with C99's designated initializers.
> > []
> >> diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
> > []
> >> @@ -2529,20 +2529,23 @@ static void clear_interrupt(ray_dev_t *local)
> >>  #define MAXDATA (PAGE_SIZE - 80)
> >>
> >>  static const char *card_status[] = {
> >> -	"Card inserted - uninitialized",	/* 0 */
> >> -	"Card not downloaded",			/* 1 */
> >> -	"Waiting for download parameters",	/* 2 */
> >> -	"Card doing acquisition",		/* 3 */
> >> -	"Acquisition complete",			/* 4 */
> >> -	"Authentication complete",		/* 5 */
> >> -	"Association complete",			/* 6 */
> >> -	"???", "???", "???", "???",		/* 7 8 9 10 undefined */
> >> -	"Card init error",			/* 11 */
> >> -	"Download parameters error",		/* 12 */
> >> -	"???",					/* 13 */
> >> -	"Acquisition failed",			/* 14 */
> >> -	"Authentication refused",		/* 15 */
> >> -	"Association failed"			/* 16 */
> >> +	[0]  = "Card inserted - uninitialized",
> > 
> > If you are going to do this at all, please use the #defines
> > in drivers/net/wireless/rayctl.h
> > 
> > 	[CARD_INSERTED] = "Card inserted - uninitialized",
> > 	[CARD_AWAITING_PARAM] = "Card not downloaded",
> > 
> > etc...
> > 
> > $ git grep -w -P 'CARD_\w+' drivers/net/wireless/rayctl.h
> > drivers/net/wireless/rayctl.h:#define CARD_INSERTED       (0)
> > drivers/net/wireless/rayctl.h:#define CARD_AWAITING_PARAM (1)
> > drivers/net/wireless/rayctl.h:#define CARD_INIT_ERROR     (11)
> > drivers/net/wireless/rayctl.h:#define CARD_DL_PARAM       (2)
> > drivers/net/wireless/rayctl.h:#define CARD_DL_PARAM_ERROR (12)
> > drivers/net/wireless/rayctl.h:#define CARD_DOING_ACQ      (3)
> > drivers/net/wireless/rayctl.h:#define CARD_ACQ_COMPLETE   (4)
> > drivers/net/wireless/rayctl.h:#define CARD_ACQ_FAILED     (14)
> > drivers/net/wireless/rayctl.h:#define CARD_AUTH_COMPLETE  (5)
> > drivers/net/wireless/rayctl.h:#define CARD_AUTH_REFUSED   (15)
> > drivers/net/wireless/rayctl.h:#define CARD_ASSOC_COMPLETE (6)
> > drivers/net/wireless/rayctl.h:#define CARD_ASSOC_FAILED   (16)
> > 
> >> +	[1]  = "Card not downloaded",
> >> +	[2]  = "Waiting for download parameters",
> >> +	[3]  = "Card doing acquisition",
> >> +	[4]  = "Acquisition complete",
> >> +	[5]  = "Authentication complete",
> >> +	[6]  = "Association complete",
> >> +	[7]  = "???",
> >> +	[8]  = "???",
> >> +	[9]  = "???",
> >> +	[10] = "???",
> >> +	[11] = "Card init error",
> >> +	[12] = "Download parameters error",
> >> +	[13] = "???",
> >> +	[14] = "Acquisition failed",
> >> +	[15] = "Authentication refused",
> >> +	[16] = "Association failed"
> >>  };
> >>
> >>  static const char *nettype[] = { "Adhoc", "Infra " };
> > 
> > 
> 
> 
> - Make card_status[] const, because it should never be modified
> - Replace comments with C99's designated initializers to improve
>   readability and maintainability
> 
> Signed-off-by: Benjamin Stürz <benni@stuerz.xyz>

Please don't include the email discussion in the commit log.

Patch set to Changes Requested.
diff mbox series

Patch

diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index 87e98ab068ed..07f36aaefbde 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -2528,21 +2528,24 @@  static void clear_interrupt(ray_dev_t *local)
 #ifdef CONFIG_PROC_FS
 #define MAXDATA (PAGE_SIZE - 80)

-static const char *card_status[] = {
-	"Card inserted - uninitialized",	/* 0 */
-	"Card not downloaded",			/* 1 */
-	"Waiting for download parameters",	/* 2 */
-	"Card doing acquisition",		/* 3 */
-	"Acquisition complete",			/* 4 */
-	"Authentication complete",		/* 5 */
-	"Association complete",			/* 6 */
-	"???", "???", "???", "???",		/* 7 8 9 10 undefined */
-	"Card init error",			/* 11 */
-	"Download parameters error",		/* 12 */
-	"???",					/* 13 */
-	"Acquisition failed",			/* 14 */
-	"Authentication refused",		/* 15 */
-	"Association failed"			/* 16 */
+static const char * const card_status[] = {
+	[CARD_INSERTED]		= "Card inserted - uninitialized",
+	[CARD_AWAITING_PARAM]	= "Card not downloaded",
+	[CARD_DL_PARAM]		= "Waiting for download parameters",
+	[CARD_DOING_ACQ]	= "Card doing acquisition",
+	[CARD_ACQ_COMPLETE]	= "Acquisition complete",
+	[CARD_AUTH_COMPLETE]	= "Authentication complete",
+	[CARD_ASSOC_COMPLETE]	= "Association complete",
+	[7]			= "???",
+	[8]			= "???",
+	[9]			= "???",
+	[10]			= "???",
+	[CARD_INIT_ERROR]	= "Card init error",
+	[CARD_DL_PARAM_ERROR]	= "Download parameters error",
+	[13]			= "???",
+	[CARD_ACQ_FAILED]	= "Acquisition failed",
+	[CARD_AUTH_REFUSED]	= "Authentication refused",
+	[CARD_ASSOC_FAILED]	= "Association failed"
 };

 static const char *nettype[] = { "Adhoc", "Infra " };