All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Wunner <lukas@wunner.de>
To: Chris Morgan <macroalpha82@gmail.com>
Cc: linux-spi@vger.kernel.org, jon.lin@rock-chips.com,
	broonie@kernel.org, robh+dt@kernel.org, heiko@sntech.de,
	jbx6244@gmail.com, hjc@rock-chips.com,
	yifeng.zhao@rock-chips.com, sugar.zhang@rock-chips.com,
	linux-rockchip@lists.infradead.org,
	linux-mtd@lists.infradead.org, p.yadav@ti.com,
	Chris Morgan <macromorgan@hotmail.com>
Subject: Re: [RFC v4 2/8] spi: rockchip-sfc: add rockchip serial flash controller
Date: Sun, 6 Jun 2021 12:47:33 +0200	[thread overview]
Message-ID: <20210606104733.GA30175@wunner.de> (raw)
In-Reply-To: <20210604151055.28636-3-macroalpha82@gmail.com>

On Fri, Jun 04, 2021 at 10:10:49AM -0500, Chris Morgan wrote:
> +static int rockchip_sfc_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct spi_master *master;
> +	struct resource *res;
> +	struct rockchip_sfc *sfc;
> +	int ret;
> +
> +	master = spi_alloc_master(&pdev->dev, sizeof(*sfc));

You need to use devm_spi_alloc_master() here because you're not
freeing the allocation in any of the probe error paths.

> +	if (!master) {
> +		dev_err(&pdev->dev, "spi_alloc_master failed\n");
> +		return -ENOMEM;
> +	}

The dev_err() is superfluous as the memory allocator will dump a
stack trace anyway on allocation failure.

> +	ret = clk_prepare_enable(sfc->hclk);
> +	if (ret) {
> +		dev_err(&pdev->dev, "Failed to enable ahb clk\n");
> +		goto err_hclk;
> +	}

Return directly here and get rid of the err_hclk label.

> +	ret = devm_spi_register_master(dev, master);

You need to use spi_register_master() here (*not* the devm variant)
and add spi_unregister_master() at the top of rockchip_sfc_remove().

The reason is that ->remove() is executed *before* devres resources
are freed and rockchip_sfc_remove() disables the clocks, presumably
rendering the chip inaccessible.

However the chip may be performing SPI transfers until
spi_unregister_master() returns, so the chip needs to be accessible
as long.

Because you're using devm_spi_register_master(), the chip may try
to perform SPI transfers even though its clocks have been disabled.
So you've got an ordering problem with the devm variant.

> +MODULE_LICENSE("GPL v2");
> +MODULE_DESCRIPTION("Rockchip Serial Flash Controller Driver");
> +MODULE_AUTHOR("Shawn Lin <shawn.lin@rock-chips.com>");

Why isn't Shawn Lin cc'ed or gets commit authorship even though they're
the driver author?

Thanks,

Lukas

  reply	other threads:[~2021-06-06 10:47 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-04 15:10 [RFC v4 0/8] Add Rockchip SFC(serial flash controller) support Chris Morgan
2021-06-04 15:10 ` Chris Morgan
2021-06-04 15:10 ` Chris Morgan
2021-06-04 15:10 ` [RFC v4 1/8] dt-bindings: rockchip-sfc: Bindings for Rockchip serial flash controller Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-04 15:31   ` Rob Herring
2021-06-04 15:31     ` Rob Herring
2021-06-04 15:31     ` Rob Herring
2021-06-04 15:44     ` Chris Morgan
2021-06-04 15:44       ` Chris Morgan
2021-06-04 15:10 ` [RFC v4 2/8] spi: rockchip-sfc: add rockchip " Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-06 10:47   ` Lukas Wunner [this message]
2021-06-04 15:10 ` [RFC v4 3/8] arm64: dts: rockchip: Add SFC to PX30 Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-04 15:10 ` [RFC v4 4/8] clk: rockchip: Add support for hclk_sfc on rk3036 Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-04 15:10 ` [RFC v4 5/8] arm: dts: rockchip: Add SFC to RK3036 Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-04 15:10 ` [RFC v4 6/8] arm: dts: rockchip: Add SFC to RV1108 Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-04 15:10 ` [RFC v4 7/8] arm64: dts: rockchip: Add SFC to RK3308 Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-04 15:10 ` [RFC v4 8/8] arm64: dts: rockchip: Enable SFC for Odroid Go Advance Chris Morgan
2021-06-04 15:10   ` Chris Morgan
2021-06-04 15:10   ` Chris Morgan

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=20210606104733.GA30175@wunner.de \
    --to=lukas@wunner.de \
    --cc=broonie@kernel.org \
    --cc=heiko@sntech.de \
    --cc=hjc@rock-chips.com \
    --cc=jbx6244@gmail.com \
    --cc=jon.lin@rock-chips.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=macroalpha82@gmail.com \
    --cc=macromorgan@hotmail.com \
    --cc=p.yadav@ti.com \
    --cc=robh+dt@kernel.org \
    --cc=sugar.zhang@rock-chips.com \
    --cc=yifeng.zhao@rock-chips.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.