Skip to contentSkip to conversation

spmi: pmic-arb: Always allocate ppid_to_apid table

PATCH In review Stephen Boyd 6 participants 6 messages Jun 27, 2017 – Jul 18, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spmi: pmic-arb: Always allocate ppid_to_apid table

After commit 7f1d4e58dabb ("spmi: pmic-arb: optimize table lookups") we always need the ppid_to_apid table regardless of the version of pmic arbiter we have. Otherwise, we will try to deref the array when we don't allocate it on v2 hardware like the msm8974 SoCs.

Cc Abhijeet Dharmapurikar <[email protected]>
Cc Kiran Gunda <[email protected]>
Fixes 7f1d4e58dabb ("spmi: pmic-arb: optimize table lookups")
---
 drivers/spmi/spmi-pmic-arb.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/spmi/spmi-pmic-arb.c +7 -10
index 2afe3597982e..f4b7a98a7913 100644
@@ -134,7 +134,6 @@ struct apid_data {
  * @spmic:		SPMI controller object
  * @ver_ops:		version dependent operations.
  * @ppid_to_apid	in-memory copy of PPID -> channel (APID) mapping table.
- *			v2 only.
  */
 struct spmi_pmic_arb {
 	void __iomem		*rd_base;
@@ -1016,6 +1015,13 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
 		goto err_put_ctrl;
 	}
 
+	pa->ppid_to_apid = devm_kcalloc(&ctrl->dev, PMIC_ARB_MAX_PPID,
+					sizeof(*pa->ppid_to_apid), GFP_KERNEL);
+	if (!pa->ppid_to_apid) {
+		err = -ENOMEM;
+		goto err_put_ctrl;
+	}
+
 	hw_ver = readl_relaxed(core + PMIC_ARB_VERSION);
 
 	if (hw_ver < PMIC_ARB_VERSION_V2_MIN) {
@@ -1048,15 +1054,6 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
 			err = PTR_ERR(pa->wr_base);
 			goto err_put_ctrl;
 		}
-
-		pa->ppid_to_apid = devm_kcalloc(&ctrl->dev,
-						PMIC_ARB_MAX_PPID,
-						sizeof(*pa->ppid_to_apid),
-						GFP_KERNEL);
-		if (!pa->ppid_to_apid) {
-			err = -ENOMEM;
-			goto err_put_ctrl;
-		}
 	}
 
 	dev_info(&ctrl->dev, "PMIC arbiter version %s (0x%x)\n",
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Stephen Boyd

After commit 7f1d4e58dabb ("spmi: pmic-arb: optimize table lookups") we always need the ppid_to_apid table regardless of the version of pmic arbiter we have. Otherwise, we will try to deref the array when we don't allocate it on v2 hardware like the msm8974 SoCs.

Cc Abhijeet Dharmapurikar <[email protected]>
Cc Kiran Gunda <[email protected]>
Fixes 7f1d4e58dabb ("spmi: pmic-arb: optimize table lookups")
Quoted 49 lines
---
 drivers/spmi/spmi-pmic-arb.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/spmi/spmi-pmic-arb.c +0 -0
index 2afe3597982e..f4b7a98a7913 100644
@@ -134,7 +134,6 @@ struct apid_data {
  * @spmic:		SPMI controller object
  * @ver_ops:		version dependent operations.
  * @ppid_to_apid	in-memory copy of PPID -> channel (APID) mapping 

table.
- * v2 only.
*/
struct spmi_pmic_arb {

drivers/spmi/spmi-pmic-arb.c +7 -0
 	void __iomem		*rd_base;
@@ -1016,6 +1015,13 @@ static int spmi_pmic_arb_probe(struct
 platform_device *pdev)
 		goto err_put_ctrl;
 	}
 
+	pa->ppid_to_apid = devm_kcalloc(&ctrl->dev, PMIC_ARB_MAX_PPID,
+					sizeof(*pa->ppid_to_apid), GFP_KERNEL);
+	if (!pa->ppid_to_apid) {
+		err = -ENOMEM;
+		goto err_put_ctrl;
+	}
+
 	hw_ver = readl_relaxed(core + PMIC_ARB_VERSION);
 
drivers/spmi/spmi-pmic-arb.c +0 -9
 	if (hw_ver < PMIC_ARB_VERSION_V2_MIN) {
@@ -1048,15 +1054,6 @@ static int spmi_pmic_arb_probe(struct
 platform_device *pdev)
 			err = PTR_ERR(pa->wr_base);
 			goto err_put_ctrl;
 		}
-
-		pa->ppid_to_apid = devm_kcalloc(&ctrl->dev,
-						PMIC_ARB_MAX_PPID,
-						sizeof(*pa->ppid_to_apid),
-						GFP_KERNEL);
-		if (!pa->ppid_to_apid) {
-			err = -ENOMEM;
-			goto err_put_ctrl;
-		}
 	}
 
Quoted 1 line

dev_info(&ctrl->dev, "PMIC arbiter version %s (0x%x)\n",

Thanks for the fix !

Tested-by
#2 lore raw
Quoted 7 lines · kgunda at codeaurora.org
Quoted 6 lines · Stephen Boyd

After commit 7f1d4e58dabb ("spmi: pmic-arb: optimize table lookups") we always need the ppid_to_apid table regardless of the version of pmic arbiter we have. Otherwise, we will try to deref the array when we don't allocate it on v2 hardware like the msm8974 SoCs.

Quoted 5 lines
Quoted 4 lines
Cc Abhijeet Dharmapurikar <[email protected]>
Cc Kiran Gunda <[email protected]>
Fixes 7f1d4e58dabb ("spmi: pmic-arb: optimize table lookups")

Tested on a qcom-apq8074-dragonboard on 4.13-rc1

Quoted 54 lines
Quoted 47 lines
---
 drivers/spmi/spmi-pmic-arb.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/spmi/spmi-pmic-arb.c +7 -1
index 2afe3597982e..f4b7a98a7913 100644
@@ -134,7 +134,6 @@ struct apid_data {
  * @spmic:        SPMI controller object
  * @ver_ops:        version dependent operations.
  * @ppid_to_apid    in-memory copy of PPID -> channel (APID) mapping table.
- *            v2 only.
  */
 struct spmi_pmic_arb {
     void __iomem        *rd_base;
@@ -1016,6 +1015,13 @@ static int spmi_pmic_arb_probe(struct
 platform_device *pdev)
         goto err_put_ctrl;
     }
 
+    pa->ppid_to_apid = devm_kcalloc(&ctrl->dev, PMIC_ARB_MAX_PPID,
+                    sizeof(*pa->ppid_to_apid), GFP_KERNEL);
+    if (!pa->ppid_to_apid) {
+        err = -ENOMEM;
+        goto err_put_ctrl;
+    }
+
     hw_ver = readl_relaxed(core + PMIC_ARB_VERSION);
 
     if (hw_ver < PMIC_ARB_VERSION_V2_MIN) {
drivers/spmi/spmi-pmic-arb.c +0 -9
@@ -1048,15 +1054,6 @@ static int spmi_pmic_arb_probe(struct
 platform_device *pdev)
             err = PTR_ERR(pa->wr_base);
             goto err_put_ctrl;
         }
-
-        pa->ppid_to_apid = devm_kcalloc(&ctrl->dev,
-                        PMIC_ARB_MAX_PPID,
-                        sizeof(*pa->ppid_to_apid),
-                        GFP_KERNEL);
-        if (!pa->ppid_to_apid) {
-            err = -ENOMEM;
-            goto err_put_ctrl;
-        }
     }
 
Quoted 1 line
     dev_info(&ctrl->dev, "PMIC arbiter version %s (0x%x)\n",

Thanks for the fix !

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tested-by on v1 1/1
#3 lore raw
In reply to Stephen Boyd
Quoted 47 lines · On Dienstag, 27. Juni 2017 04:17:46 CEST Stephen Boyd wrote:

After commit 7f1d4e58dabb ("spmi: pmic-arb: optimize table lookups") we always need the ppid_to_apid table regardless of the version of pmic arbiter we have. Otherwise, we will try to deref the array when we don't allocate it on v2 hardware like the msm8974 SoCs.

Cc Abhijeet Dharmapurikar <[email protected]>
Cc Kiran Gunda <[email protected]>
Fixes 7f1d4e58dabb ("spmi: pmic-arb: optimize table lookups")
---
 drivers/spmi/spmi-pmic-arb.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/spmi/spmi-pmic-arb.c +7 -3
index 2afe3597982e..f4b7a98a7913 100644
@@ -134,7 +134,6 @@ struct apid_data {
  * @spmic:		SPMI controller object
  * @ver_ops:		version dependent operations.
  * @ppid_to_apid	in-memory copy of PPID -> channel (APID) mapping table.
- *			v2 only.
  */
 struct spmi_pmic_arb {
 	void __iomem		*rd_base;
@@ -1016,6 +1015,13 @@ static int spmi_pmic_arb_probe(struct platform_device
 *pdev) goto err_put_ctrl;
 	}
 
+	pa->ppid_to_apid = devm_kcalloc(&ctrl->dev, PMIC_ARB_MAX_PPID,
+					sizeof(*pa->ppid_to_apid), GFP_KERNEL);
+	if (!pa->ppid_to_apid) {
+		err = -ENOMEM;
+		goto err_put_ctrl;
+	}
+
 	hw_ver = readl_relaxed(core + PMIC_ARB_VERSION);
 
 	if (hw_ver < PMIC_ARB_VERSION_V2_MIN) {
@@ -1048,15 +1054,6 @@ static int spmi_pmic_arb_probe(struct platform_device
 *pdev) err = PTR_ERR(pa->wr_base);
 			goto err_put_ctrl;
 		}
-
-		pa->ppid_to_apid = devm_kcalloc(&ctrl->dev,

drivers/spmi/spmi-pmic-arb.c static int spmi_pmic_arb_probe(struct platform_device · line 1059

Quoted 10 lines
drivers/spmi/spmi-pmic-arb.c +0 -7
-						PMIC_ARB_MAX_PPID,
-						sizeof(*pa->ppid_to_apid),
-						GFP_KERNEL);
-		if (!pa->ppid_to_apid) {
-			err = -ENOMEM;
-			goto err_put_ctrl;
-		}
 	}
 
 	dev_info(&ctrl->dev, "PMIC arbiter version %s (0x%x)\n",
#4 lore raw
In reply to Stephen Boyd
Quoted 10 lines · Stephen Boyd

After commit 7f1d4e58dabb ("spmi: pmic-arb: optimize table lookups") we always need the ppid_to_apid table regardless of the version of pmic arbiter we have. Otherwise, we will try to deref the array when we don't allocate it on v2 hardware like the msm8974 SoCs.

Cc Abhijeet Dharmapurikar <[email protected]>
Cc Kiran Gunda <[email protected]>
Fixes 7f1d4e58dabb ("spmi: pmic-arb: optimize table lookups")

Greg,

Can you pick this up? This is an urgent fix for Qualcomm 8x74 platforms.

Thanks!

Andy

#5 lore raw
Quoted 7 lines · Andy Gross
Quoted 6 lines · Stephen Boyd

After commit 7f1d4e58dabb ("spmi: pmic-arb: optimize table lookups") we always need the ppid_to_apid table regardless of the version of pmic arbiter we have. Otherwise, we will try to deref the array when we don't allocate it on v2 hardware like the msm8974 SoCs.

Quoted 8 lines
Quoted 4 lines
Cc Abhijeet Dharmapurikar <[email protected]>
Cc Kiran Gunda <[email protected]>
Fixes 7f1d4e58dabb ("spmi: pmic-arb: optimize table lookups")

Greg,

Can you pick this up? This is an urgent fix for Qualcomm 8x74 platforms.

Will get it now, thanks.

greg k-h