mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Oleksij Rempel <linux@rempel-privat.de>
Cc: barebox@lists.infradead.org,
	Rouven Czerwinski <r.czerwinski@pengutronix.de>
Subject: Re: [PATCH v2 4/8] serial_ns16550: handle default reg-io-width
Date: Fri, 14 Dec 2018 11:58:41 +0100	[thread overview]
Message-ID: <20181214105841.6fxgixefvbk273n6@pengutronix.de> (raw)
In-Reply-To: <21f248f5-59e9-c80b-aec7-6959c916a5eb@rempel-privat.de>

On Thu, Dec 13, 2018 at 04:56:46PM +0100, Oleksij Rempel wrote:
> Am 13.12.18 um 08:44 schrieb Rouven Czerwinski:
> > -	if (!of_property_read_u32(np, "reg-io-width", &width))
> > -		switch (width) {
> > -		case 1:
> > -			priv->read_reg = ns16550_read_reg_mmio_8;
> > -			priv->write_reg = ns16550_write_reg_mmio_8;
> > -			break;
> > -		case 2:
> > -			priv->read_reg = ns16550_read_reg_mmio_16;
> > -			priv->write_reg = ns16550_write_reg_mmio_16;
> > -			break;
> > -		case 4:
> > -			if (of_device_is_big_endian(np)) {
> > -				priv->read_reg = ns16550_read_reg_mmio_32be;
> > -				priv->write_reg = ns16550_write_reg_mmio_32be;
> > -			} else {
> > -				priv->read_reg = ns16550_read_reg_mmio_32;
> > -				priv->write_reg = ns16550_write_reg_mmio_32;
> > -			}
> > -			break;
> > -		default:
> > -			dev_err(dev, "unsupported reg-io-width (%d)\n",
> > -				width);
> > +	of_property_read_u32(np, "reg-io-width", &width);
> 
> i think it is not good to drop error handling completely. We may fail in
> different ways:
> static const void *of_find_property_value_of_size(const struct
> device_node *np,
> 			const char *propname, u32 len)
> {
> 	struct property *prop = of_find_property(np, propname, NULL);
> 	const void *value;
> 
> 	if (!prop)
> 		return ERR_PTR(-EINVAL);
> 	value = of_property_get_value(prop);
> 	if (!value)
> 		return ERR_PTR(-ENODATA);
> 	if (len > prop->length)
> 		return ERR_PTR(-EOVERFLOW);

Although we could differenciate between these different values and
return an error I think initializing a variable with a default and let
of_property_read_* overwrite it without further error checking is common
sense now, you can find hundreds of hits in the Linux Kernel.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

  reply	other threads:[~2018-12-14 10:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-13  7:44 [PATCH v2 0/8] Raspberry Pi miniuart support Rouven Czerwinski
2018-12-13  7:44 ` [PATCH v2 1/8] ARM: rpi: fix typo in rpi-common.c Rouven Czerwinski
2018-12-13  7:44 ` [PATCH v2 2/8] ARM: rpi: move clks into board specific rpi-common Rouven Czerwinski
2018-12-13  7:44 ` [PATCH v2 3/8] ARM: rpi: retrieve miniuart clock from firmware Rouven Czerwinski
2018-12-13  7:44 ` [PATCH v2 4/8] serial_ns16550: handle default reg-io-width Rouven Czerwinski
2018-12-13 15:56   ` Oleksij Rempel
2018-12-14 10:58     ` Sascha Hauer [this message]
2018-12-13  7:44 ` [PATCH v2 5/8] serial_ns16550: add raspberry pi compatible and init Rouven Czerwinski
2018-12-13 15:53   ` Oleksij Rempel
2018-12-13  7:44 ` [PATCH v2 6/8] ARM: rpi: add NS16550 support Rouven Czerwinski
2018-12-13  7:44 ` [PATCH v2 7/8] ARM: rpi: choose miniuart as stdout Rouven Czerwinski
2018-12-13  7:44 ` [PATCH v2 8/8] doc: bcm283x: remove miniuart overlay instruction Rouven Czerwinski

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=20181214105841.6fxgixefvbk273n6@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=linux@rempel-privat.de \
    --cc=r.czerwinski@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