linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jonathan.cameron@huawei.com>
To: Krzysztof Wilczynski <kw@linux.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	<linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] iio: light: bh1750: Move static keyword to the front of declaration
Date: Tue, 10 Sep 2019 14:35:50 +0100	[thread overview]
Message-ID: <20190910143550.00000e64@huawei.com> (raw)
In-Reply-To: <20190908135208.GA29162@rocinante>

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






  reply	other threads:[~2019-09-10 13:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2019-09-10 20:25       ` Krzysztof Wilczynski
2019-09-10 20:38 ` [PATCH v2] iio: light: bh1750: Resolve compiler warning and make code more readable Krzysztof Wilczynski
2019-09-10 21:04   ` Uwe Kleine-König
2019-09-13 20:24   ` [PATCH v3] " Krzysztof Wilczynski
2019-09-15  9:48     ` Jonathan Cameron
2019-09-15 18:41       ` Krzysztof Wilczynski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190910143550.00000e64@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=kw@linux.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).