From: Russell King - ARM Linux admin <linux@armlinux.org.uk>
To: Anson Huang <anson.huang@nxp.com>
Cc: "catalin.marinas@arm.com" <catalin.marinas@arm.com>,
"will.deacon@arm.com" <will.deacon@arm.com>,
"shawnguo@kernel.org" <shawnguo@kernel.org>,
"s.hauer@pengutronix.de" <s.hauer@pengutronix.de>,
"kernel@pengutronix.de" <kernel@pengutronix.de>,
"festevam@gmail.com" <festevam@gmail.com>,
"maxime.ripard@bootlin.com" <maxime.ripard@bootlin.com>,
"olof@lixom.net" <olof@lixom.net>,
"agross@kernel.org" <agross@kernel.org>,
"jagan@amarulasolutions.com" <jagan@amarulasolutions.com>,
"bjorn.andersson@linaro.org" <bjorn.andersson@linaro.org>,
Leonard Crestez <leonard.crestez@nxp.com>,
"dinguyen@kernel.org" <dinguyen@kernel.org>,
"enric.balletbo@collabora.com" <enric.balletbo@collabora.com>,
Aisheng Dong <aisheng.dong@nxp.com>,
Abel Vesa <abel.vesa@nxp.com>,
"l.stach@pengutronix.de" <l.stach@pengutronix.de>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"robh@kernel.org" <robh@kernel.org>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
dl-linux-imx <linux-imx@nxp.com>
Subject: Re: [PATCH V6 1/2] soc: imx: Add SCU SoC info driver support
Date: Thu, 23 May 2019 10:09:41 +0100 [thread overview]
Message-ID: <20190523090941.zd4rbvcimgit5lq5@shell.armlinux.org.uk> (raw)
In-Reply-To: <1558586911-29309-1-git-send-email-Anson.Huang@nxp.com>
On Thu, May 23, 2019 at 04:53:46AM +0000, Anson Huang wrote:
> Add i.MX SCU SoC info driver to support i.MX8QXP SoC, introduce
> driver dependency into Kconfig as CONFIG_IMX_SCU must be
> selected to support i.MX SCU SoC driver, also need to use
> platform driver model to make sure IMX_SCU driver is probed
> before i.MX SCU SoC driver.
This seems buggy...
> +static int imx_scu_soc_probe(struct platform_device *pdev)
> +{
> + struct soc_device_attribute *soc_dev_attr;
> + struct soc_device *soc_dev;
> + u32 id, val;
> + int ret;
> +
> + ret = imx_scu_get_handle(&soc_ipc_handle);
> + if (ret)
> + return ret;
> +
> + soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr),
> + GFP_KERNEL);
> + if (!soc_dev_attr)
> + return -ENOMEM;
> +
> + soc_dev_attr->family = "Freescale i.MX";
> +
> + ret = of_property_read_string(of_root,
> + "model",
> + &soc_dev_attr->machine);
> + if (ret)
> + return ret;
> +
> + id = imx_scu_soc_id();
> +
> + /* format soc_id value passed from SCU firmware */
> + val = id & 0x1f;
> + soc_dev_attr->soc_id = val ? kasprintf(GFP_KERNEL, "0x%x", val)
> + : "unknown";
soc_id can either be an allocated string, or it can be a static string
of "unknown".
> + if (!soc_dev_attr->soc_id)
> + return -ENOMEM;
> +
> + /* format revision value passed from SCU firmware */
> + val = (id >> 5) & 0xf;
> + val = (((val >> 2) + 1) << 4) | (val & 0x3);
> + soc_dev_attr->revision = val ? kasprintf(GFP_KERNEL,
> + "%d.%d",
> + (val >> 4) & 0xf,
> + val & 0xf) : "unknown";
revision here is the same.
> + if (!soc_dev_attr->revision) {
> + ret = -ENOMEM;
> + goto free_soc_id;
> + }
> +
> + soc_dev = soc_device_register(soc_dev_attr);
> + if (IS_ERR(soc_dev)) {
> + ret = PTR_ERR(soc_dev);
> + goto free_revision;
> + }
> +
> + return 0;
> +
> +free_revision:
> + kfree(soc_dev_attr->revision);
> +free_soc_id:
> + kfree(soc_dev_attr->soc_id);
Yet here you blindly kfree(), which means you could be doing in effect
kfree("unknown") - which will likely result in a kernel oops.
Either always make revision/soc_id an allocated string, or use some
static storage for the strings (they're only small, static storage is
likely to be much more efficient in this case, and there can only be
one of these in any case.)
> + return ret;
> +}
> +
> +static struct platform_driver imx_scu_soc_driver = {
> + .driver = {
> + .name = IMX_SCU_SOC_DRIVER_NAME,
> + },
> + .probe = imx_scu_soc_probe,
> +};
> +
> +static int __init imx_scu_soc_init(void)
> +{
> + struct platform_device *imx_scu_soc_pdev;
> + struct device_node *np;
> + int ret;
> +
> + np = of_find_compatible_node(NULL, NULL, "fsl,imx-scu");
> + if (!np)
> + return -ENODEV;
> +
> + of_node_put(np);
> +
> + ret = platform_driver_register(&imx_scu_soc_driver);
> + if (ret)
> + return ret;
> +
> + imx_scu_soc_pdev =
> + platform_device_register_simple(IMX_SCU_SOC_DRIVER_NAME,
> + -1,
> + NULL,
> + 0);
> + if (IS_ERR(imx_scu_soc_pdev))
> + platform_driver_unregister(&imx_scu_soc_driver);
> +
> + return PTR_ERR_OR_ZERO(imx_scu_soc_pdev);
> +}
> +device_initcall(imx_scu_soc_init);
> --
> 2.7.4
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
next prev parent reply other threads:[~2019-05-23 9:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-23 4:53 Anson Huang
2019-05-23 4:53 ` [PATCH V6 2/2] arm64: defconfig: Add i.MX SCU SoC info driver Anson Huang
2019-05-23 9:09 ` Russell King - ARM Linux admin [this message]
2019-05-23 9:35 ` [PATCH V6 1/2] soc: imx: Add SCU SoC info driver support Anson Huang
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=20190523090941.zd4rbvcimgit5lq5@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=abel.vesa@nxp.com \
--cc=agross@kernel.org \
--cc=aisheng.dong@nxp.com \
--cc=anson.huang@nxp.com \
--cc=bjorn.andersson@linaro.org \
--cc=catalin.marinas@arm.com \
--cc=dinguyen@kernel.org \
--cc=enric.balletbo@collabora.com \
--cc=festevam@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jagan@amarulasolutions.com \
--cc=kernel@pengutronix.de \
--cc=l.stach@pengutronix.de \
--cc=leonard.crestez@nxp.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maxime.ripard@bootlin.com \
--cc=olof@lixom.net \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=tglx@linutronix.de \
--cc=will.deacon@arm.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 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®