diff mbox

[1/5] ARM: tegra: WARN if flowctrl is not supported

Message ID 1489584715-23138-2-git-send-email-jonathanh@nvidia.com
State Superseded
Headers show

Commit Message

Jon Hunter March 15, 2017, 1:31 p.m. UTC
If we fail to map the IO space for the Tegra flowctrl module in
tegra_flowctrl_init(), then if any of the public APIs for the Tegra
flowctrl driver are called we still still attempt to access the
hardware. Fix this by only accessing the hardware if the
'tegra_flowctrl_base' address has not been setup correctly and warn
if we attempt to access the hardware when it has not.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
---
 arch/arm/mach-tegra/flowctrl.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Thierry Reding March 20, 2017, 2:10 p.m. UTC | #1
On Wed, Mar 15, 2017 at 01:31:51PM +0000, Jon Hunter wrote:
> If we fail to map the IO space for the Tegra flowctrl module in
> tegra_flowctrl_init(), then if any of the public APIs for the Tegra
> flowctrl driver are called we still still attempt to access the
> hardware. Fix this by only accessing the hardware if the
> 'tegra_flowctrl_base' address has not been setup correctly and warn
> if we attempt to access the hardware when it has not.
> 
> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> ---
>  arch/arm/mach-tegra/flowctrl.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/arch/arm/mach-tegra/flowctrl.c b/arch/arm/mach-tegra/flowctrl.c
> index 475e783992fd..40b15e39f849 100644
> --- a/arch/arm/mach-tegra/flowctrl.c
> +++ b/arch/arm/mach-tegra/flowctrl.c
> @@ -47,6 +47,9 @@ static void __iomem *tegra_flowctrl_base;
>  
>  static void flowctrl_update(u8 offset, u32 value)
>  {
> +	if (WARN_ONCE(!tegra_flowctrl_base, "Tegra flowctrl not supported!"))

Technically I think this string needs a terminating "\n" because it is
eventually passed to printk(), even though the WARN_ONCE() will probably
format the output correctly even without it.

Also, "not supported" isn't a very accurate description. This has to do
with the flow controller not having been initialized yet.

Thierry
Jon Hunter March 20, 2017, 4:32 p.m. UTC | #2
On 20/03/17 14:10, Thierry Reding wrote:
> * PGP Signed by an unknown key
> 
> On Wed, Mar 15, 2017 at 01:31:51PM +0000, Jon Hunter wrote:
>> If we fail to map the IO space for the Tegra flowctrl module in
>> tegra_flowctrl_init(), then if any of the public APIs for the Tegra
>> flowctrl driver are called we still still attempt to access the
>> hardware. Fix this by only accessing the hardware if the
>> 'tegra_flowctrl_base' address has not been setup correctly and warn
>> if we attempt to access the hardware when it has not.
>>
>> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
>> ---
>>  arch/arm/mach-tegra/flowctrl.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/arch/arm/mach-tegra/flowctrl.c b/arch/arm/mach-tegra/flowctrl.c
>> index 475e783992fd..40b15e39f849 100644
>> --- a/arch/arm/mach-tegra/flowctrl.c
>> +++ b/arch/arm/mach-tegra/flowctrl.c
>> @@ -47,6 +47,9 @@ static void __iomem *tegra_flowctrl_base;
>>  
>>  static void flowctrl_update(u8 offset, u32 value)
>>  {
>> +	if (WARN_ONCE(!tegra_flowctrl_base, "Tegra flowctrl not supported!"))
> 
> Technically I think this string needs a terminating "\n" because it is
> eventually passed to printk(), even though the WARN_ONCE() will probably
> format the output correctly even without it.

Yes, will fix up.

> Also, "not supported" isn't a very accurate description. This has to do
> with the flow controller not having been initialized yet.

Will update to 'not initialised'.

Jon
diff mbox

Patch

diff --git a/arch/arm/mach-tegra/flowctrl.c b/arch/arm/mach-tegra/flowctrl.c
index 475e783992fd..40b15e39f849 100644
--- a/arch/arm/mach-tegra/flowctrl.c
+++ b/arch/arm/mach-tegra/flowctrl.c
@@ -47,6 +47,9 @@  static void __iomem *tegra_flowctrl_base;
 
 static void flowctrl_update(u8 offset, u32 value)
 {
+	if (WARN_ONCE(!tegra_flowctrl_base, "Tegra flowctrl not supported!"))
+		return;
+
 	writel(value, tegra_flowctrl_base + offset);
 
 	/* ensure the update has reached the flow controller */
@@ -58,6 +61,9 @@  u32 flowctrl_read_cpu_csr(unsigned int cpuid)
 {
 	u8 offset = flowctrl_offset_cpu_csr[cpuid];
 
+	if (WARN_ONCE(!tegra_flowctrl_base, "Tegra flowctrl not supported!"))
+		return 0;
+
 	return readl(tegra_flowctrl_base + offset);
 }