lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Thu, 14 Apr 2022 19:02:27 +0200
From:   Jonathan Neuschäfer <j.neuschaefer@....net>
To:     Paul Menzel <pmenzel@...gen.mpg.de>
Cc:     Jonathan Neuschäfer <j.neuschaefer@....net>,
        openbmc@...ts.ozlabs.org, Arnd Bergmann <arnd@...db.de>,
        linux-kernel@...r.kernel.org,
        Linus Walleij <linus.walleij@...aro.org>,
        Hector Martin <marcan@...can.st>,
        Nicolas Ferre <nicolas.ferre@...rochip.com>,
        Conor Dooley <conor.dooley@...rochip.com>,
        Joel Stanley <joel@....id.au>
Subject: Re: [PATCH v2] soc: nuvoton: Add SoC info driver for WPCM450

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@....net>
> > Reviewed-by: Joel Stanley <joel@....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@...gen.mpg.de>

Thank you!

Jonathan

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ