All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: rawnand: Fix probe failure due to of_get_nand_secure_regions()
@ 2021-07-27  6:28 ` Manivannan Sadhasivam
  0 siblings, 0 replies; 6+ messages in thread
From: Manivannan Sadhasivam @ 2021-07-27  6:28 UTC (permalink / raw)
  To: miquel.raynal
  Cc: richard, vigneshr, boris.brezillon, tudor.ambarus, linux-mtd,
	linux-kernel, dan.carpenter, martin, Manivannan Sadhasivam

Due to 14f97f0b8e2b, the rawnand platforms without "secure-regions"
property defined in DT fails to probe. The issue is,
of_get_nand_secure_regions() errors out if
of_property_count_elems_of_size() returns a negative error code.

If the "secure-regions" property is not present in DT, then also we'll
get -EINVAL from of_property_count_elems_of_size() but it should not
be treated as an error for platforms not declaring "secure-regions"
in DT.

So fix this behaviour by checking for the existence of that property in
DT and return 0 if it is not present.

Fixes: 14f97f0b8e2b ("mtd: rawnand: Add a check in of_get_nand_secure_regions()")
Reported-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/mtd/nand/raw/nand_base.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index cbba46432e39..3d6c6e880520 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -5228,8 +5228,14 @@ static bool of_get_nand_on_flash_bbt(struct device_node *np)
 static int of_get_nand_secure_regions(struct nand_chip *chip)
 {
 	struct device_node *dn = nand_get_flash_node(chip);
+	struct property *prop;
 	int nr_elem, i, j;
 
+	/* Only proceed if the "secure-regions" property is present in DT */
+	prop = of_find_property(dn, "secure-regions", NULL);
+	if (!prop)
+		return 0;
+
 	nr_elem = of_property_count_elems_of_size(dn, "secure-regions", sizeof(u64));
 	if (nr_elem <= 0)
 		return nr_elem;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] mtd: rawnand: Fix probe failure due to of_get_nand_secure_regions()
@ 2021-07-27  6:28 ` Manivannan Sadhasivam
  0 siblings, 0 replies; 6+ messages in thread
From: Manivannan Sadhasivam @ 2021-07-27  6:28 UTC (permalink / raw)
  To: miquel.raynal
  Cc: richard, vigneshr, boris.brezillon, tudor.ambarus, linux-mtd,
	linux-kernel, dan.carpenter, martin, Manivannan Sadhasivam

Due to 14f97f0b8e2b, the rawnand platforms without "secure-regions"
property defined in DT fails to probe. The issue is,
of_get_nand_secure_regions() errors out if
of_property_count_elems_of_size() returns a negative error code.

If the "secure-regions" property is not present in DT, then also we'll
get -EINVAL from of_property_count_elems_of_size() but it should not
be treated as an error for platforms not declaring "secure-regions"
in DT.

So fix this behaviour by checking for the existence of that property in
DT and return 0 if it is not present.

Fixes: 14f97f0b8e2b ("mtd: rawnand: Add a check in of_get_nand_secure_regions()")
Reported-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/mtd/nand/raw/nand_base.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index cbba46432e39..3d6c6e880520 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -5228,8 +5228,14 @@ static bool of_get_nand_on_flash_bbt(struct device_node *np)
 static int of_get_nand_secure_regions(struct nand_chip *chip)
 {
 	struct device_node *dn = nand_get_flash_node(chip);
+	struct property *prop;
 	int nr_elem, i, j;
 
+	/* Only proceed if the "secure-regions" property is present in DT */
+	prop = of_find_property(dn, "secure-regions", NULL);
+	if (!prop)
+		return 0;
+
 	nr_elem = of_property_count_elems_of_size(dn, "secure-regions", sizeof(u64));
 	if (nr_elem <= 0)
 		return nr_elem;
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] mtd: rawnand: Fix probe failure due to of_get_nand_secure_regions()
  2021-07-27  6:28 ` Manivannan Sadhasivam
@ 2021-07-27 16:13   ` Martin Kaiser
  -1 siblings, 0 replies; 6+ messages in thread
From: Martin Kaiser @ 2021-07-27 16:13 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: miquel.raynal, richard, vigneshr, boris.brezillon, tudor.ambarus,
	linux-mtd, linux-kernel, dan.carpenter

Hi Mani and all,

Thus wrote Manivannan Sadhasivam (manivannan.sadhasivam@linaro.org):

> Due to 14f97f0b8e2b, the rawnand platforms without "secure-regions"
> property defined in DT fails to probe. The issue is,
> of_get_nand_secure_regions() errors out if
> of_property_count_elems_of_size() returns a negative error code.

> If the "secure-regions" property is not present in DT, then also we'll
> get -EINVAL from of_property_count_elems_of_size() but it should not
> be treated as an error for platforms not declaring "secure-regions"
> in DT.

> So fix this behaviour by checking for the existence of that property in
> DT and return 0 if it is not present.

> Fixes: 14f97f0b8e2b ("mtd: rawnand: Add a check in of_get_nand_secure_regions()")
> Reported-by: Martin Kaiser <martin@kaiser.cx>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
>  drivers/mtd/nand/raw/nand_base.c | 6 ++++++
>  1 file changed, 6 insertions(+)

> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> index cbba46432e39..3d6c6e880520 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -5228,8 +5228,14 @@ static bool of_get_nand_on_flash_bbt(struct device_node *np)
>  static int of_get_nand_secure_regions(struct nand_chip *chip)
>  {
>  	struct device_node *dn = nand_get_flash_node(chip);
> +	struct property *prop;
>  	int nr_elem, i, j;

> +	/* Only proceed if the "secure-regions" property is present in DT */
> +	prop = of_find_property(dn, "secure-regions", NULL);
> +	if (!prop)
> +		return 0;
> +
>  	nr_elem = of_property_count_elems_of_size(dn, "secure-regions", sizeof(u64));
>  	if (nr_elem <= 0)
>  		return nr_elem;
> -- 
> 2.25.1

not surprisingly, this fixes the issue for me.

Reviewed-by: Martin Kaiser <martin@kaiser.cx>
Tested-by: Martin Kaiser <martin@kaiser.cx>

Still, I was wondering if the behaviour of of_property_count_elems_of_size
makes sense. Without a prior check, there's no chance for the caller to
distinguish between "property is absent" and "property is malformed". 

Thanks,
Martin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mtd: rawnand: Fix probe failure due to of_get_nand_secure_regions()
@ 2021-07-27 16:13   ` Martin Kaiser
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Kaiser @ 2021-07-27 16:13 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: miquel.raynal, richard, vigneshr, boris.brezillon, tudor.ambarus,
	linux-mtd, linux-kernel, dan.carpenter

Hi Mani and all,

Thus wrote Manivannan Sadhasivam (manivannan.sadhasivam@linaro.org):

> Due to 14f97f0b8e2b, the rawnand platforms without "secure-regions"
> property defined in DT fails to probe. The issue is,
> of_get_nand_secure_regions() errors out if
> of_property_count_elems_of_size() returns a negative error code.

> If the "secure-regions" property is not present in DT, then also we'll
> get -EINVAL from of_property_count_elems_of_size() but it should not
> be treated as an error for platforms not declaring "secure-regions"
> in DT.

> So fix this behaviour by checking for the existence of that property in
> DT and return 0 if it is not present.

> Fixes: 14f97f0b8e2b ("mtd: rawnand: Add a check in of_get_nand_secure_regions()")
> Reported-by: Martin Kaiser <martin@kaiser.cx>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
>  drivers/mtd/nand/raw/nand_base.c | 6 ++++++
>  1 file changed, 6 insertions(+)

> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> index cbba46432e39..3d6c6e880520 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -5228,8 +5228,14 @@ static bool of_get_nand_on_flash_bbt(struct device_node *np)
>  static int of_get_nand_secure_regions(struct nand_chip *chip)
>  {
>  	struct device_node *dn = nand_get_flash_node(chip);
> +	struct property *prop;
>  	int nr_elem, i, j;

> +	/* Only proceed if the "secure-regions" property is present in DT */
> +	prop = of_find_property(dn, "secure-regions", NULL);
> +	if (!prop)
> +		return 0;
> +
>  	nr_elem = of_property_count_elems_of_size(dn, "secure-regions", sizeof(u64));
>  	if (nr_elem <= 0)
>  		return nr_elem;
> -- 
> 2.25.1

not surprisingly, this fixes the issue for me.

Reviewed-by: Martin Kaiser <martin@kaiser.cx>
Tested-by: Martin Kaiser <martin@kaiser.cx>

Still, I was wondering if the behaviour of of_property_count_elems_of_size
makes sense. Without a prior check, there's no chance for the caller to
distinguish between "property is absent" and "property is malformed". 

Thanks,
Martin

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mtd: rawnand: Fix probe failure due to of_get_nand_secure_regions()
  2021-07-27  6:28 ` Manivannan Sadhasivam
@ 2021-08-06 19:45   ` Miquel Raynal
  -1 siblings, 0 replies; 6+ messages in thread
From: Miquel Raynal @ 2021-08-06 19:45 UTC (permalink / raw)
  To: Manivannan Sadhasivam, miquel.raynal
  Cc: richard, vigneshr, boris.brezillon, tudor.ambarus, linux-mtd,
	linux-kernel, dan.carpenter, martin

On Tue, 2021-07-27 at 06:28:13 UTC, Manivannan Sadhasivam wrote:
> Due to 14f97f0b8e2b, the rawnand platforms without "secure-regions"
> property defined in DT fails to probe. The issue is,
> of_get_nand_secure_regions() errors out if
> of_property_count_elems_of_size() returns a negative error code.
> 
> If the "secure-regions" property is not present in DT, then also we'll
> get -EINVAL from of_property_count_elems_of_size() but it should not
> be treated as an error for platforms not declaring "secure-regions"
> in DT.
> 
> So fix this behaviour by checking for the existence of that property in
> DT and return 0 if it is not present.
> 
> Fixes: 14f97f0b8e2b ("mtd: rawnand: Add a check in of_get_nand_secure_regions()")
> Reported-by: Martin Kaiser <martin@kaiser.cx>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> Reviewed-by: Martin Kaiser <martin@kaiser.cx>
> Tested-by: Martin Kaiser <martin@kaiser.cx>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes, thanks.

Miquel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mtd: rawnand: Fix probe failure due to of_get_nand_secure_regions()
@ 2021-08-06 19:45   ` Miquel Raynal
  0 siblings, 0 replies; 6+ messages in thread
From: Miquel Raynal @ 2021-08-06 19:45 UTC (permalink / raw)
  To: Manivannan Sadhasivam, miquel.raynal
  Cc: richard, vigneshr, boris.brezillon, tudor.ambarus, linux-mtd,
	linux-kernel, dan.carpenter, martin

On Tue, 2021-07-27 at 06:28:13 UTC, Manivannan Sadhasivam wrote:
> Due to 14f97f0b8e2b, the rawnand platforms without "secure-regions"
> property defined in DT fails to probe. The issue is,
> of_get_nand_secure_regions() errors out if
> of_property_count_elems_of_size() returns a negative error code.
> 
> If the "secure-regions" property is not present in DT, then also we'll
> get -EINVAL from of_property_count_elems_of_size() but it should not
> be treated as an error for platforms not declaring "secure-regions"
> in DT.
> 
> So fix this behaviour by checking for the existence of that property in
> DT and return 0 if it is not present.
> 
> Fixes: 14f97f0b8e2b ("mtd: rawnand: Add a check in of_get_nand_secure_regions()")
> Reported-by: Martin Kaiser <martin@kaiser.cx>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> Reviewed-by: Martin Kaiser <martin@kaiser.cx>
> Tested-by: Martin Kaiser <martin@kaiser.cx>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-08-06 19:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-27  6:28 [PATCH] mtd: rawnand: Fix probe failure due to of_get_nand_secure_regions() Manivannan Sadhasivam
2021-07-27  6:28 ` Manivannan Sadhasivam
2021-07-27 16:13 ` Martin Kaiser
2021-07-27 16:13   ` Martin Kaiser
2021-08-06 19:45 ` Miquel Raynal
2021-08-06 19:45   ` Miquel Raynal

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.