diff mbox

ARM: omap_hwmod: Fix up resource names when booted with devicetree

Message ID 1345730049-12675-1-git-send-email-peter.ujfalusi@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Ujfalusi Aug. 23, 2012, 1:54 p.m. UTC
When booted with some resource will have their name set to NULL. This can
cause later kernel crash since this is not expected by the platform code.

When we boot without DT the devices are created with platform_device_add()
which itself fixes up the missing resource names:
if (r->name == NULL)
	r->name = dev_name(&pdev->dev);

The of core also fixes up the resource names when taking the information
from DT data - in __of_address_to_resource():
r->name = name ? name : dev->full_name;

When we boot OMAP with devicetree: of will create the devices based on the
DT data so the resource names are guarantied to be not NULL. Since we have
the 'ti,hwmod' tag, we remove the of created resources from the device and
re-create them based on hwmod data. If the hwmod data does not specify a
name for a resource it will be NULL.
This can cause kernel crash if the driver uses
platform_get_resource_byname() to get any resource.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 arch/arm/plat-omap/omap_device.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

Comments

Paul Walmsley Aug. 24, 2012, 3:38 p.m. UTC | #1
Hello Péter,

On Thu, 23 Aug 2012, Peter Ujfalusi wrote:

> When booted with some resource will have their name set to NULL. This can
> cause later kernel crash since this is not expected by the platform code.
> 
> When we boot without DT the devices are created with platform_device_add()
> which itself fixes up the missing resource names:
> if (r->name == NULL)
> 	r->name = dev_name(&pdev->dev);
> 
> The of core also fixes up the resource names when taking the information
> from DT data - in __of_address_to_resource():
> r->name = name ? name : dev->full_name;
> 
> When we boot OMAP with devicetree: of will create the devices based on the
> DT data so the resource names are guarantied to be not NULL. Since we have
> the 'ti,hwmod' tag, we remove the of created resources from the device and
> re-create them based on hwmod data. If the hwmod data does not specify a
> name for a resource it will be NULL.
> This can cause kernel crash if the driver uses
> platform_get_resource_byname() to get any resource.

Do we need both this one and your '[PATCH] driver core: Check if r->name 
is valid in platform_get_resource_byname()' ?  Or would that second patch 
be enough?  Is the crash happening in the platform_get_resource_byname() 
iterator?


- Paul
Peter Ujfalusi Aug. 24, 2012, 4:20 p.m. UTC | #2
Hi Paul,

On 08/24/2012 06:38 PM, Paul Walmsley wrote:
> Do we need both this one and your '[PATCH] driver core: Check if r->name 
> is valid in platform_get_resource_byname()' ?  Or would that second patch 
> be enough?  Is the crash happening in the platform_get_resource_byname() 
> iterator?

The crash happens in platform_get_resource_byname(). What I see as a problem
that when we boot without DT the r->name is configured for the hwmods. If we
boot with DT we discard the resources created by the OF (which also have the
r->name configured). We replace the resources from hwmods but we do not fix up
the resource names (which is done in other cases).
I have sent the patch for the drivers core as well since I think it is a good
practice anyway to check for NULL pointer before strcmp().

Either is good, but IMHO we should fix this in omap_hwmod (at least).
Benoit Cousson Sept. 5, 2012, 2:27 p.m. UTC | #3
Hi Paul,

On 08/24/2012 06:20 PM, Peter Ujfalusi wrote:
> Hi Paul,
> 
> On 08/24/2012 06:38 PM, Paul Walmsley wrote:
>> Do we need both this one and your '[PATCH] driver core: Check if r->name 
>> is valid in platform_get_resource_byname()' ?  Or would that second patch 
>> be enough?  Is the crash happening in the platform_get_resource_byname() 
>> iterator?
> 
> The crash happens in platform_get_resource_byname(). What I see as a problem
> that when we boot without DT the r->name is configured for the hwmods. If we
> boot with DT we discard the resources created by the OF (which also have the
> r->name configured). We replace the resources from hwmods but we do not fix up
> the resource names (which is done in other cases).
> I have sent the patch for the drivers core as well since I think it is a good
> practice anyway to check for NULL pointer before strcmp().
> 
> Either is good, but IMHO we should fix this in omap_hwmod (at least).

Yes, clearly we do have a corner case today due to the mix of hwmod /
DTS resource management.
- Legacy boot + hwmod resources is OK
- DTS boot with DTS resources will be OK
- DTS boot with hwmod resources is not OK since the resource name will
  not be populated in the case resources are not named :-(

If you are OK, I'll take that patch along with Vaibhav one to handle
properly the resources from DTS long with the DTS patches I'm queuing
for 3.7.

Thanks,
Benoit
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Benoit Cousson Sept. 5, 2012, 2:46 p.m. UTC | #4
Peter,

I will just slighty change the subject since it is a omap_device.c patch and not an omap_hwmod.c one.

ARM: OMAP: omap_device: Fix up resource names when booted with devicetree

Regards,
Benoit

On 09/05/2012 04:27 PM, Benoit Cousson wrote:
> Hi Paul,
> 
> On 08/24/2012 06:20 PM, Peter Ujfalusi wrote:
>> Hi Paul,
>>
>> On 08/24/2012 06:38 PM, Paul Walmsley wrote:
>>> Do we need both this one and your '[PATCH] driver core: Check if r->name 
>>> is valid in platform_get_resource_byname()' ?  Or would that second patch 
>>> be enough?  Is the crash happening in the platform_get_resource_byname() 
>>> iterator?
>>
>> The crash happens in platform_get_resource_byname(). What I see as a problem
>> that when we boot without DT the r->name is configured for the hwmods. If we
>> boot with DT we discard the resources created by the OF (which also have the
>> r->name configured). We replace the resources from hwmods but we do not fix up
>> the resource names (which is done in other cases).
>> I have sent the patch for the drivers core as well since I think it is a good
>> practice anyway to check for NULL pointer before strcmp().
>>
>> Either is good, but IMHO we should fix this in omap_hwmod (at least).
> 
> Yes, clearly we do have a corner case today due to the mix of hwmod /
> DTS resource management.
> - Legacy boot + hwmod resources is OK
> - DTS boot with DTS resources will be OK
> - DTS boot with hwmod resources is not OK since the resource name will
>   not be populated in the case resources are not named :-(
> 
> If you are OK, I'll take that patch along with Vaibhav one to handle
> properly the resources from DTS long with the DTS patches I'm queuing
> for 3.7.
> 
> Thanks,
> Benoit
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Benoit Cousson Sept. 5, 2012, 2:46 p.m. UTC | #5
Peter,

I will just slighty change the subject since it is an omap_device.c patch and not an omap_hwmod.c one.

ARM: OMAP: omap_device: Fix up resource names when booted with devicetree

Regards,
Benoit

On 09/05/2012 04:27 PM, Benoit Cousson wrote:
> Hi Paul,
> 
> On 08/24/2012 06:20 PM, Peter Ujfalusi wrote:
>> Hi Paul,
>>
>> On 08/24/2012 06:38 PM, Paul Walmsley wrote:
>>> Do we need both this one and your '[PATCH] driver core: Check if r->name 
>>> is valid in platform_get_resource_byname()' ?  Or would that second patch 
>>> be enough?  Is the crash happening in the platform_get_resource_byname() 
>>> iterator?
>>
>> The crash happens in platform_get_resource_byname(). What I see as a problem
>> that when we boot without DT the r->name is configured for the hwmods. If we
>> boot with DT we discard the resources created by the OF (which also have the
>> r->name configured). We replace the resources from hwmods but we do not fix up
>> the resource names (which is done in other cases).
>> I have sent the patch for the drivers core as well since I think it is a good
>> practice anyway to check for NULL pointer before strcmp().
>>
>> Either is good, but IMHO we should fix this in omap_hwmod (at least).
> 
> Yes, clearly we do have a corner case today due to the mix of hwmod /
> DTS resource management.
> - Legacy boot + hwmod resources is OK
> - DTS boot with DTS resources will be OK
> - DTS boot with hwmod resources is not OK since the resource name will
>   not be populated in the case resources are not named :-(
> 
> If you are OK, I'll take that patch along with Vaibhav one to handle
> properly the resources from DTS long with the DTS patches I'm queuing
> for 3.7.
> 
> Thanks,
> Benoit
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Vaibhav Hiremath Sept. 5, 2012, 8:05 p.m. UTC | #6
On 9/5/2012 7:57 PM, Benoit Cousson wrote:
> Hi Paul,
> 
> On 08/24/2012 06:20 PM, Peter Ujfalusi wrote:
>> Hi Paul,
>>
>> On 08/24/2012 06:38 PM, Paul Walmsley wrote:
>>> Do we need both this one and your '[PATCH] driver core: Check if r->name 
>>> is valid in platform_get_resource_byname()' ?  Or would that second patch 
>>> be enough?  Is the crash happening in the platform_get_resource_byname() 
>>> iterator?
>>
>> The crash happens in platform_get_resource_byname(). What I see as a problem
>> that when we boot without DT the r->name is configured for the hwmods. If we
>> boot with DT we discard the resources created by the OF (which also have the
>> r->name configured). We replace the resources from hwmods but we do not fix up
>> the resource names (which is done in other cases).
>> I have sent the patch for the drivers core as well since I think it is a good
>> practice anyway to check for NULL pointer before strcmp().
>>
>> Either is good, but IMHO we should fix this in omap_hwmod (at least).
> 
> Yes, clearly we do have a corner case today due to the mix of hwmod /
> DTS resource management.
> - Legacy boot + hwmod resources is OK
> - DTS boot with DTS resources will be OK
> - DTS boot with hwmod resources is not OK since the resource name will
>   not be populated in the case resources are not named :-(
> 
> If you are OK, I'll take that patch along with Vaibhav one to handle
> properly the resources from DTS long with the DTS patches I'm queuing
> for 3.7.
> 

Benoit,
Note that this patch will add device name to all resources, since none
of the resource will have name property and may break drivers;
especially after my patch which respects DT resources.

Also I just read the thread you started sometime back on _byname api,
not sure that was the conclusion, but it seems like it is not
recommended to use _byname. The driver should be fixed while converting
to DT.

http://lists.infradead.org/pipermail/linux-arm-kernel/2011-August/060861.html

Thanks,
Vaibhav

> Thanks,
> Benoit
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Benoit Cousson Sept. 6, 2012, 7:37 a.m. UTC | #7
Hi Vaibhav,

On 09/05/2012 10:05 PM, Vaibhav Hiremath wrote:
> On 9/5/2012 7:57 PM, Benoit Cousson wrote:
>> Hi Paul,
>>
>> On 08/24/2012 06:20 PM, Peter Ujfalusi wrote:
>>> Hi Paul,
>>>
>>> On 08/24/2012 06:38 PM, Paul Walmsley wrote:
>>>> Do we need both this one and your '[PATCH] driver core: Check if r->name 
>>>> is valid in platform_get_resource_byname()' ?  Or would that second patch 
>>>> be enough?  Is the crash happening in the platform_get_resource_byname() 
>>>> iterator?
>>>
>>> The crash happens in platform_get_resource_byname(). What I see as a problem
>>> that when we boot without DT the r->name is configured for the hwmods. If we
>>> boot with DT we discard the resources created by the OF (which also have the
>>> r->name configured). We replace the resources from hwmods but we do not fix up
>>> the resource names (which is done in other cases).
>>> I have sent the patch for the drivers core as well since I think it is a good
>>> practice anyway to check for NULL pointer before strcmp().
>>>
>>> Either is good, but IMHO we should fix this in omap_hwmod (at least).
>>
>> Yes, clearly we do have a corner case today due to the mix of hwmod /
>> DTS resource management.
>> - Legacy boot + hwmod resources is OK
>> - DTS boot with DTS resources will be OK
>> - DTS boot with hwmod resources is not OK since the resource name will
>>   not be populated in the case resources are not named :-(
>>
>> If you are OK, I'll take that patch along with Vaibhav one to handle
>> properly the resources from DTS long with the DTS patches I'm queuing
>> for 3.7.
>>
> 
> Benoit,
> Note that this patch will add device name to all resources, since none
> of the resource will have name property and may break drivers;
> especially after my patch which respects DT resources.

So you do have to add the name in the DTS if the driver is expecting that.

> Also I just read the thread you started sometime back on _byname api,
> not sure that was the conclusion, but it seems like it is not
> recommended to use _byname. The driver should be fixed while converting
> to DT.

No the DT name for reg and interrupt was accepted and Peter is taking advantage on that.
The only missing binding is the DMA now.

Here is what Peter did.

 			compatible = "ti,omap4-mcpdm";
 			reg = <0x40132000 0x7f>, /* MPU private access */
 			      <0x49032000 0x7f>; /* L3 Interconnect */
+			reg-names = "mpu", "dma";
 			interrupts = <0 112 0x4>;
 			interrupt-parent = <&gic>;
 			ti,hwmods = "mcpdm";


Regards,
Benoit

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Vaibhav Hiremath Sept. 6, 2012, 8:28 a.m. UTC | #8
On Thu, Sep 06, 2012 at 13:07:29, Cousson, Benoit wrote:
> Hi Vaibhav,
> 
> On 09/05/2012 10:05 PM, Vaibhav Hiremath wrote:
> > On 9/5/2012 7:57 PM, Benoit Cousson wrote:
> >> Hi Paul,
> >>
> >> On 08/24/2012 06:20 PM, Peter Ujfalusi wrote:
> >>> Hi Paul,
> >>>
> >>> On 08/24/2012 06:38 PM, Paul Walmsley wrote:
> >>>> Do we need both this one and your '[PATCH] driver core: Check if r->name 
> >>>> is valid in platform_get_resource_byname()' ?  Or would that second patch 
> >>>> be enough?  Is the crash happening in the platform_get_resource_byname() 
> >>>> iterator?
> >>>
> >>> The crash happens in platform_get_resource_byname(). What I see as a problem
> >>> that when we boot without DT the r->name is configured for the hwmods. If we
> >>> boot with DT we discard the resources created by the OF (which also have the
> >>> r->name configured). We replace the resources from hwmods but we do not fix up
> >>> the resource names (which is done in other cases).
> >>> I have sent the patch for the drivers core as well since I think it is a good
> >>> practice anyway to check for NULL pointer before strcmp().
> >>>
> >>> Either is good, but IMHO we should fix this in omap_hwmod (at least).
> >>
> >> Yes, clearly we do have a corner case today due to the mix of hwmod /
> >> DTS resource management.
> >> - Legacy boot + hwmod resources is OK
> >> - DTS boot with DTS resources will be OK
> >> - DTS boot with hwmod resources is not OK since the resource name will
> >>   not be populated in the case resources are not named :-(
> >>
> >> If you are OK, I'll take that patch along with Vaibhav one to handle
> >> properly the resources from DTS long with the DTS patches I'm queuing
> >> for 3.7.
> >>
> > 
> > Benoit,
> > Note that this patch will add device name to all resources, since none
> > of the resource will have name property and may break drivers;
> > especially after my patch which respects DT resources.
> 
> So you do have to add the name in the DTS if the driver is expecting that.
> 
> > Also I just read the thread you started sometime back on _byname api,
> > not sure that was the conclusion, but it seems like it is not
> > recommended to use _byname. The driver should be fixed while converting
> > to DT.
> 
> No the DT name for reg and interrupt was accepted and Peter is taking advantage on that.
> The only missing binding is the DMA now.
> 
> Here is what Peter did.
> 
>  			compatible = "ti,omap4-mcpdm";
>  			reg = <0x40132000 0x7f>, /* MPU private access */
>  			      <0x49032000 0x7f>; /* L3 Interconnect */
> +			reg-names = "mpu", "dma";
>  			interrupts = <0 112 0x4>;
>  			interrupt-parent = <&gic>;
>  			ti,hwmods = "mcpdm";
> 

Thanks for sharing this and now I found it in 
Documentation/devicetree/bindings/resource-names.txt

In that case, we do not have any issues and you can merge this patch.

Thanks,
Vaibhav
> 
> Regards,
> Benoit
> 
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" 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/arch/arm/plat-omap/omap_device.c b/arch/arm/plat-omap/omap_device.c
index c490240..ff57b5a 100644
--- a/arch/arm/plat-omap/omap_device.c
+++ b/arch/arm/plat-omap/omap_device.c
@@ -370,6 +370,14 @@  static int omap_device_build_from_dt(struct platform_device *pdev)
 		goto odbfd_exit1;
 	}
 
+	/* Fix up missing resource names */
+	for (i = 0; i < pdev->num_resources; i++) {
+		struct resource *r = &pdev->resource[i];
+
+		if (r->name == NULL)
+			r->name = dev_name(&pdev->dev);
+	}
+
 	if (of_get_property(node, "ti,no_idle_on_suspend", NULL))
 		omap_device_disable_idle_on_suspend(pdev);