public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Joseph CHAMG <josright123@gmail.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	joseph_chang@davicom.com.tw, netdev@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	Leon Romanovsky <leon@kernel.org>
Subject: Re: [PATCH v9, 2/2] net: Add dm9051 driver
Date: Tue, 28 Dec 2021 11:22:48 +0100	[thread overview]
Message-ID: <YcrleBNQhHCHhmL5@lunn.ch> (raw)
In-Reply-To: <20211227100233.8037-3-josright123@gmail.com>

> +#define	dm9051_inb(db, reg, prxb)	dm9051_xfer(db, DM_SPI_RD | (reg), NULL, prxb, 1)
> +#define	dm9051_outb(db, reg, ptxb)	dm9051_xfer(db, DM_SPI_WR | (reg), ptxb, NULL, 1)
> +#define	dm9051_inblk(db, buff, len)	dm9051_xfer(db, DM_SPI_RD | DM_SPI_MRCMD, NULL, buff, len)
> +#define	dm9051_outblk(db, buff, len)	dm9051_xfer(db, DM_SPI_WR | DM_SPI_MWCMD, buff, NULL, len)

How many times do i have to say it, no wrappers. This makes it a lot
less obvious you are throwing away the error code from dm9051_xfer().

> +/* spi low level code */
> +static int dm9051_xfer(struct board_info *db, u8 cmd, u8 *txb, u8 *rxb, unsigned int len)
> +{
> +	struct device *dev = &db->spidev->dev;
> +	int ret;
> +
> +	db->cmd[0] = cmd;
> +	db->spi_xfer2[0].tx_buf = &db->cmd[0];
> +	db->spi_xfer2[0].rx_buf = NULL;
> +	db->spi_xfer2[0].len = 1;
> +	db->spi_xfer2[1].tx_buf = txb;
> +	db->spi_xfer2[1].rx_buf = rxb;
> +	db->spi_xfer2[1].len = len;
> +	ret = spi_sync(db->spidev, &db->spi_msg);
> +	if (ret < 0)
> +		dev_err(dev, "spi burst cmd 0x%02x, ret=%d\n", cmd, ret);
> +	return ret;
> +}
> +
> +static u8 dm9051_getreg(struct board_info *db, unsigned int reg)
> +{
> +	int ret;
> +	u8 rxb[1];
> +
> +	ret = dm9051_inb(db, reg, rxb);
> +	if (ret < 0) {

If ret < 0 you probably have had an SPI error, -EIO, or maybe -ETIMEDOUT? 

> +		if (reg == DM9051_NSR)
> +			return NSR_TX2END | NSR_TX1END;
> +		if (reg == DM9051_EPCR)
> +			return (u8)(~EPCR_ERRE);

So please add a comment explaining why it is O.K. to return these
values when you probably cannot even talk to the device.

> +		return 0;

And here you should be returning the error code. And whatever called
dm9051_getreg() needs to deal with that error code, probably returning
it to its caller, etc.

> +	}
> +	return rxb[0];
> +}
> +

> +static int dm9051_phy_read(struct board_info *db, int reg, int *pvalue)
> +{
> +	int ret;
> +	u8 check_val;
> +	u8 eph, epl;
> +
> +	dm9051_iow(db, DM9051_EPAR, DM9051_PHY | reg);

dm9051_iow() returns an error code. You should check for an error, and
return it. dm9051_mdio_read() already does the correct thing, passing
the error code along. The MDIO core will then pass the error along to
phylib, and phylib will probably report the error to user space and
probably disable the PHY, since the PHY is no longer accessible. That
is how error handling should work.

Since you still do not have the trivial things correct, i've not done
a deep review yet. I would not expect this driver to be merged very
soon, and until somebody does make a deeper review, there could be
more serious things wrong with this driver, like locking.

     Andrew


  parent reply	other threads:[~2021-12-28 10:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-27 10:02 [PATCH v9, 0/2] ADD DM9051 ETHERNET DRIVER Joseph CHAMG
2021-12-27 10:02 ` [PATCH v9, 1/2] yaml: Add dm9051 SPI network yaml file Joseph CHAMG
2021-12-27 10:02 ` [PATCH v9, 2/2] net: Add dm9051 driver Joseph CHAMG
2021-12-28  1:49   ` Jakub Kicinski
2021-12-28 10:22   ` Andrew Lunn [this message]
     [not found]   ` <CAHp75Vfgd=O_SukOrD4Adw4v7JdPBWsVsjwkj2-TiRy=Vk1mPA@mail.gmail.com>
2021-12-28 15:34     ` Andrew Lunn

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=YcrleBNQhHCHhmL5@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=joseph_chang@davicom.com.tw \
    --cc=josright123@gmail.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /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