Skip to contentSkip to conversation

staging: sm750fb: make pointers in array const

PATCH In review Kushal Kothari 5 participants 13 messages Oct 18, 2021

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

PATCH 1/1 staging: sm750fb: make pointers in array const

Change the parameters of functions from const char *g_fbmode[] to const char * const g_fbmode[]. This additional const is needed to allow us to fix checkpatch warning, as well as being good programming practice.

For the checkpatch warnings, if we have a set of command line args that we want to check defined as:

	static const char * g_fbmode[] = {NULL, NULL};

checkpatch will complain:
WARNING: static const char * array should probably be static const char * const

---
 drivers/staging/sm750fb/sm750.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/sm750fb/sm750.c +1 -1
index dbd1159a2ef0..3d9b4b0efcb1 100644
@@ -33,7 +33,7 @@
 static int g_hwcursor = 1;
 static int g_noaccel;
 static int g_nomtrr;
-static const char *g_fbmode[] = {NULL, NULL};
+static const char * const g_fbmode[] = {NULL, NULL};
 static const char *g_def_fbmode = "1024x768-32@60";
 static char *g_settings;
 static int g_dualview;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 11 lines · CEST Kushal Kothari

Change the parameters of functions from const char *g_fbmode[] to const char * const g_fbmode[]. This additional const is needed to allow us to fix checkpatch warning, as well as being good programming practice.

For the checkpatch warnings, if we have a set of command line args that we want to check defined as:

	static const char * g_fbmode[] = {NULL, NULL};

checkpatch will complain:
WARNING: static const char * array should probably be static const

char * const

drivers/staging/sm750fb/

Quoted 7 lines
---
 drivers/staging/sm750fb/sm750.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/sm750fb/ renamed from drivers/staging/sm750fb/sm750.c +0 -0

sm750.c

drivers/staging/sm750fb/sm750.c line 36

Quoted 9 lines

index dbd1159a2ef0..3d9b4b0efcb1 100644

drivers/staging/sm750fb/sm750.c +1 -1
@@ -33,7 +33,7 @@
 static int g_hwcursor = 1;
 static int g_noaccel;
 static int g_nomtrr;
-static const char *g_fbmode[] = {NULL, NULL};
+static const char * const g_fbmode[] = {NULL, NULL};

You have introduced a logical change (g_fbmode[] entries cannot be assigned any more) and a build error (because there is code somewhere that assigns values to those slots).

Please, build the code after you've changed it.

Thanks,

Fabio

Quoted 8 lines
drivers/staging/sm750fb/sm750.c +0 -0
 static const char *g_def_fbmode = "1024x768-32@60";
 static char *g_settings;
 static int g_dualview;
Signature · 4 lines
2.25.1

-- 
You received this message because you are subscribed to the Google Groups 

"outreachy-kernel" group.

Quoted 1 line

To unsubscribe from this group and stop receiving emails from it, send an

email to [email protected].

Quoted 1 line

To view this discussion on the web visit https://groups.google.com/d/msgid/

outreachy-kernel/20211018164431.26462-1-kushalkothari285%40gmail.com.

Quoted 1 line
#2 lore raw
Quoted 21 lines · Fabio M. De Francesco
Quoted 11 lines · CEST Kushal Kothari

Change the parameters of functions from const char *g_fbmode[] to const char * const g_fbmode[]. This additional const is needed to allow us to fix checkpatch warning, as well as being good programming practice.

For the checkpatch warnings, if we have a set of command line args that we want to check defined as:

	static const char * g_fbmode[] = {NULL, NULL};

checkpatch will complain:
WARNING: static const char * array should probably be static const

char * const

drivers/staging/sm750fb/

Quoted 7 lines
---
 drivers/staging/sm750fb/sm750.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/sm750fb/ renamed from drivers/staging/sm750fb/sm750.c +0 -0

sm750.c

Quoted 13 lines

drivers/staging/sm750fb/sm750.c line 36

Quoted 9 lines

index dbd1159a2ef0..3d9b4b0efcb1 100644

drivers/staging/sm750fb/sm750.c +1 -1
@@ -33,7 +33,7 @@
 static int g_hwcursor = 1;
 static int g_noaccel;
 static int g_nomtrr;
-static const char *g_fbmode[] = {NULL, NULL};
+static const char * const g_fbmode[] = {NULL, NULL};

You have introduced a logical change (g_fbmode[] entries cannot be assigned any more) and a build error (because there is code somewhere that assigns values to those slots).

I wonder if this warning makes much sense when the array elements are NULL. I don't know if checkpatch could easily detect that.

julia

Quoted 30 lines

Please, build the code after you've changed it.

Thanks,

Fabio

Quoted 8 lines
drivers/staging/sm750fb/sm750.c +0 -1
 static const char *g_def_fbmode = "1024x768-32@60";
 static char *g_settings;
 static int g_dualview;
--

2.25.1

--
You received this message because you are subscribed to the Google Groups

"outreachy-kernel" group.

Quoted 1 line

To unsubscribe from this group and stop receiving emails from it, send an

email to [email protected].

Quoted 1 line

To view this discussion on the web visit https://groups.google.com/d/msgid/

outreachy-kernel/20211018164431.26462-1-kushalkothari285%40gmail.com.

Quoted 1 line

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/163460335.XzdQGyDEVH%40localhost.localdomain.

#3 lore raw
Quoted 9 lines · CEST Julia Lawall
Quoted 6 lines · Fabio M. De Francesco
Quoted 5 lines · CEST Kushal Kothari

Change the parameters of functions from const char *g_fbmode[] to const char * const g_fbmode[]. This additional const is needed to allow us to fix checkpatch warning, as well as being good programming practice.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

For the checkpatch warnings, if we have a set of command line args that we want to check defined as:

	static const char * g_fbmode[] = {NULL, NULL};

checkpatch will complain:
WARNING: static const char * array should probably be static

const

Quoted 11 lines
Quoted 11 lines

char * const

drivers/staging/sm750fb/sm750.c line 36

Quoted 8 lines

---

[...]

drivers/staging/sm750fb/sm750.c +1 -1
-static const char *g_fbmode[] = {NULL, NULL};
+static const char * const g_fbmode[] = {NULL, NULL};

You have introduced a logical change (g_fbmode[] entries cannot be

assigned

Quoted 7 lines
Quoted 2 lines

any more) and a build error (because there is code somewhere that assigns values to those slots).

I wonder if this warning makes much sense when the array elements are NULL. I don't know if checkpatch could easily detect that.

julia

Unfortunately I cannot change checkpatch.pl because I am not able to program with Perl.

However, it should be an easy fix in whatever programming language:
checkpatch should warn if and only if the array elements are assigned with non 'NULL' values, because it's pretty clear that somewhere else there must be some lines that assign values to them.

Fabio

Quoted 14 lines
Quoted 14 lines

Please, build the code after you've changed it.

Thanks,

Fabio

Quoted 6 lines

static const char *g_def_fbmode = "1024x768-32@60"; static char *g_settings;
static int g_dualview;
--
2.25.1

#4 lore raw
Quoted 22 lines · Fabio M. De Francesco
Quoted 9 lines · CEST Julia Lawall
Quoted 6 lines · Fabio M. De Francesco
Quoted 5 lines · CEST Kushal Kothari

Change the parameters of functions from const char *g_fbmode[] to const char * const g_fbmode[]. This additional const is needed to allow us to fix checkpatch warning, as well as being good programming practice.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

For the checkpatch warnings, if we have a set of command line args that we want to check defined as:

	static const char * g_fbmode[] = {NULL, NULL};

checkpatch will complain:
WARNING: static const char * array should probably be static

const

Quoted 5 lines
Quoted 5 lines

char * const

Quoted 4 lines

---

Quoted 12 lines
Quoted 6 lines
Quoted 6 lines

drivers/staging/sm750fb/sm750.c line 36

Quoted 4 lines

[...]

drivers/staging/sm750fb/sm750.c +1 -1
-static const char *g_fbmode[] = {NULL, NULL};
+static const char * const g_fbmode[] = {NULL, NULL};

You have introduced a logical change (g_fbmode[] entries cannot be

assigned

Quoted 5 lines
Quoted 2 lines

any more) and a build error (because there is code somewhere that assigns values to those slots).

I wonder if this warning makes much sense when the array elements are NULL. I don't know if checkpatch could easily detect that.

No, it couldn't really. It's a line by line parser and most frequently these are on separate lines.

Quoted 4 lines

However, it should be an easy fix in whatever programming language:
checkpatch should warn if and only if the array elements are assigned with non 'NULL' values, because it's pretty clear that somewhere else there must be some lines that assign values to them.

Don't take checkpatch warning too seriously and do compile and test any change you make _before_ you submit a patch.

#5 lore raw
Quoted 23 lines · CEST Joe Perches
Quoted 22 lines · Fabio M. De Francesco
Quoted 9 lines · CEST Julia Lawall
Quoted 6 lines · Fabio M. De Francesco
Quoted 5 lines · CEST Kushal Kothari

Change the parameters of functions from const char *g_fbmode[] to const char * const g_fbmode[]. This additional const is needed to allow us to fix checkpatch warning, as well as being good programming practice.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

For the checkpatch warnings, if we have a set of command line args that we want to check defined as:

	static const char * g_fbmode[] = {NULL, NULL};

checkpatch will complain:
WARNING: static const char * array should probably be static

const

Quoted 5 lines
Quoted 5 lines

char * const

Quoted 4 lines

---

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

drivers/staging/sm750fb/sm750.c line 36

Quoted 4 lines

[...]

drivers/staging/sm750fb/sm750.c +1 -1
-static const char *g_fbmode[] = {NULL, NULL};
+static const char * const g_fbmode[] = {NULL, NULL};

You have introduced a logical change (g_fbmode[] entries cannot be

assigned

Quoted 1 line
Quoted 1 line

any more) and a build error (because there is code somewhere that

assigns

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

values to those slots).

I wonder if this warning makes much sense when the array elements are NULL. I don't know if checkpatch could easily detect that.

No, it couldn't really. It's a line by line parser and most frequently these are on separate lines.

Sorry but I don't get it. For sure I'm missing something...

I guess that checkpatch.pl warned Kushal because it detected that the array of pointers was assigned with something and so it output that "static const char * array should probably be static const".

What I cannot understand is why it _can_ detect that the array is assigned with some values but it _cannot_ check that those values are 'NULL' and so avoid to warn.

Thanks,

Fabio

Quoted 3 lines
Quoted 3 lines

However, it should be an easy fix in whatever programming language:
checkpatch should warn if and only if the array elements are assigned

with

Quoted 1 line
Quoted 1 line

non 'NULL' values, because it's pretty clear that somewhere else there

must

Quoted 7 lines
Quoted 1 line

be some lines that assign values to them.

Don't take checkpatch warning too seriously and do compile and test any change you make _before_ you submit a patch.

#6 lore raw
Quoted 43 lines · Fabio M. De Francesco
Quoted 23 lines · CEST Joe Perches
Quoted 22 lines · Fabio M. De Francesco
Quoted 9 lines · CEST Julia Lawall
Quoted 6 lines · Fabio M. De Francesco
Quoted 5 lines · CEST Kushal Kothari

Change the parameters of functions from const char *g_fbmode[] to const char * const g_fbmode[]. This additional const is needed to allow us to fix checkpatch warning, as well as being good programming practice.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

For the checkpatch warnings, if we have a set of command line args that we want to check defined as:

	static const char * g_fbmode[] = {NULL, NULL};

checkpatch will complain:
WARNING: static const char * array should probably be static

const

Quoted 5 lines
Quoted 5 lines

char * const

Quoted 4 lines

---

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

drivers/staging/sm750fb/sm750.c line 36

Quoted 4 lines

[...]

drivers/staging/sm750fb/sm750.c +1 -1
-static const char *g_fbmode[] = {NULL, NULL};
+static const char * const g_fbmode[] = {NULL, NULL};

You have introduced a logical change (g_fbmode[] entries cannot be

assigned

Quoted 1 line
Quoted 1 line

any more) and a build error (because there is code somewhere that

assigns

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

values to those slots).

I wonder if this warning makes much sense when the array elements are NULL. I don't know if checkpatch could easily detect that.

No, it couldn't really. It's a line by line parser and most frequently these are on separate lines.

Sorry but I don't get it. For sure I'm missing something...

Quoted 7 lines

I guess that checkpatch.pl warned Kushal because it detected that the array of pointers was assigned with something and so it output that "static const char * array should probably be static const".

What I cannot understand is why it _can_ detect that the array is assigned with some values but it _cannot_ check that those values are 'NULL' and so avoid to warn.

In this case it could, but this case is too specific to be worth making a special case for. The problem is that checkpatch only looks at one line at a time, so some values could be on another line.

julia

Quoted 23 lines

Thanks,

Fabio

Quoted 3 lines
Quoted 3 lines

However, it should be an easy fix in whatever programming language:
checkpatch should warn if and only if the array elements are assigned

with

Quoted 1 line
Quoted 1 line

non 'NULL' values, because it's pretty clear that somewhere else there

must

Quoted 7 lines
Quoted 1 line

be some lines that assign values to them.

Don't take checkpatch warning too seriously and do compile and test any change you make _before_ you submit a patch.

#7 lore raw
Quoted 1 line

As I wrote your patch has errors, however, if it had no errors it could

not

Quoted 4 lines

be taken in any case. I just noticed that you forgot to CC linux-
<https://groups.google.com/>[email protected].

Some days ago, Greg Kroah-Hartman wrote clearly that he cannot take

patches

Quoted 1 line

that are not submitted to linux-staging.

Yes, I forgot and CC'ed only to the output of the list of that script . I'll keep this in mind ahead.
Thanks.

Quoted 94 lines · On Tuesday, October 19, 2021 at 12:13:47 AM UTC+5:30 [email protected] wrote:
Quoted 8 lines · Fabio M. De Francesco
Quoted 7 lines · CEST Joe Perches
Quoted 6 lines · Fabio M. De Francesco
Quoted 5 lines · CEST Julia Lawall
Quoted 2 lines · Fabio M. De Francesco
Quoted 1 line · CEST Kushal Kothari

Change the parameters of functions from const char *g_fbmode[]

to

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

const char * const g_fbmode[]. This additional const is needed

to

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

allow us to fix checkpatch warning, as well as being good programming practice.

For the checkpatch warnings, if we have a set of command line args that we want to check defined as:
static const char * g_fbmode[] = {NULL, NULL};

checkpatch will complain:
WARNING: static const char * array should probably be static

const

Quoted 5 lines
Quoted 5 lines

char * const

Quoted 4 lines

---

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 4 lines

[...]

(quoted diff) +1 -1
-static const char *g_fbmode[] = {NULL, NULL};
+static const char * const g_fbmode[] = {NULL, NULL};

You have introduced a logical change (g_fbmode[] entries cannot

be

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

assigned

Quoted 1 line
Quoted 1 line

any more) and a build error (because there is code somewhere that

assigns

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

values to those slots).

I wonder if this warning makes much sense when the array elements

are

Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

NULL. I don't know if checkpatch could easily detect that.

No, it couldn't really. It's a line by line parser and most frequently these are on separate lines.

Sorry but I don't get it. For sure I'm missing something...

I guess that checkpatch.pl warned Kushal because it detected that the

array

Quoted 1 line

of pointers was assigned with something and so it output that "static

const

Quoted 3 lines

char * array should probably be static const".

What I cannot understand is why it _can_ detect that the array is

assigned

Quoted 1 line

with some values but it _cannot_ check that those values are 'NULL' and

so

Quoted 1 line

avoid to warn.

In this case it could, but this case is too specific to be worth making a special case for. The problem is that checkpatch only looks at one line at a time, so some values could be on another line.

julia

Quoted 10 lines

Thanks,

Fabio

Quoted 3 lines
Quoted 3 lines

However, it should be an easy fix in whatever programming language:
checkpatch should warn if and only if the array elements are assigned

with

Quoted 1 line
Quoted 1 line

non 'NULL' values, because it's pretty clear that somewhere else

there

Quoted 13 lines

must

Quoted 7 lines
Quoted 1 line

be some lines that assign values to them.

Don't take checkpatch warning too seriously and do compile and test any change you make _before_ you submit a patch.

#8 lore raw
Quoted 5 lines · kushal kothari
Quoted 1 line

As I wrote your patch has errors, however, if it had no errors it could

not

Quoted 2 lines

be taken in any case. I just noticed that you forgot to CC linux-
<https://groups.google.com/>[email protected].

Quoted 7 lines
Quoted 1 line

Some days ago, Greg Kroah-Hartman wrote clearly that he cannot take

patches

Quoted 1 line

that are not submitted to linux-staging.

Yes, I forgot and CC'ed only to the output of the list of that script . I'll keep this in mind ahead.
Thanks.

Hi Kushal,

Thanks for your perserverance.

I'm not sure this is mentioned anywhere in the first patch tutorial, but is should be: avoid pruning the recipient list in an ongoing email thread. I wanted to reply to this, but I see the recipient list got truncated along the way.

Adding recipients, but pruning in an ongoing discussion gets confusing.

wrt who to send the patches to - you should not be pruning that list either. Read back through previous emails on this list about that. The send to Greg is not a special request. It's default behavior when get_maintainers is used correctly.

Thanks,
Alison

Quoted 103 lines
Quoted 94 lines · On Tuesday, October 19, 2021 at 12:13:47 AM UTC+5:30 [email protected] wrote:
Quoted 8 lines · Fabio M. De Francesco
Quoted 7 lines · CEST Joe Perches
Quoted 6 lines · Fabio M. De Francesco
Quoted 5 lines · CEST Julia Lawall
Quoted 2 lines · Fabio M. De Francesco
Quoted 1 line · CEST Kushal Kothari

Change the parameters of functions from const char *g_fbmode[]

to

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

const char * const g_fbmode[]. This additional const is needed

to

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

allow us to fix checkpatch warning, as well as being good programming practice.

For the checkpatch warnings, if we have a set of command line args that we want to check defined as:
static const char * g_fbmode[] = {NULL, NULL};

checkpatch will complain:
WARNING: static const char * array should probably be static

const

Quoted 5 lines
Quoted 5 lines

char * const

Quoted 4 lines

---

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 4 lines

[...]

(quoted diff) +1 -1
-static const char *g_fbmode[] = {NULL, NULL};
+static const char * const g_fbmode[] = {NULL, NULL};

You have introduced a logical change (g_fbmode[] entries cannot

be

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

assigned

Quoted 1 line
Quoted 1 line

any more) and a build error (because there is code somewhere that

assigns

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

values to those slots).

I wonder if this warning makes much sense when the array elements

are

Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

NULL. I don't know if checkpatch could easily detect that.

No, it couldn't really. It's a line by line parser and most frequently these are on separate lines.

Sorry but I don't get it. For sure I'm missing something...

I guess that checkpatch.pl warned Kushal because it detected that the

array

Quoted 1 line

of pointers was assigned with something and so it output that "static

const

Quoted 3 lines

char * array should probably be static const".

What I cannot understand is why it _can_ detect that the array is

assigned

Quoted 1 line

with some values but it _cannot_ check that those values are 'NULL' and

so

Quoted 1 line

avoid to warn.

In this case it could, but this case is too specific to be worth making a special case for. The problem is that checkpatch only looks at one line at a time, so some values could be on another line.

julia

Quoted 10 lines

Thanks,

Fabio

Quoted 3 lines
Quoted 3 lines

However, it should be an easy fix in whatever programming language:
checkpatch should warn if and only if the array elements are assigned

with

Quoted 1 line
Quoted 1 line

non 'NULL' values, because it's pretty clear that somewhere else

there

Quoted 13 lines

must

Quoted 7 lines
Quoted 1 line

be some lines that assign values to them.

Don't take checkpatch warning too seriously and do compile and test any change you make _before_ you submit a patch.

Signature · 3 lines
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/cc951a48-8d3f-4243-8dc6-bae3446941c1n%40googlegroups.com.
#9 lore raw
In reply to Julia Lawall
Quoted 11 lines · CEST Julia Lawall
Quoted 8 lines · Fabio M. De Francesco
Quoted 7 lines · CEST Joe Perches
Quoted 6 lines · Fabio M. De Francesco
Quoted 5 lines · CEST Julia Lawall
Quoted 2 lines · Fabio M. De Francesco
Quoted 1 line · CEST Kushal Kothari

Change the parameters of functions from const char *g_fbmode[]

to

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

const char * const g_fbmode[]. This additional const is needed

to

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

allow us to fix checkpatch warning, as well as being good programming practice.

For the checkpatch warnings, if we have a set of command line args that we want to check defined as:

	static const char * g_fbmode[] = {NULL, NULL};

checkpatch will complain:
WARNING: static const char * array should probably be static

const

Quoted 5 lines
Quoted 5 lines

char * const

Quoted 4 lines

---

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 4 lines

[...]

(quoted diff) +1 -1
-static const char *g_fbmode[] = {NULL, NULL};
+static const char * const g_fbmode[] = {NULL, NULL};

You have introduced a logical change (g_fbmode[] entries cannot

be

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

assigned

Quoted 1 line
Quoted 1 line

any more) and a build error (because there is code somewhere that

assigns

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

values to those slots).

I wonder if this warning makes much sense when the array elements

are

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

NULL. I don't know if checkpatch could easily detect that.

No, it couldn't really. It's a line by line parser and most frequently these are on separate lines.

Sorry but I don't get it. For sure I'm missing something...

I guess that checkpatch.pl warned Kushal because it detected that the

array

Quoted 1 line
Quoted 1 line

of pointers was assigned with something and so it output that "static

const

Quoted 3 lines
Quoted 3 lines

char * array should probably be static const".

What I cannot understand is why it _can_ detect that the array is

assigned

Quoted 1 line
Quoted 1 line

with some values but it _cannot_ check that those values are 'NULL' and

so

Quoted 5 lines
Quoted 1 line

avoid to warn.

In this case it could, but this case is too specific to be worth making a special case for. The problem is that checkpatch only looks at one line at a time, so some values could be on another line.

Yes, I understand that checkpatch's developers want to keep it simple and check one line at a time. After all, as Joe wrote, this is just a tool and final decisions should be made by the users of the tool.

I'm not trying to justify errors like the one that Kushal made by saying that checkpatch is the culprit. I've seen hundreds of warning output by static analyzers that are mere false positives.

I guess that entering a loop and checking line by line until it gets to the closing braces (or to a value != NULL) is not something that is worth doing.

Thanks,

Fabio

Quoted 13 lines

julia

Quoted 10 lines

Thanks,

Fabio

Quoted 3 lines
Quoted 3 lines

However, it should be an easy fix in whatever programming language:
checkpatch should warn if and only if the array elements are assigned

with

Quoted 1 line
Quoted 1 line

non 'NULL' values, because it's pretty clear that somewhere else

there

Quoted 14 lines
Quoted 13 lines

must

Quoted 7 lines
Quoted 1 line

be some lines that assign values to them.

Don't take checkpatch warning too seriously and do compile and test any change you make _before_ you submit a patch.

#10 lore raw
In reply to Fabio M. De Francesco
Quoted 43 lines · Fabio M. De Francesco
Quoted 23 lines · CEST Joe Perches
Quoted 22 lines · Fabio M. De Francesco
Quoted 9 lines · CEST Julia Lawall
Quoted 6 lines · Fabio M. De Francesco
Quoted 5 lines · CEST Kushal Kothari

Change the parameters of functions from const char *g_fbmode[] to const char * const g_fbmode[]. This additional const is needed to allow us to fix checkpatch warning, as well as being good programming practice.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

For the checkpatch warnings, if we have a set of command line args that we want to check defined as:

	static const char * g_fbmode[] = {NULL, NULL};

checkpatch will complain:
WARNING: static const char * array should probably be static

const

Quoted 5 lines
Quoted 5 lines

char * const

Quoted 4 lines

---

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

drivers/staging/sm750fb/sm750.c line 36

Quoted 4 lines

[...]

drivers/staging/sm750fb/sm750.c +1 -1
-static const char *g_fbmode[] = {NULL, NULL};
+static const char * const g_fbmode[] = {NULL, NULL};

You have introduced a logical change (g_fbmode[] entries cannot be

assigned

Quoted 1 line
Quoted 1 line

any more) and a build error (because there is code somewhere that

assigns

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

values to those slots).

I wonder if this warning makes much sense when the array elements are NULL. I don't know if checkpatch could easily detect that.

No, it couldn't really. It's a line by line parser and most frequently these are on separate lines.

Sorry but I don't get it. For sure I'm missing something...

Quoted 7 lines

I guess that checkpatch.pl warned Kushal because it detected that the array of pointers was assigned with something and so it output that "static const char * array should probably be static const".

What I cannot understand is why it _can_ detect that the array is assigned with some values but it _cannot_ check that those values are 'NULL' and so avoid to warn.

It's a simple rule.

char *foo[] = { should probably be const char * const foo[] = {

There are exceptions and that's why the message output is a warning and the text includes the word "probably" and not "must".

It's up to the reader to determine if the warning is valid or not.

That's true for _every_ output error, warning or strict message checkpatch emits.

checkpatch is a stupid brainless script doing trivial pattern matches.

People should _use_ their brains and not blindly trust and follow brainless scripts.

And especially, everyone should compile and test changes _before_ submitting patches.

It doesn't matter if a tool that produces a warning is checkpatch, sparse, coccinelle or a compiler.

Validate and test _before_ submitting a patch.

#11 lore raw
Quoted 9 lines · CEST Joe Perches
Quoted 8 lines · Fabio M. De Francesco
Quoted 7 lines · CEST Joe Perches
Quoted 6 lines · Fabio M. De Francesco
Quoted 5 lines · CEST Julia Lawall
Quoted 2 lines · Fabio M. De Francesco
Quoted 1 line · CEST Kushal Kothari

Change the parameters of functions from const char *g_fbmode[]

to

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

const char * const g_fbmode[]. This additional const is needed

to

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

allow us to fix checkpatch warning, as well as being good programming practice.

For the checkpatch warnings, if we have a set of command line args that we want to check defined as:

	static const char * g_fbmode[] = {NULL, NULL};

checkpatch will complain:
WARNING: static const char * array should probably be static

const

Quoted 5 lines
Quoted 5 lines

char * const

Quoted 4 lines

---

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 4 lines

[...]

(quoted diff) +1 -1
-static const char *g_fbmode[] = {NULL, NULL};
+static const char * const g_fbmode[] = {NULL, NULL};

You have introduced a logical change (g_fbmode[] entries cannot

be

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

assigned

Quoted 1 line
Quoted 1 line

any more) and a build error (because there is code somewhere that

assigns

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

values to those slots).

I wonder if this warning makes much sense when the array elements

are

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

NULL. I don't know if checkpatch could easily detect that.

No, it couldn't really. It's a line by line parser and most frequently these are on separate lines.

Sorry but I don't get it. For sure I'm missing something...

I guess that checkpatch.pl warned Kushal because it detected that the

array

Quoted 1 line
Quoted 1 line

of pointers was assigned with something and so it output that "static

const

Quoted 3 lines
Quoted 3 lines

char * array should probably be static const".

What I cannot understand is why it _can_ detect that the array is

assigned

Quoted 1 line
Quoted 1 line

with some values but it _cannot_ check that those values are 'NULL' and

so

Quoted 19 lines
Quoted 1 line

avoid to warn.

It's a simple rule.

char *foo[] = { should probably be const char * const foo[] = {

There are exceptions and that's why the message output is a warning and the text includes the word "probably" and not "must".

It's up to the reader to determine if the warning is valid or not.

That's true for _every_ output error, warning or strict message checkpatch emits.

checkpatch is a stupid brainless script doing trivial pattern matches.

People should _use_ their brains and not blindly trust and follow brainless scripts.

Quoted 8 lines

And especially, everyone should compile and test changes _before_ submitting patches.

It doesn't matter if a tool that produces a warning is checkpatch, sparse, coccinelle or a compiler.

Validate and test _before_ submitting a patch.

Yes, after some more thinking about this matter I agree with you :)

This is why I wrote another message for explaining my new POV some minutes ago.

Thanks,

Fabio

#12 lore raw
In reply to Fabio M. De Francesco
Quoted 6 lines · CEST Fabio M. De Francesco
Quoted 5 lines · CEST Kushal Kothari

Change the parameters of functions from const char *g_fbmode[] to const char * const g_fbmode[]. This additional const is needed to allow us to fix checkpatch warning, as well as being good programming practice.

Quoted 6 lines
Quoted 6 lines

For the checkpatch warnings, if we have a set of command line args that we want to check defined as:

	static const char * g_fbmode[] = {NULL, NULL};

checkpatch will complain:
WARNING: static const char * array should probably be static

const

Quoted 23 lines

char * const

drivers/staging/sm750fb/

Quoted 7 lines
---
 drivers/staging/sm750fb/sm750.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/sm750fb/ renamed from drivers/staging/sm750fb/sm750.c +0 -0

sm750.c

drivers/staging/sm750fb/sm750.c line 36

Quoted 9 lines

index dbd1159a2ef0..3d9b4b0efcb1 100644

drivers/staging/sm750fb/sm750.c +1 -1
@@ -33,7 +33,7 @@
 static int g_hwcursor = 1;
 static int g_noaccel;
 static int g_nomtrr;
-static const char *g_fbmode[] = {NULL, NULL};
+static const char * const g_fbmode[] = {NULL, NULL};

You have introduced a logical change (g_fbmode[] entries cannot be assigned any more) and a build error (because there is code somewhere that assigns values to those slots).

Quoted 5 lines

Please, build the code after you've changed it.

Thanks,

Fabio

Hi Kushal,

As I wrote your patch has errors, however, if it had no errors it could not be taken in any case. I just noticed that you forgot to CC linux- [email protected].

Some days ago, Greg Kroah-Hartman wrote clearly that he cannot take patches that are not submitted to linux-staging.

The "Submit patches" section of https://kernelnewbies.org/Outreachyfirstpatch
is a bit misleading. However, Karolina Drobnik is taking care to rework it.

For the moment, please use the following command (or some smart variation of it) to get a list with _all_ the people and mailing lists you should send your patches to:

kernel_source_dir@localhost:~ # perl scripts/get_maintainer.pl --separator , --norolestats -f drivers/staging/sm750fb/

The output is:

Sudip Mukherjee <[email protected]>,Teddy Wang <[email protected]>,Greg Kroah-Hartman <[email protected]>,[email protected],linux- [email protected],[email protected]

Thanks,

Fabio

P.S.: @Karolina, please correct me if I wrote something that is wrong and that contradicts the new text you are working on.