From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Alexander Shiyan <shc_work@mail.ru>, linux-can@vger.kernel.org
Cc: Wolfgang Grandegger <wg@grandegger.com>
Subject: Re: [PATCH 3/4] can: mcp251x: Improve mcp251x_hw_probe()
Date: Tue, 01 Apr 2014 22:46:02 +0200 [thread overview]
Message-ID: <533B258A.3030801@pengutronix.de> (raw)
In-Reply-To: <1396001687-7092-3-git-send-email-shc_work@mail.ru>
[-- Attachment #1: Type: text/plain, Size: 2641 bytes --]
On 03/28/2014 11:14 AM, Alexander Shiyan wrote:
> This patch adds check for mcp251x_hw_reset() result on startup and
> removes unnecessary checking for CANSTAT register since this value
> is being checked in mcp251x_hw_reset().
>
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> ---
> drivers/net/can/mcp251x.c | 41 ++++++++++++++++++-----------------------
> 1 file changed, 18 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
> index fea41b4..f4786c8 100644
> --- a/drivers/net/can/mcp251x.c
> +++ b/drivers/net/can/mcp251x.c
> @@ -645,23 +645,19 @@ static int mcp251x_hw_reset(struct spi_device *spi)
>
> static int mcp251x_hw_probe(struct spi_device *spi)
> {
> - int st1, st2;
> + u8 ctrl;
> + int ret;
>
> - mcp251x_hw_reset(spi);
> + ret = mcp251x_hw_reset(spi);
> + if (ret)
> + return ret;
>
> - /*
> - * Please note that these are "magic values" based on after
> - * reset defaults taken from data sheet which allows us to see
> - * if we really have a chip on the bus (we avoid common all
> - * zeroes or all ones situations)
> - */
> - st1 = mcp251x_read_reg(spi, CANSTAT) & 0xEE;
> - st2 = mcp251x_read_reg(spi, CANCTRL) & 0x17;
> + ctrl = mcp251x_read_reg(spi, CANCTRL);
>
> - dev_dbg(&spi->dev, "CANSTAT 0x%02x CANCTRL 0x%02x\n", st1, st2);
> + dev_dbg(&spi->dev, "CANCTRL 0x%02x\n", ctrl);
>
> - /* Check for power up default values */
> - return (st1 == 0x80 && st2 == 0x07) ? 1 : 0;
> + /* Check for power up default value */
> + return ((ctrl & 0x17) == 0x07) ? 0 : -ENODEV;
I've converted this into:
+ if ((ctrl & 0x17) != 0x07)
+ return -ENODEV;
+
+ return 0;
...which is more readable, IMHO.
> }
>
> static int mcp251x_power_enable(struct regulator *reg, int enable)
> @@ -1138,19 +1134,18 @@ static int mcp251x_can_probe(struct spi_device *spi)
> SET_NETDEV_DEV(net, &spi->dev);
>
> /* Here is OK to not lock the MCP, no one knows about it yet */
> - if (!mcp251x_hw_probe(spi)) {
> - ret = -ENODEV;
> - goto error_probe;
> - }
> - mcp251x_hw_sleep(spi);
> + ret = mcp251x_hw_probe(spi);
> + if (!ret) {
I don't like the idea due to readability, that the non-error path is
inside the if () { }. I've fixed this, the diff is even smaller.
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 242 bytes --]
next prev parent reply other threads:[~2014-04-01 20:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-28 10:14 [PATCH 1/4] can: mcp251x: Check return value of spi_setup() Alexander Shiyan
2014-03-28 10:14 ` [PATCH 2/4] can: mcp251x: Improve mcp251x_hw_reset() Alexander Shiyan
2014-04-01 20:47 ` Marc Kleine-Budde
2014-03-28 10:14 ` [PATCH 3/4] can: mcp251x: Improve mcp251x_hw_probe() Alexander Shiyan
2014-04-01 20:46 ` Marc Kleine-Budde [this message]
2014-03-28 10:14 ` [PATCH 4/4] can: mcp251x: Remove unnecessary power disabling Alexander Shiyan
2014-04-01 20:36 ` Marc Kleine-Budde
2014-04-02 6:17 ` Alexander Shiyan
2014-04-02 7:05 ` Marc Kleine-Budde
2014-04-01 11:56 ` [PATCH 1/4] can: mcp251x: Check return value of spi_setup() Marc Kleine-Budde
2014-04-01 12:47 ` Alexander Shiyan
2014-04-01 12:49 ` Marc Kleine-Budde
2014-04-01 12:54 ` Alexander Shiyan
2014-04-01 20:40 ` Marc Kleine-Budde
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=533B258A.3030801@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=linux-can@vger.kernel.org \
--cc=shc_work@mail.ru \
--cc=wg@grandegger.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.