mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Trent Piepho <trent.piepho@igorinstitute.com>
To: Oleksij Rempel <o.rempel@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v1 3/4] ARM: rpi: validate devicetree compatible instead of changing model name
Date: Mon, 17 Jan 2022 12:14:17 -0800	[thread overview]
Message-ID: <CAMHeXxOMT7=Eo1Xsx484WQcX0eEXfSb9v9L7U6fLubBYnFz1WA@mail.gmail.com> (raw)
In-Reply-To: <20220117120500.3556703-3-o.rempel@pengutronix.de>

On Mon, Jan 17, 2022 at 4:06 AM Oleksij Rempel <o.rempel@pengutronix.de> wrote:
> +struct rpi_priv;
> +struct rpi_machine_data {
> +       unsigned int hw_id;
> +#define RPI_OLD_SCHEMA                 BIT(0)
> +       unsigned int flags;

hw_id is only a byte.  Both of these fields could be u8, which would
make the struct smaller.

> +struct rpi_priv {
> +       struct device_d *dev;
> +       const struct rpi_machine_data *dcfg;

Doesn't seem like there is any need to have dcfg saved in this struct.
It looks like it's used just once, in the same function that finds the
value.  rpi_get_dcfg() could return the value directly, rather than
indirectly by writing it into a field of a struct passed as an
argument.

>
> +static int rpi_get_dcfg(struct rpi_priv *priv)
> +{
> +       const struct rpi_machine_data *dcfg;
> +       int ret;
> +
> +       dcfg = of_device_get_match_data(priv->dev);
> +       if (!dcfg) {
> +               ret = -EINVAL;
> +               goto exit_get_dcfg;
> +       }

Then later:
> +       ret = rpi_get_dcfg(priv);
> +       if (ret)
> +               goto free_priv;

It looks like any board that doesn't have match data will be rejected
and fail to init.  But then what about these boards:

>  static const struct of_device_id rpi_of_match[] = {
>         /* BCM2711 based Boards */
>         { .compatible = "raspberrypi,400" },
> @@ -465,24 +599,24 @@ static const struct of_device_id rpi_of_match[] = {
>         { .compatible = "raspberrypi,4-model-b" },

Looks like they'll get rejected since they have no match data.

> +
> +       for (; dcfg->hw_id != UINT_MAX; dcfg++) {
> +               if (priv->hw_id & 0x800000) {
> +                       if (dcfg->hw_id != ((priv->hw_id >> 4) & 0xff))
> +                               continue;
> +               } else {
> +                       if (!(dcfg->flags & RPI_OLD_SCHEMA))
> +                               continue;
> +                       if (dcfg->hw_id != (priv->hw_id & 0xff))
> +                               continue;
> +               }
> +
> +               priv->dcfg = dcfg;
> +               break;

Could just return 0 here instead of break.  Or better, "return dcfg",
as there's no reason not to just return the value like a normal
function.

> +       }
> +
> +       if (!priv->dcfg) {
> +               ret = -ENODEV;
> +               goto exit_get_dcfg;
> +       }

Then this can become ret = -ENODEV and the if and goto go away.

> +
> +       priv = xzalloc(sizeof(*priv));
> +       if (!priv)
> +               return -ENOMEM;

No need to check the return value of "x" alloc functions.  That's the
whole point of the x version.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2022-01-17 20:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17 12:04 [PATCH v1 1/4] ARM: rpi: convert board code to a driver Oleksij Rempel
2022-01-17 12:04 ` [PATCH v1 2/4] ARM: rpi: move clk support to a separate driver and enable deep-probe Oleksij Rempel
2022-01-18  7:57   ` Sascha Hauer
2022-01-17 12:04 ` [PATCH v1 3/4] ARM: rpi: validate devicetree compatible instead of changing model name Oleksij Rempel
2022-01-17 20:14   ` Trent Piepho [this message]
2022-01-17 12:05 ` [PATCH v1 4/4] ARM: rpi: set host name based on DT compatible Oleksij Rempel

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='CAMHeXxOMT7=Eo1Xsx484WQcX0eEXfSb9v9L7U6fLubBYnFz1WA@mail.gmail.com' \
    --to=trent.piepho@igorinstitute.com \
    --cc=barebox@lists.infradead.org \
    --cc=o.rempel@pengutronix.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