diff mbox

TESTCASE: of: OOPS when disabling node via OF_DYNAMIC

Message ID 20150607111632.CC7A4C410F0@trevor.secretlab.ca (mailing list archive)
State Not Applicable
Headers show

Commit Message

Grant Likely June 7, 2015, 11:16 a.m. UTC
On Wed, 22 Apr 2015 15:30:28 +0300
, Pantelis Antoniou <pantelis.antoniou@konsulko.com>
 wrote:
> Hi Wolfram,
> 
> > On Apr 14, 2015, at 16:27 , Wolfram Sang <wsa@the-dreams.de> wrote:
> > 
> > Hi Pantelis,
> > 
> > thanks for your prompt reply. Unfortunately, I had to wait until I could
> > access the test system again.
> > 
> 
> [snip]
> 
> Sorry for the non-prompt reply; but just for kicks, can you try the attached patch?
> 
> I have a hunch this might be the problem.
> 
> Regards
> 
> — Pantelis
> 
> 

I played around with this some today. If I'm reading it correctly, the
following patch reproduces the same problem:

(continued below patch)
---

--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Laurent Pinchart June 9, 2015, 4:50 p.m. UTC | #1
Hi Grant,

On Sunday 07 June 2015 12:16:32 Grant Likely wrote:
> On Wed, 22 Apr 2015 15:30:28 +0300, Pantelis Antoniou wrote:
> > > On Apr 14, 2015, at 16:27 , Wolfram Sang <wsa@the-dreams.de> wrote:
> > > 
> > > Hi Pantelis,
> > > 
> > > thanks for your prompt reply. Unfortunately, I had to wait until I could
> > > access the test system again.
> > 
> > [snip]
> > 
> > Sorry for the non-prompt reply; but just for kicks, can you try the
> > attached patch?
> > 
> > I have a hunch this might be the problem.
> > 
> > Regards
> > 
> > â?? Pantelis
> 
> I played around with this some today. If I'm reading it correctly, the
> following patch reproduces the same problem:
> 
> (continued below patch)
> ---
> diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
> index 18016341d5a9..0a27b38c3041 100644
> --- a/drivers/of/unittest.c
> +++ b/drivers/of/unittest.c
> @@ -753,6 +753,11 @@ static void __init of_unittest_match_node(void)
>  	}
>  }
> 
> +static struct resource test_bus_res = {
> +	.start = 0xfffffff8,
> +	.end = 0xfffffff9,
> +	.flags = IORESOURCE_MEM,
> +};
>  static const struct platform_device_info test_bus_info = {
>  	.name = "unittest-bus",
>  };
> @@ -795,6 +800,7 @@ static void __init of_unittest_platform_populate(void)
>  	if (rc)
>  		return;
>  	test_bus->dev.of_node = np;
> +	platform_device_add_resources(test_bus, &test_bus_res, 1);
> 
>  	of_platform_populate(np, match, NULL, &test_bus->dev);
>  	for_each_child_of_node(np, child) {
> 
> ---
> 
> I think the fixup patch boils down to the following. It's hard to tell
> because it combines refactoring with the bug fix. Do I have it correct?
> If so, I'd rather commit the simple fix which can be committed now for
> v4.1, and the refactoring can be pushed for v4.2

The patch below looks equivalent to Pantelis' patch if we remove the 
refactoring, but I don't immediately see how r->parent can be NULL in 
platform_device_del() if type is equal to IORESOURCE_MEM or IORESOURCE_IO, as 
platform_device_add() will have called insert_resource() in those cases, which 
should set the resource parent pointer. I must be missing something as the 
patch fixes Wolfram's issue, so an explanation in the commit message would be 
welcome.

> ---
> 
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index ebf034b97278..b3042e6ee3ef 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -377,7 +377,7 @@ int platform_device_add(struct platform_device *pdev)
>  		struct resource *r = &pdev->resource[i];
>  		unsigned long type = resource_type(r);
> 
> -		if (type == IORESOURCE_MEM || type == IORESOURCE_IO)
> +		if (r->parent)
>  			release_resource(r);
>  	}
> 
> @@ -410,7 +410,7 @@ void platform_device_del(struct platform_device *pdev)
>  			struct resource *r = &pdev->resource[i];
>  			unsigned long type = resource_type(r);
> 
> -			if (type == IORESOURCE_MEM || type == IORESOURCE_IO)
> +			if (r->parent)
>  				release_resource(r);
>  		}
>  	}
Grant Likely June 10, 2015, 4:53 p.m. UTC | #2
On Tue, 09 Jun 2015 19:50:26 +0300
, Laurent Pinchart <laurent.pinchart@ideasonboard.com>
 wrote:
> Hi Grant,
> 
> On Sunday 07 June 2015 12:16:32 Grant Likely wrote:
> > On Wed, 22 Apr 2015 15:30:28 +0300, Pantelis Antoniou wrote:
> > > > On Apr 14, 2015, at 16:27 , Wolfram Sang <wsa@the-dreams.de> wrote:
> > > > 
> > > > Hi Pantelis,
> > > > 
> > > > thanks for your prompt reply. Unfortunately, I had to wait until I could
> > > > access the test system again.
> > > 
> > > [snip]
> > > 
> > > Sorry for the non-prompt reply; but just for kicks, can you try the
> > > attached patch?
> > > 
> > > I have a hunch this might be the problem.
> > > 
> > > Regards
> > > 
> > > â?? Pantelis
> > 
> > I played around with this some today. If I'm reading it correctly, the
> > following patch reproduces the same problem:
> > 
> > (continued below patch)
> > ---
> > diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
> > index 18016341d5a9..0a27b38c3041 100644
> > --- a/drivers/of/unittest.c
> > +++ b/drivers/of/unittest.c
> > @@ -753,6 +753,11 @@ static void __init of_unittest_match_node(void)
> >  	}
> >  }
> > 
> > +static struct resource test_bus_res = {
> > +	.start = 0xfffffff8,
> > +	.end = 0xfffffff9,
> > +	.flags = IORESOURCE_MEM,
> > +};
> >  static const struct platform_device_info test_bus_info = {
> >  	.name = "unittest-bus",
> >  };
> > @@ -795,6 +800,7 @@ static void __init of_unittest_platform_populate(void)
> >  	if (rc)
> >  		return;
> >  	test_bus->dev.of_node = np;
> > +	platform_device_add_resources(test_bus, &test_bus_res, 1);
> > 
> >  	of_platform_populate(np, match, NULL, &test_bus->dev);
> >  	for_each_child_of_node(np, child) {
> > 
> > ---
> > 
> > I think the fixup patch boils down to the following. It's hard to tell
> > because it combines refactoring with the bug fix. Do I have it correct?
> > If so, I'd rather commit the simple fix which can be committed now for
> > v4.1, and the refactoring can be pushed for v4.2
> 
> The patch below looks equivalent to Pantelis' patch if we remove the 
> refactoring, but I don't immediately see how r->parent can be NULL in 
> platform_device_del() if type is equal to IORESOURCE_MEM or IORESOURCE_IO, as 
> platform_device_add() will have called insert_resource() in those cases, which 
> should set the resource parent pointer. I must be missing something as the 
> patch fixes Wolfram's issue, so an explanation in the commit message would be 
> welcome.

of_platform_populate() adds platform devices via of_device_add().
of_device_add() doesn't add the resources because there are platforms
that break due to nodes with overlapping resources.

g.
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pantelis Antoniou June 11, 2015, 11:14 a.m. UTC | #3
Hi Grant,

> On Jun 7, 2015, at 14:16 , Grant Likely <grant.likely@secretlab.ca> wrote:
> 
> On Wed, 22 Apr 2015 15:30:28 +0300
> , Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> wrote:
>> Hi Wolfram,
>> 
>>> On Apr 14, 2015, at 16:27 , Wolfram Sang <wsa@the-dreams.de> wrote:
>>> 
>>> Hi Pantelis,
>>> 
>>> thanks for your prompt reply. Unfortunately, I had to wait until I could
>>> access the test system again.
>>> 
>> 
>> [snip]
>> 
>> Sorry for the non-prompt reply; but just for kicks, can you try the attached patch?
>> 
>> I have a hunch this might be the problem.
>> 
>> Regards
>> 
>> — Pantelis
>> 
>> 
> 
> I played around with this some today. If I'm reading it correctly, the
> following patch reproduces the same problem:
> 
> (continued below patch)
> ---
> diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
> index 18016341d5a9..0a27b38c3041 100644
> --- a/drivers/of/unittest.c
> +++ b/drivers/of/unittest.c
> @@ -753,6 +753,11 @@ static void __init of_unittest_match_node(void)
> 	}
> }
> 
> +static struct resource test_bus_res = {
> +	.start = 0xfffffff8,
> +	.end = 0xfffffff9,
> +	.flags = IORESOURCE_MEM,
> +};
> static const struct platform_device_info test_bus_info = {
> 	.name = "unittest-bus",
> };
> @@ -795,6 +800,7 @@ static void __init of_unittest_platform_populate(void)
> 	if (rc)
> 		return;
> 	test_bus->dev.of_node = np;
> +	platform_device_add_resources(test_bus, &test_bus_res, 1);
> 
> 	of_platform_populate(np, match, NULL, &test_bus->dev);
> 	for_each_child_of_node(np, child) {
> 
> ---
> 
> I think the fixup patch boils down to the following. It's hard to tell
> because it combines refactoring with the bug fix. Do I have it correct?
> If so, I'd rather commit the simple fix which can be committed now for
> v4.1, and the refactoring can be pushed for v4.2
> 
> ---
> 
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index ebf034b97278..b3042e6ee3ef 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -377,7 +377,7 @@ int platform_device_add(struct platform_device *pdev)
> 		struct resource *r = &pdev->resource[i];
> 		unsigned long type = resource_type(r);
> 
> -		if (type == IORESOURCE_MEM || type == IORESOURCE_IO)
> +		if (r->parent)
> 			release_resource(r);
> 	}
> 
> @@ -410,7 +410,7 @@ void platform_device_del(struct platform_device *pdev)
> 			struct resource *r = &pdev->resource[i];
> 			unsigned long type = resource_type(r);
> 
> -			if (type == IORESOURCE_MEM || type == IORESOURCE_IO)
> +			if (r->parent)
> 				release_resource(r);
> 		}
> 	}
> 

Verified. No crashes.

Acked-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 18016341d5a9..0a27b38c3041 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -753,6 +753,11 @@  static void __init of_unittest_match_node(void)
 	}
 }
 
+static struct resource test_bus_res = {
+	.start = 0xfffffff8,
+	.end = 0xfffffff9,
+	.flags = IORESOURCE_MEM,
+};
 static const struct platform_device_info test_bus_info = {
 	.name = "unittest-bus",
 };
@@ -795,6 +800,7 @@  static void __init of_unittest_platform_populate(void)
 	if (rc)
 		return;
 	test_bus->dev.of_node = np;
+	platform_device_add_resources(test_bus, &test_bus_res, 1);
 
 	of_platform_populate(np, match, NULL, &test_bus->dev);
 	for_each_child_of_node(np, child) {

---

I think the fixup patch boils down to the following. It's hard to tell
because it combines refactoring with the bug fix. Do I have it correct?
If so, I'd rather commit the simple fix which can be committed now for
v4.1, and the refactoring can be pushed for v4.2

---

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index ebf034b97278..b3042e6ee3ef 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -377,7 +377,7 @@  int platform_device_add(struct platform_device *pdev)
 		struct resource *r = &pdev->resource[i];
 		unsigned long type = resource_type(r);
 
-		if (type == IORESOURCE_MEM || type == IORESOURCE_IO)
+		if (r->parent)
 			release_resource(r);
 	}
 
@@ -410,7 +410,7 @@  void platform_device_del(struct platform_device *pdev)
 			struct resource *r = &pdev->resource[i];
 			unsigned long type = resource_type(r);
 
-			if (type == IORESOURCE_MEM || type == IORESOURCE_IO)
+			if (r->parent)
 				release_resource(r);
 		}
 	}