Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: Saravana Kannan <saravanak@google.com>
Cc: linux-arm-kernel@lists.infradead.org, kernel@dh-electronics.com,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Arnd Bergmann <arnd@arndb.de>, Fabio Estevam <festevam@gmail.com>,
	Jeff Johnson <quic_jjohnson@quicinc.com>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Shawn Guo <shawnguo@kernel.org>,
	imx@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/2] soc: imx8m: Probe the SoC driver as platform driver
Date: Fri, 27 Sep 2024 23:42:41 +0200	[thread overview]
Message-ID: <e32ed329-b012-44f2-854b-80a8b0efc4e6@denx.de> (raw)
In-Reply-To: <CAGETcx-q7+DGhPYd3QrsPh7O_0HU7T=NhaJYp0Fu7YW2zwbo7Q@mail.gmail.com>

On 9/27/24 1:39 AM, Saravana Kannan wrote:

[...]

>> +static int imx8mq_soc_revision(u32 *socrev)
>>   {
>>          struct device_node *np;
>>          void __iomem *ocotp_base;
>>          u32 magic;
>>          u32 rev;
>>          struct clk *clk;
>> +       int ret;
>>
>>          np = of_find_compatible_node(NULL, NULL, "fsl,imx8mq-ocotp");
>>          if (!np)
>> -               return 0;
>> +               return -EINVAL;
>>
>>          ocotp_base = of_iomap(np, 0);
> 
> Using devm_of_iomap() and scoped "whatever it's called" might help
> simplify the error handling.
> 
> So something like this for np:
> struct device_node *np __free(device_node) = np =
> of_find_compatible_node(NULL, NULL, "fsl,imx8mq-ocotp");
> 
> And this for ocotp_base:
> ocotp_base = devm_of_iomap(dev, np, 0);

This would fail if OCOTP driver probes first and claims the memory area 
with request_mem_region() (or devm_request_mem_region(), used in 
__devm_ioremap_resource() which is called from devm_of_iomap()). I ran 
into this with ANATOP, which is the other iomap()d device here. The 
of_iomap() does not use request_mem_region(), so it can map the area.

> Would mean you can delete all the error handling parts

All right, let's do this in separate 3/3 patch , because the amount of 
changes in this one patch are growing to be too much and difficult to 
review.

[...]

>> @@ -212,8 +240,11 @@ static int __init imx8_soc_init(void)
>>          data = id->data;
>>          if (data) {
>>                  soc_dev_attr->soc_id = data->name;
>> -               if (data->soc_revision)
>> -                       soc_rev = data->soc_revision();
>> +               if (data->soc_revision) {
>> +                       ret = data->soc_revision(&soc_rev);
>> +                       if (ret)
>> +                               goto free_soc;
>> +               }
>>          }
> 
> I'm glad it's working for you, but I think there might still be a race
> that you are just lucky enough to not hit. I think you still need to
> fix up drivers/base/soc.c to return -EPROBE_DEFER when
> soc_device_match() is called but soc_bus_type has no devices
> registered. That way any drivers that try to use that API will defer
> probe until this device gets to probe.

soc_device_match() returns a pointer to soc_device_attribute or NULL, do 
you have some other function in mind ?

> And then you'll have to look at all the callers of that API for the
> boards this driver is meant for and make sure they don't ignore the
> error return value. Just add a WARN() on the API to figure out all the
> callers in your board.
> 
> Also, you might want to check that your list of probed devices doesn't
> change without any async probing or this patch vs with async probing
> and this patch. Quick way to get list of successfully probed devices
> is:
> # find /sys/devices -name driver

It seems OK.

[...]

  parent reply	other threads:[~2024-09-27 21:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-26 21:36 [PATCH v3 1/2] soc: imx8m: Probe the SoC driver as platform driver Marek Vasut
2024-09-26 21:36 ` [PATCH v3 2/2] soc: imx8m: Remove global soc_uid Marek Vasut
2024-09-27 16:58   ` Frank Li
2024-09-27 20:05     ` Marek Vasut
2024-09-26 23:39 ` [PATCH v3 1/2] soc: imx8m: Probe the SoC driver as platform driver Saravana Kannan
2024-09-27 11:56   ` Arnd Bergmann
2024-09-27 21:42   ` Marek Vasut [this message]
2024-09-27 22:27     ` Saravana Kannan
2024-09-28 14:09       ` Arnd Bergmann
2024-09-29 18:47       ` Marek Vasut

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=e32ed329-b012-44f2-854b-80a8b0efc4e6@denx.de \
    --to=marex@denx.de \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=arnd@arndb.de \
    --cc=festevam@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@dh-electronics.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=quic_jjohnson@quicinc.com \
    --cc=s.hauer@pengutronix.de \
    --cc=saravanak@google.com \
    --cc=shawnguo@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