[1/2] ARM: imx: Fix boot crash if ocotp is not found
diff mbox series

Message ID 68b9e3bc9c60c89017648bf3abe150fd0abbde86.1576014367.git.leonard.crestez@nxp.com
State Accepted
Headers show
Series
  • Fix imx6ull/6ulz boot crash
Related show

Commit Message

Leonard Crestez Dec. 10, 2019, 9:49 p.m. UTC
The imx_soc_device_init functions tries to fetch the ocotp regmap in
order to soc serial number. If regmap fetch fails then a message is
printed but regmap_read is called anyway and the system crashes.

Failing to lookup ocotp regmap shouldn't be a fatal boot error so check
that the pointer is valid.

Only side-effect of ocotp lookup failure now is that serial number will
be reported as all-zeros which is acceptable.

Cc: stable@vger.kernel.org
Fixes: 8267ff89b713 ("ARM: imx: Add serial number support for i.MX6/7 SoCs")
Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
---
 arch/arm/mach-imx/cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Christoph Niedermaier Dec. 11, 2019, 10:25 a.m. UTC | #1
From: Leonard Crestez <leonard.crestez@nxp.com>
Sent: Tuesday, December 10, 2019 10:49 PM
> The imx_soc_device_init functions tries to fetch the ocotp regmap in
> order to soc serial number. If regmap fetch fails then a message is
> printed but regmap_read is called anyway and the system crashes.
>
> Failing to lookup ocotp regmap shouldn't be a fatal boot error so check
> that the pointer is valid.
>
> Only side-effect of ocotp lookup failure now is that serial number will
> be reported as all-zeros which is acceptable.
>
> Cc: stable@vger.kernel.org
> Fixes: 8267ff89b713 ("ARM: imx: Add serial number support for i.MX6/7 SoCs")
> Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
> ---
>  arch/arm/mach-imx/cpu.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/mach-imx/cpu.c b/arch/arm/mach-imx/cpu.c
> index d70b6fc72b35..484bf6cdb363 100644
> --- a/arch/arm/mach-imx/cpu.c
> +++ b/arch/arm/mach-imx/cpu.c
> @@ -87,11 +87,11 @@ struct device * __init imx_soc_device_init(void)
>  {
>  	struct soc_device_attribute *soc_dev_attr;
>  	const char *ocotp_compat = NULL;
>  	struct soc_device *soc_dev;
>  	struct device_node *root;
> -	struct regmap *ocotp;
> +	struct regmap *ocotp = NULL;
>  	const char *soc_id;
>  	u64 soc_uid = 0;
>  	u32 val;
>  	int ret;
>  
> @@ -179,11 +179,13 @@ struct device * __init imx_soc_device_init(void)
>  
>  	if (ocotp_compat) {
>  		ocotp = syscon_regmap_lookup_by_compatible(ocotp_compat);
>  		if (IS_ERR(ocotp))
>  			pr_err("%s: failed to find %s regmap!\n", __func__, ocotp_compat);
> +	}
>  
> +	if (!IS_ERR_OR_NULL(ocotp)) {
>  		if (__mxc_cpu_type == MXC_CPU_IMX7ULP) {
>  			regmap_read(ocotp, OCOTP_ULP_UID_4, &val);
>  			soc_uid = val & 0xffff;
>  			regmap_read(ocotp, OCOTP_ULP_UID_3, &val);
>  			soc_uid <<= 16;
> 

Tested-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>

Best regards,
Christoph
Shawn Guo Dec. 12, 2019, 2:44 a.m. UTC | #2
On Tue, Dec 10, 2019 at 11:49:28PM +0200, Leonard Crestez wrote:
> The imx_soc_device_init functions tries to fetch the ocotp regmap in
> order to soc serial number. If regmap fetch fails then a message is
> printed but regmap_read is called anyway and the system crashes.
> 
> Failing to lookup ocotp regmap shouldn't be a fatal boot error so check
> that the pointer is valid.
> 
> Only side-effect of ocotp lookup failure now is that serial number will
> be reported as all-zeros which is acceptable.
> 
> Cc: stable@vger.kernel.org
> Fixes: 8267ff89b713 ("ARM: imx: Add serial number support for i.MX6/7 SoCs")
> Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>

As this is a fix we want it in 5.5-rc, it should be generated against
5.5-rc1 rather than -next.  I rebased it and applied, thanks.

Shawn

Patch
diff mbox series

diff --git a/arch/arm/mach-imx/cpu.c b/arch/arm/mach-imx/cpu.c
index d70b6fc72b35..484bf6cdb363 100644
--- a/arch/arm/mach-imx/cpu.c
+++ b/arch/arm/mach-imx/cpu.c
@@ -87,11 +87,11 @@  struct device * __init imx_soc_device_init(void)
 {
 	struct soc_device_attribute *soc_dev_attr;
 	const char *ocotp_compat = NULL;
 	struct soc_device *soc_dev;
 	struct device_node *root;
-	struct regmap *ocotp;
+	struct regmap *ocotp = NULL;
 	const char *soc_id;
 	u64 soc_uid = 0;
 	u32 val;
 	int ret;
 
@@ -179,11 +179,13 @@  struct device * __init imx_soc_device_init(void)
 
 	if (ocotp_compat) {
 		ocotp = syscon_regmap_lookup_by_compatible(ocotp_compat);
 		if (IS_ERR(ocotp))
 			pr_err("%s: failed to find %s regmap!\n", __func__, ocotp_compat);
+	}
 
+	if (!IS_ERR_OR_NULL(ocotp)) {
 		if (__mxc_cpu_type == MXC_CPU_IMX7ULP) {
 			regmap_read(ocotp, OCOTP_ULP_UID_4, &val);
 			soc_uid = val & 0xffff;
 			regmap_read(ocotp, OCOTP_ULP_UID_3, &val);
 			soc_uid <<= 16;