mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: Viacheslav Bocharov <adeep@lexina.in>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Kevin Hilman <khilman@baylibre.com>,
	Jerome Brunet <jbrunet@baylibre.com>,
	Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-amlogic@lists.infradead.org
Cc: Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
Subject: Re: [PATCH v3 2/4] soc: amlogic: meson-gx-socinfo-sm: Add Amlogic secure-monitor SoC Information driver
Date: Thu, 14 Mar 2024 08:11:57 +0100	[thread overview]
Message-ID: <111346d3-8357-4ca3-9249-a43ebc225fcb@linaro.org> (raw)
In-Reply-To: <20240314070433.4151931-3-adeep@lexina.in>

On 14/03/2024 07:59, Viacheslav Bocharov wrote:
> Amlogic SoCs have a SoC information secure-monitor call for SoC type,
> package type, revision information and chipid.
> This patchs adds support for secure-monitor call decoding and exposing
> with the SoC bus infrastructure in addition to the previous SoC
> Information driver.
> 
> Signed-off-by: Viacheslav Bocharov <adeep@lexina.in>
> ---
>  drivers/soc/amlogic/Kconfig               |  10 ++
>  drivers/soc/amlogic/Makefile              |   1 +
>  drivers/soc/amlogic/meson-gx-socinfo-sm.c | 192 ++++++++++++++++++++++
>  3 files changed, 203 insertions(+)
>  create mode 100644 drivers/soc/amlogic/meson-gx-socinfo-sm.c
> 
> diff --git a/drivers/soc/amlogic/Kconfig b/drivers/soc/amlogic/Kconfig
> index d08e398bdad4..82fc77ca3b4b 100644
> --- a/drivers/soc/amlogic/Kconfig
> +++ b/drivers/soc/amlogic/Kconfig
> @@ -26,6 +26,16 @@ config MESON_GX_SOCINFO
>  	  Say yes to support decoding of Amlogic Meson GX SoC family
>  	  information about the type, package and version.
>  
> +config MESON_GX_SOCINFO_SM
> +	bool "Amlogic Meson GX SoC Information driver via Secure Monitor"
> +	depends on (ARM64 && ARCH_MESON || COMPILE_TEST) && MESON_SM=y
> +	default ARCH_MESON && MESON_SM
> +	select SOC_BUS
> +	help
> +	  Say yes to support decoding of Amlogic Meson GX SoC family
> +	  information about the type, package and version via secure
> +	  monitor call.
> +

I wonder, why do you need socinfo driver per each SoC? Usually it is one
or two per entire arch.

> +
> +static int meson_gx_socinfo_sm_probe(struct platform_device *pdev)
> +{
> +	struct soc_device_attribute *soc_dev_attr;
> +	struct soc_device *soc_dev;
> +	struct device_node *sm_np;
> +	struct meson_sm_firmware *fw;
> +	struct regmap *regmap;
> +	union meson_cpu_id socinfo;
> +	struct device *dev;
> +	int ret;
> +
> +	/* check if chip-id is available */
> +	if (!of_property_read_bool(pdev->dev.of_node, "amlogic,has-chip-id"))
> +		return -ENODEV;
> +
> +	/* node should be a syscon */
> +	regmap = syscon_node_to_regmap(pdev->dev.of_node);
> +	if (IS_ERR(regmap)) {
> +		dev_err(&pdev->dev, "failed to get regmap\n");

Syntax is:

return dev_err_probe()

> +		return -ENODEV;

Anyway wrong return code, use the real one you got.

> +	}
> +
> +	sm_np = of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
> +	if (!sm_np) {
> +		dev_err(&pdev->dev, "no secure-monitor node found\n");
> +		return -ENODEV;

-EINVAL

> +	}
> +
> +	fw = meson_sm_get(sm_np);
> +	of_node_put(sm_np);
> +	if (!fw) {
> +		dev_info(&pdev->dev, "secure-monitor device not ready, probe later\n");

No, you never print messages on deferred probe.

> +		return -EPROBE_DEFER;
> +	}
> +
> +	ret = regmap_read(regmap, AO_SEC_SOCINFO_OFFSET, &socinfo.raw);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (!socinfo.raw) {
> +		dev_err(&pdev->dev, "invalid regmap chipid value\n");
> +		return -EINVAL;
> +	}
> +
> +	soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr),
> +				    GFP_KERNEL);
> +	if (!soc_dev_attr)
> +		return -ENOMEM;
> +
> +	soc_dev_attr->serial_number = socinfo_get_chipid(&pdev->dev, fw, &socinfo);
> +
> +	soc_dev_attr->family = "Amlogic Meson";
> +	soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%x:%x - %x:%x",
> +					   socinfo.v1.major_id,
> +					   socinfo.v1.chip_rev,
> +					   socinfo.v1.pack_id,
> +					   (socinfo.v1.reserved<<4) + socinfo.v1.layout_ver);
> +	soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%s (%s)",
> +					 socinfo_v1_to_soc_id(socinfo),
> +					 socinfo_v1_to_package_id(socinfo));
> +
> +	soc_dev = soc_device_register(soc_dev_attr);
> +
> +
> +	if (IS_ERR(soc_dev)) {
> +		kfree(soc_dev_attr->revision);
> +		kfree_const(soc_dev_attr->soc_id);
> +		kfree(soc_dev_attr);

That's a double free. This was not tested.

> +		return PTR_ERR(soc_dev);
> +	}
> +
> +	dev = soc_device_to_device(soc_dev);
> +	platform_set_drvdata(pdev, soc_dev);
> +
> +	dev_info(dev, "Amlogic Meson %s Revision %x:%x (%x:%x) Detected (SM)\n",
> +			soc_dev_attr->soc_id,
> +			socinfo.v1.major_id,
> +			socinfo.v1.chip_rev,
> +			socinfo.v1.pack_id,
> +			(socinfo.v1.reserved<<4) + socinfo.v1.layout_ver);
> +
> +	return PTR_ERR_OR_ZERO(dev);
> +}
> +
> +
> +static int meson_gx_socinfo_sm_remove(struct platform_device *pdev)
> +{
> +	struct soc_device *soc_dev = platform_get_drvdata(pdev);
> +
> +	soc_device_unregister(soc_dev);

If you free the memory in probe() error path, why you did not decide to
free it here as well? It is symmetrical, so this should make you wonder
- error path is wrong.


Best regards,
Krzysztof


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  reply	other threads:[~2024-03-14  7:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-14  6:59 [PATCH v3 0/4] soc: amlogic: add new meson-gx-socinfo-sm driver Viacheslav Bocharov
2024-03-14  6:59 ` [PATCH v3 1/4] soc: amlogic: meson-gx-socinfo: move common code to header file Viacheslav Bocharov
2024-03-14  6:59 ` [PATCH v3 2/4] soc: amlogic: meson-gx-socinfo-sm: Add Amlogic secure-monitor SoC Information driver Viacheslav Bocharov
2024-03-14  7:11   ` Krzysztof Kozlowski [this message]
2024-03-14 12:22     ` Viacheslav
2024-03-14 13:31       ` Krzysztof Kozlowski
2024-03-14 13:59         ` Viacheslav
2024-03-14  6:59 ` [PATCH v3 3/4] soc: amlogic: meson-gx-socinfo: add new definition for Amlogic A113X package Viacheslav Bocharov
2024-03-14  6:59 ` [PATCH v3 4/4] arm64: dts: meson: add dts links to secure-monitor for soc driver in a1, axg, gx, g12 Viacheslav Bocharov
2024-03-14 10:40 ` [PATCH v3 0/4] soc: amlogic: add new meson-gx-socinfo-sm driver Sudeep Holla
2024-03-14 12:25   ` Viacheslav
2024-03-14 14:30     ` Sudeep Holla

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=111346d3-8357-4ca3-9249-a43ebc225fcb@linaro.org \
    --to=krzysztof.kozlowski@linaro.org \
    --cc=adeep@lexina.in \
    --cc=jbrunet@baylibre.com \
    --cc=khilman@baylibre.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=neil.armstrong@linaro.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

all inboxes | Powered by JetHome®