public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Jonathan Neuschäfer" <j.neuschaefer@gmx.net>
To: Paul Menzel <pmenzel@molgen.mpg.de>
Cc: "Jonathan Neuschäfer" <j.neuschaefer@gmx.net>,
	openbmc@lists.ozlabs.org, "Arnd Bergmann" <arnd@arndb.de>,
	linux-kernel@vger.kernel.org,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Hector Martin" <marcan@marcan.st>,
	"Nicolas Ferre" <nicolas.ferre@microchip.com>,
	"Conor Dooley" <conor.dooley@microchip.com>,
	"Joel Stanley" <joel@jms.id.au>
Subject: Re: [PATCH v2] soc: nuvoton: Add SoC info driver for WPCM450
Date: Thu, 14 Apr 2022 19:02:27 +0200	[thread overview]
Message-ID: <YlhTo+F0p7ggPAQb@latitude> (raw)
In-Reply-To: <67f42821-34ad-cee6-98fb-7086599c4c0f@molgen.mpg.de>

[-- Attachment #1: Type: text/plain, Size: 2384 bytes --]

On Sat, Apr 09, 2022 at 07:55:09PM +0200, Paul Menzel wrote:
> Dear Jonathan,
> 
> 
> Thank you for your patch.
> 
> Am 09.04.22 um 19:33 schrieb Jonathan Neuschäfer:
> > Add a SoC information driver for Nuvoton WPCM450 SoCs. It provides
> > information such as the SoC revision.
> 
> Maybe add an example command, how to read the model and revision.

Will do.


> 
> > Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
> > Reviewed-by: Joel Stanley <joel@jms.id.au>
> > ---
[...]
> > +#define GCR_PDID	0
> > +#define PDID_CHIP(x)	((x) & 0x00ffffff)
> > +#define CHIP_WPCM450	0x926450
> > +#define PDID_REV(x)	((x) >> 24)
> > +
> > +struct revision {
> > +	u8 number;
> 
> Can this be just be `unsigned int`s

It could be, but it's unnecessary because I'm dealing with a 8-bit value
here.

The same amount of space is used in the struct whether I declare the
value as unsigned int or as u8, but with u8 it's clearer that it's
really (always) just an 8-bit value.

> 
> > +	const char *name;
> > +};
> > +
> > +const struct revision revisions[] __initconst = {

Unrelated to your comments, I noticed that this table can and should be
declared static.

> > +	{ 0x00, "Z1" },
> > +	{ 0x03, "Z2" },
> > +	{ 0x04, "Z21" },
> > +	{ 0x08, "A1" },
> > +	{ 0x09, "A2" },
> > +	{ 0x0a, "A3" },
> > +	{}
> > +};
> > +
> > +static const char * __init get_revision(u8 rev)
> > +{
> > +	int i;
> 
> I’d do `unsigned int`, though it does not make a difference in the end
> result.

To avoid unexpected silent truncation that sort of makes sense.
> 
> > +
> > +	for (i = 0; revisions[i].name; i++)
> > +		if (revisions[i].number == rev)
> > +			return revisions[i].name;
> > +	return NULL;
> > +}
> > +
> > +static int __init wpcm450_soc_init(void)
> > +{
[...]
> > +
> > +	revision = get_revision(PDID_REV(pdid));
> 
> The signature of `get_revision()` is u8, but you pass u32, if I am not
> mistaken.

The truncation to u8 is fine in this case, because PDID_REV extracts an
8 bit value and the upper 24 bits of the result of PDID_REV are thus
always already zero.

> 
> > +	if (!revision) {
> > +		pr_warn("Unknown chip revision in GCR.PDID: 0x%02x\n", PDID_REV(pdid));
> > +		return -ENODEV;
> > +	}
[...]
> > 
> 
> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>

Thank you!

Jonathan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2022-04-14 17:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-09 17:33 [PATCH v2] soc: nuvoton: Add SoC info driver for WPCM450 Jonathan Neuschäfer
2022-04-09 17:55 ` Paul Menzel
2022-04-14 17:02   ` Jonathan Neuschäfer [this message]

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=YlhTo+F0p7ggPAQb@latitude \
    --to=j.neuschaefer@gmx.net \
    --cc=arnd@arndb.de \
    --cc=conor.dooley@microchip.com \
    --cc=joel@jms.id.au \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcan@marcan.st \
    --cc=nicolas.ferre@microchip.com \
    --cc=openbmc@lists.ozlabs.org \
    --cc=pmenzel@molgen.mpg.de \
    /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