linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: light: bh1750: Move static keyword to the front of declaration
@ 2019-09-02 11:31 Krzysztof Wilczynski
  2019-09-03 17:35 ` Tomasz Duszynski
  2019-09-08 10:49 ` Jonathan Cameron
  0 siblings, 2 replies; 6+ messages in thread
From: Krzysztof Wilczynski @ 2019-09-02 11:31 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	linux-iio, linux-kernel

Move the static keyword to the front of declaration of
bh1750_chip_info_tbl, and resolve the following compiler
warning that can be seen when building with warnings
enabled (W=1):

drivers/iio/light/bh1750.c:64:1: warning:
  ‘static’ is not at beginning of declaration [-Wold-style-declaration]

Signed-off-by: Krzysztof Wilczynski <kw@linux.com>
---
Related: https://lore.kernel.org/r/20190827233017.GK9987@google.com

 drivers/iio/light/bh1750.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/light/bh1750.c b/drivers/iio/light/bh1750.c
index 28347df78cff..460c0013f1a9 100644
--- a/drivers/iio/light/bh1750.c
+++ b/drivers/iio/light/bh1750.c
@@ -42,7 +42,7 @@ struct bh1750_data {
 	u16 mtreg;
 };
 
-struct bh1750_chip_info {
+static const struct bh1750_chip_info {
 	u16 mtreg_min;
 	u16 mtreg_max;
 	u16 mtreg_default;
@@ -59,9 +59,7 @@ struct bh1750_chip_info {
 
 	u16 int_time_low_mask;
 	u16 int_time_high_mask;
-}
-
-static const bh1750_chip_info_tbl[] = {
+} bh1750_chip_info_tbl[] = {
 	[BH1710] = { 140, 1022, 300, 400,  250000000, 2, 0x001F, 0x03E0 },
 	[BH1721] = { 140, 1020, 300, 400,  250000000, 2, 0x0010, 0x03E0 },
 	[BH1750] = { 31,  254,  69,  1740, 57500000,  1, 0x001F, 0x00E0 },
-- 
2.22.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: light: bh1750: Move static keyword to the front of declaration
  2019-09-02 11:31 [PATCH] iio: light: bh1750: Move static keyword to the front of declaration Krzysztof Wilczynski
@ 2019-09-03 17:35 ` Tomasz Duszynski
  2019-09-08 10:49 ` Jonathan Cameron
  1 sibling, 0 replies; 6+ messages in thread
From: Tomasz Duszynski @ 2019-09-03 17:35 UTC (permalink / raw)
  To: Krzysztof Wilczynski
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

On Mon, Sep 02, 2019 at 01:31:32PM +0200, Krzysztof Wilczynski wrote:
> Move the static keyword to the front of declaration of
> bh1750_chip_info_tbl, and resolve the following compiler
> warning that can be seen when building with warnings
> enabled (W=1):

Looks okay.
Acked-by: Tomasz Duszynski <tduszyns@gmail.com>

>
> drivers/iio/light/bh1750.c:64:1: warning:
>   ‘static’ is not at beginning of declaration [-Wold-style-declaration]
>
> Signed-off-by: Krzysztof Wilczynski <kw@linux.com>
> ---
> Related: https://lore.kernel.org/r/20190827233017.GK9987@google.com
>
>  drivers/iio/light/bh1750.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/light/bh1750.c b/drivers/iio/light/bh1750.c
> index 28347df78cff..460c0013f1a9 100644
> --- a/drivers/iio/light/bh1750.c
> +++ b/drivers/iio/light/bh1750.c
> @@ -42,7 +42,7 @@ struct bh1750_data {
>  	u16 mtreg;
>  };
>
> -struct bh1750_chip_info {
> +static const struct bh1750_chip_info {
>  	u16 mtreg_min;
>  	u16 mtreg_max;
>  	u16 mtreg_default;
> @@ -59,9 +59,7 @@ struct bh1750_chip_info {
>
>  	u16 int_time_low_mask;
>  	u16 int_time_high_mask;
> -}
> -
> -static const bh1750_chip_info_tbl[] = {
> +} bh1750_chip_info_tbl[] = {
>  	[BH1710] = { 140, 1022, 300, 400,  250000000, 2, 0x001F, 0x03E0 },
>  	[BH1721] = { 140, 1020, 300, 400,  250000000, 2, 0x0010, 0x03E0 },
>  	[BH1750] = { 31,  254,  69,  1740, 57500000,  1, 0x001F, 0x00E0 },
> --
> 2.22.1
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: light: bh1750: Move static keyword to the front of declaration
  2019-09-02 11:31 [PATCH] iio: light: bh1750: Move static keyword to the front of declaration Krzysztof Wilczynski
  2019-09-03 17:35 ` Tomasz Duszynski
@ 2019-09-08 10:49 ` Jonathan Cameron
  2019-09-08 13:52   ` Krzysztof Wilczynski
  1 sibling, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2019-09-08 10:49 UTC (permalink / raw)
  To: Krzysztof Wilczynski
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	linux-iio, linux-kernel

On Mon,  2 Sep 2019 13:31:32 +0200
Krzysztof Wilczynski <kw@linux.com> wrote:

> Move the static keyword to the front of declaration of
> bh1750_chip_info_tbl, and resolve the following compiler
> warning that can be seen when building with warnings
> enabled (W=1):
> 
> drivers/iio/light/bh1750.c:64:1: warning:
>   ‘static’ is not at beginning of declaration [-Wold-style-declaration]
> 
> Signed-off-by: Krzysztof Wilczynski <kw@linux.com>

This one has me confused.  The warning seems to be false as static
is at the beginning of the declaration....

Sure we "could" combine the declaration with the definition as you have
done here, but that has nothing much to do with the warning.

What am I missing?

Jonathan

> ---
> Related: https://lore.kernel.org/r/20190827233017.GK9987@google.com
> 
>  drivers/iio/light/bh1750.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/light/bh1750.c b/drivers/iio/light/bh1750.c
> index 28347df78cff..460c0013f1a9 100644
> --- a/drivers/iio/light/bh1750.c
> +++ b/drivers/iio/light/bh1750.c
> @@ -42,7 +42,7 @@ struct bh1750_data {
>  	u16 mtreg;
>  };
>  
> -struct bh1750_chip_info {
> +static const struct bh1750_chip_info {
>  	u16 mtreg_min;
>  	u16 mtreg_max;
>  	u16 mtreg_default;
> @@ -59,9 +59,7 @@ struct bh1750_chip_info {
>  
>  	u16 int_time_low_mask;
>  	u16 int_time_high_mask;
> -}
> -
> -static const bh1750_chip_info_tbl[] = {
Looks like the beginning fo the declaration to me!

Jonathan

> +} bh1750_chip_info_tbl[] = {
>  	[BH1710] = { 140, 1022, 300, 400,  250000000, 2, 0x001F, 0x03E0 },
>  	[BH1721] = { 140, 1020, 300, 400,  250000000, 2, 0x0010, 0x03E0 },
>  	[BH1750] = { 31,  254,  69,  1740, 57500000,  1, 0x001F, 0x00E0 },


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: light: bh1750: Move static keyword to the front of declaration
  2019-09-08 10:49 ` Jonathan Cameron
@ 2019-09-08 13:52   ` Krzysztof Wilczynski
  2019-09-10 13:35     ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: Krzysztof Wilczynski @ 2019-09-08 13:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	linux-iio, linux-kernel

Hello Jonathan,

Thank you for feedback.

[...]
> > drivers/iio/light/bh1750.c:64:1: warning:
> >   ‘static’ is not at beginning of declaration [-Wold-style-declaration]
[...]
> This one has me confused.  The warning seems to be false as static
> is at the beginning of the declaration....
> 
> Sure we "could" combine the declaration with the definition as you have
> done here, but that has nothing much to do with the warning.
[...]

I only moved the "static const" at the front, I haven't changed the
code as it's already has been a declaration and definition.  There is
no semicolon there and the original author put a newline to separate
things which makes it look as if these were separate.

Simple example based on the existing code:

  https://godbolt.org/z/hV4HP7

I hope this helps to illustrate the change in the patch.  I apologise
if my approach was incorrect.

As part of the patch I removed the newline in an aim to make it less
confusing to anyone who will read the code in the future.  Especially,
since it makes it a bit awkward to read and when using things like
grep.

Krzysztof

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: light: bh1750: Move static keyword to the front of declaration
  2019-09-08 13:52   ` Krzysztof Wilczynski
@ 2019-09-10 13:35     ` Jonathan Cameron
  2019-09-10 20:25       ` Krzysztof Wilczynski
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2019-09-10 13:35 UTC (permalink / raw)
  To: Krzysztof Wilczynski
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

On Sun, 8 Sep 2019 15:52:09 +0200
Krzysztof Wilczynski <kw@linux.com> wrote:

> Hello Jonathan,
> 
> Thank you for feedback.
> 
> [...]
> > > drivers/iio/light/bh1750.c:64:1: warning:
> > >   ‘static’ is not at beginning of declaration [-Wold-style-declaration]  
> [...]
> > This one has me confused.  The warning seems to be false as static
> > is at the beginning of the declaration....
> > 
> > Sure we "could" combine the declaration with the definition as you have
> > done here, but that has nothing much to do with the warning.  
> [...]
> 
> I only moved the "static const" at the front, I haven't changed the
> code as it's already has been a declaration and definition.  There is
> no semicolon there and the original author put a newline to separate
> things which makes it look as if these were separate.
> 
> Simple example based on the existing code:
> 
>   https://godbolt.org/z/hV4HP7
> 
> I hope this helps to illustrate the change in the patch.  I apologise
> if my approach was incorrect.
> 
> As part of the patch I removed the newline in an aim to make it less
> confusing to anyone who will read the code in the future.  Especially,
> since it makes it a bit awkward to read and when using things like
> grep.
> 
> Krzysztof

I get what you are trying to do, the issue is the code is currently:

struct bh1750_chip_info {
	u16 mtreg_min;
	u16 mtreg_max;
	u16 mtreg_default;
	int mtreg_to_usec;
	int mtreg_to_scale;

	/*
	 * For BH1710/BH1721 all possible integration time values won't fit
	 * into one page so displaying is limited to every second one.
	 * Note, that user can still write proper values which were not
	 * listed.
	 */
	int inc;

	u16 int_time_low_mask;
	u16 int_time_high_mask;
}

static const bh1750_chip_info_tbl[] = {
	[BH1710] = { 140, 1022, 300, 400,  250000000, 2, 0x001F, 0x03E0 },
	[BH1721] = { 140, 1020, 300, 400,  250000000, 2, 0x0010, 0x03E0 },
	[BH1750] = { 31,  254,  69,  1740, 57500000,  1, 0x001F, 0x00E0 },
};

That test is supposed to catch the second block being

const static bh1750_chip_info_tbl[] = {
...

Which it isn't.  So the issue here was never that the static keyword
wasn't at the front of the declaration but that we could save a tiny
bit code by using the pattern

static const struct bh1750_chip_info {
...
} bh1750_chip_info_tbl[] {
	[...] = ...
};

We can do that of course, but that's nothing to do with moving the static
keyword to the front of the declaration which is what the patch claims
to be doing.

Jonathan






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: light: bh1750: Move static keyword to the front of declaration
  2019-09-10 13:35     ` Jonathan Cameron
@ 2019-09-10 20:25       ` Krzysztof Wilczynski
  0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Wilczynski @ 2019-09-10 20:25 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

Hello Jonathan,

Thank you for the feedback.  I really appreciate it.

[...]
> We can do that of course, but that's nothing to do with moving the static
> keyword to the front of the declaration which is what the patch claims
> to be doing.

I see your point.  I am going to send a v2 that hopefully will be much
cleaner and better worded.  Thank you!

Krzysztof

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-09-10 20:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-02 11:31 [PATCH] iio: light: bh1750: Move static keyword to the front of declaration Krzysztof Wilczynski
2019-09-03 17:35 ` Tomasz Duszynski
2019-09-08 10:49 ` Jonathan Cameron
2019-09-08 13:52   ` Krzysztof Wilczynski
2019-09-10 13:35     ` Jonathan Cameron
2019-09-10 20:25       ` Krzysztof Wilczynski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).