Skip to contentSkip to conversation

clk: xgene: Don't call __pa on ioremaped address

PATCH Applied Laura Abbott 3 participants 5 messages Oct 28, 2016 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 clk: xgene: Don't call __pa on ioremaped address

ioremaped addresses are not linearly mapped so the physical address can not be figured out via __pa. More generally, there is no guarantee that backing value of an ioremapped address is a physical address at all. The value here is only used for debugging so just drop the call to __pa on the ioremapped address.

Fixes 6ae5fd381251 ("clk: xgene: Silence sparse warnings")

---
v2: Fix up one more format string

I put the fixes tag to match with the cleanup that was done. If there is interest in this fix for pre-4.2 kernels for stable, I can submit a patch for that as well.

---
 drivers/clk/clk-xgene.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/clk/clk-xgene.c +4 -6
index 3433132..1e67655 100644
@@ -243,22 +243,20 @@ static int xgene_clk_enable(struct clk_hw *hw)
 	struct xgene_clk *pclk = to_xgene_clk(hw);
 	unsigned long flags = 0;
 	u32 data;
-	phys_addr_t reg;
 
 	if (pclk->lock)
 		spin_lock_irqsave(pclk->lock, flags);
 
 	if (pclk->param.csr_reg != NULL) {
 		pr_debug("%s clock enabled\n", clk_hw_get_name(hw));
-		reg = __pa(pclk->param.csr_reg);
 		/* First enable the clock */
 		data = xgene_clk_read(pclk->param.csr_reg +
 					pclk->param.reg_clk_offset);
 		data |= pclk->param.reg_clk_mask;
 		xgene_clk_write(data, pclk->param.csr_reg +
 					pclk->param.reg_clk_offset);
-		pr_debug("%s clock PADDR base %pa clk offset 0x%08X mask 0x%08X value 0x%08X\n",
-			clk_hw_get_name(hw), &reg,
+		pr_debug("%s clk offset 0x%08X mask 0x%08X value 0x%08X\n",
+			clk_hw_get_name(hw),
 			pclk->param.reg_clk_offset, pclk->param.reg_clk_mask,
 			data);
 
@@ -268,8 +266,8 @@ static int xgene_clk_enable(struct clk_hw *hw)
 		data &= ~pclk->param.reg_csr_mask;
 		xgene_clk_write(data, pclk->param.csr_reg +
 					pclk->param.reg_csr_offset);
-		pr_debug("%s CSR RESET PADDR base %pa csr offset 0x%08X mask 0x%08X value 0x%08X\n",
-			clk_hw_get_name(hw), &reg,
+		pr_debug("%s csr offset 0x%08X mask 0x%08X value 0x%08X\n",
+			clk_hw_get_name(hw),
 			pclk->param.reg_csr_offset, pclk->param.reg_csr_mask,
 			data);
 	}
Signature · 1 line
2.7.4
#1 lore raw

Hi Laura,

Quoted 49 lines

ioremaped addresses are not linearly mapped so the physical address can not be figured out via __pa. More generally, there is no guarantee that backing value of an ioremapped address is a physical address at all. The value here is only used for debugging so just drop the call to __pa on the ioremapped address.

Fixes 6ae5fd381251 ("clk: xgene: Silence sparse warnings")

---
v2: Fix up one more format string

I put the fixes tag to match with the cleanup that was done. If there is interest in this fix for pre-4.2 kernels for stable, I can submit a patch for that as well.

---
 drivers/clk/clk-xgene.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/clk/clk-xgene.c +2 -4
index 3433132..1e67655 100644
@@ -243,22 +243,20 @@ static int xgene_clk_enable(struct clk_hw *hw)
        struct xgene_clk *pclk = to_xgene_clk(hw);
        unsigned long flags = 0;
        u32 data;
-       phys_addr_t reg;
 
        if (pclk->lock)
                spin_lock_irqsave(pclk->lock, flags);
 
        if (pclk->param.csr_reg != NULL) {
                pr_debug("%s clock enabled\n", clk_hw_get_name(hw));
-               reg = __pa(pclk->param.csr_reg);
                /* First enable the clock */
                data = xgene_clk_read(pclk->param.csr_reg +
                                        pclk->param.reg_clk_offset);
                data |= pclk->param.reg_clk_mask;
                xgene_clk_write(data, pclk->param.csr_reg +
                                        pclk->param.reg_clk_offset);
-               pr_debug("%s clock PADDR base %pa clk offset 0x%08X mask 0x%08X value 0x%08X\n",
-                       clk_hw_get_name(hw), &reg,
+               pr_debug("%s clk offset 0x%08X mask 0x%08X value 0x%08X\n",
+                       clk_hw_get_name(hw),
                        pclk->param.reg_clk_offset, pclk->param.reg_clk_mask,
                        data);
 

drivers/clk/clk-xgene.c static int xgene_clk_enable(struct clk_hw *hw) · line 273

Quoted 10 lines
drivers/clk/clk-xgene.c +2 -2
@@ -268,8 +266,8 @@ static int xgene_clk_enable(struct clk_hw *hw)
                data &= ~pclk->param.reg_csr_mask;
                xgene_clk_write(data, pclk->param.csr_reg +
                                        pclk->param.reg_csr_offset);
-               pr_debug("%s CSR RESET PADDR base %pa csr offset 0x%08X mask 0x%08X value 0x%08X\n",
-                       clk_hw_get_name(hw), &reg,
+               pr_debug("%s csr offset 0x%08X mask 0x%08X value 0x%08X\n",
+                       clk_hw_get_name(hw),
                        pclk->param.reg_csr_offset, pclk->param.reg_csr_mask,
                        data);
        }

The code looks fine to me. May be overly cautious here. Do you have a board to test this out?

-Loc

#2 lore raw
Quoted 66 lines · Loc Ho

Hi Laura,

Quoted 49 lines

ioremaped addresses are not linearly mapped so the physical address can not be figured out via __pa. More generally, there is no guarantee that backing value of an ioremapped address is a physical address at all. The value here is only used for debugging so just drop the call to __pa on the ioremapped address.

Fixes 6ae5fd381251 ("clk: xgene: Silence sparse warnings")

---
v2: Fix up one more format string

I put the fixes tag to match with the cleanup that was done. If there is interest in this fix for pre-4.2 kernels for stable, I can submit a patch for that as well.

---
 drivers/clk/clk-xgene.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/clk/clk-xgene.c +2 -4
index 3433132..1e67655 100644
@@ -243,22 +243,20 @@ static int xgene_clk_enable(struct clk_hw *hw)
        struct xgene_clk *pclk = to_xgene_clk(hw);
        unsigned long flags = 0;
        u32 data;
-       phys_addr_t reg;
 
        if (pclk->lock)
                spin_lock_irqsave(pclk->lock, flags);
 
        if (pclk->param.csr_reg != NULL) {
                pr_debug("%s clock enabled\n", clk_hw_get_name(hw));
-               reg = __pa(pclk->param.csr_reg);
                /* First enable the clock */
                data = xgene_clk_read(pclk->param.csr_reg +
                                        pclk->param.reg_clk_offset);
                data |= pclk->param.reg_clk_mask;
                xgene_clk_write(data, pclk->param.csr_reg +
                                        pclk->param.reg_clk_offset);
-               pr_debug("%s clock PADDR base %pa clk offset 0x%08X mask 0x%08X value 0x%08X\n",
-                       clk_hw_get_name(hw), &reg,
+               pr_debug("%s clk offset 0x%08X mask 0x%08X value 0x%08X\n",
+                       clk_hw_get_name(hw),
                        pclk->param.reg_clk_offset, pclk->param.reg_clk_mask,
                        data);
 

drivers/clk/clk-xgene.c static int xgene_clk_enable(struct clk_hw *hw) · line 273

Quoted 10 lines
drivers/clk/clk-xgene.c +2 -2
@@ -268,8 +266,8 @@ static int xgene_clk_enable(struct clk_hw *hw)
                data &= ~pclk->param.reg_csr_mask;
                xgene_clk_write(data, pclk->param.csr_reg +
                                        pclk->param.reg_csr_offset);
-               pr_debug("%s CSR RESET PADDR base %pa csr offset 0x%08X mask 0x%08X value 0x%08X\n",
-                       clk_hw_get_name(hw), &reg,
+               pr_debug("%s csr offset 0x%08X mask 0x%08X value 0x%08X\n",
+                       clk_hw_get_name(hw),
                        pclk->param.reg_csr_offset, pclk->param.reg_csr_mask,
                        data);
        }

The code looks fine to me. May be overly cautious here. Do you have a board to test this out?

Quoted 2 lines

-Loc

Yes, that was how I caught the problem. There are no errors that I can see with this patch applied.

Thanks,
Laura

Acked-by
#3 lore raw

Hi,

Quoted 72 lines
Quoted 72 lines
Quoted 64 lines

ioremaped addresses are not linearly mapped so the physical address can not be figured out via __pa. More generally, there is no guarantee that backing value of an ioremapped address is a physical address at all. The value here is only used for debugging so just drop the call to __pa on the ioremapped address.

Fixes 6ae5fd381251 ("clk: xgene: Silence sparse warnings")

---
v2: Fix up one more format string

I put the fixes tag to match with the cleanup that was done. If there is interest in this fix for pre-4.2 kernels for stable, I can submit a patch for that as well.

---
 drivers/clk/clk-xgene.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/clk/clk-xgene.c +2 -4
index 3433132..1e67655 100644
@@ -243,22 +243,20 @@ static int xgene_clk_enable(struct clk_hw *hw)
        struct xgene_clk *pclk = to_xgene_clk(hw);
        unsigned long flags = 0;
        u32 data;
-       phys_addr_t reg;
 
        if (pclk->lock)
                spin_lock_irqsave(pclk->lock, flags);
 
        if (pclk->param.csr_reg != NULL) {
                pr_debug("%s clock enabled\n", clk_hw_get_name(hw));
-               reg = __pa(pclk->param.csr_reg);
                /* First enable the clock */
                data = xgene_clk_read(pclk->param.csr_reg +
                                        pclk->param.reg_clk_offset);
                data |= pclk->param.reg_clk_mask;
                xgene_clk_write(data, pclk->param.csr_reg +
                                        pclk->param.reg_clk_offset);
-               pr_debug("%s clock PADDR base %pa clk offset 0x%08X mask
 0x%08X value 0x%08X\n",
-                       clk_hw_get_name(hw), &reg,
+               pr_debug("%s clk offset 0x%08X mask 0x%08X value
 0x%08X\n",
+                       clk_hw_get_name(hw),
                        pclk->param.reg_clk_offset,

pclk->param.reg_clk_mask,

                        data);
drivers/clk/clk-xgene.c +2 -2
@@ -268,8 +266,8 @@ static int xgene_clk_enable(struct clk_hw *hw)
                data &= ~pclk->param.reg_csr_mask;
                xgene_clk_write(data, pclk->param.csr_reg +
                                        pclk->param.reg_csr_offset);
-               pr_debug("%s CSR RESET PADDR base %pa csr offset 0x%08X
 mask 0x%08X value 0x%08X\n",
-                       clk_hw_get_name(hw), &reg,
+               pr_debug("%s csr offset 0x%08X mask 0x%08X value
 0x%08X\n",
+                       clk_hw_get_name(hw),
                        pclk->param.reg_csr_offset,

pclk->param.reg_csr_mask,

Quoted 2 lines
                        data);
        }

The code looks fine to me. May be overly cautious here. Do you have a board to test this out?

Quoted 5 lines
Quoted 2 lines

-Loc

Yes, that was how I caught the problem. There are no errors that I can see with this patch applied.

-Loc

Applied
#4 lore raw
In reply to Laura Abbott
Quoted 10 lines · Laura Abbott

ioremaped addresses are not linearly mapped so the physical address can not be figured out via __pa. More generally, there is no guarantee that backing value of an ioremapped address is a physical address at all. The value here is only used for debugging so just drop the call to __pa on the ioremapped address.

Fixes 6ae5fd381251 ("clk: xgene: Silence sparse warnings")

---

Applied to clk-fixes

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project