Skip to contentSkip to conversation

pinctrl: samsung: Constify wakeup driver specific data

PATCH In review Krzysztof Kozlowski 2 participants 4 messages May 23, 2017 – May 29, 2017

Subsystems (4)
lore
Share & tools
lore

Krzysztof Kozlowski

author maintainer
#0 lore raw

PATCH 1/3 pinctrl: samsung: Constify wakeup driver specific data

Static exynos_irq_chip structures, containing driver specific data, are referenced only through opaque data pointer in const of_device_id table. The contents of pointed memory (exynos_irq_chip structure itself) is then copied with kmemdup() during wakeup initialization so exynos_irq_chip can be made const for code safenes.

---
 drivers/pinctrl/samsung/pinctrl-exynos.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/samsung/pinctrl-exynos.c +2 -2
index 7b0e6cc35e04..cdea07af308a 100644
@@ -387,7 +387,7 @@ static int exynos_wkup_irq_set_wake(struct irq_data *irqd, unsigned int on)
 /*
  * irq_chip for wakeup interrupts
  */
-static struct exynos_irq_chip exynos4210_wkup_irq_chip __initdata = {
+static const struct exynos_irq_chip exynos4210_wkup_irq_chip __initconst = {
 	.chip = {
 		.name = "exynos4210_wkup_irq_chip",
 		.irq_unmask = exynos_irq_unmask,
@@ -403,7 +403,7 @@ static struct exynos_irq_chip exynos4210_wkup_irq_chip __initdata = {
 	.eint_pend = EXYNOS_WKUP_EPEND_OFFSET,
 };
 
-static struct exynos_irq_chip exynos7_wkup_irq_chip __initdata = {
+static const struct exynos_irq_chip exynos7_wkup_irq_chip __initconst = {
 	.chip = {
 		.name = "exynos7_wkup_irq_chip",
 		.irq_unmask = exynos_irq_unmask,
Signature · 1 line
2.9.3
author maintainer
#1 lore raw

PATCH 2/3 pinctrl: samsung: Handle memory allocation failure during wakeup banks init

Check if kmemdup failed during wakeup banks initialization. Otherwise NULL pointer would be stored under "irq_chip" member of bank and later dereferenced in interrupt handler.

---
 drivers/pinctrl/samsung/pinctrl-exynos.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pinctrl/samsung/pinctrl-exynos.c +2 -0
index cdea07af308a..66122627b3ed 100644
@@ -503,6 +503,8 @@ static int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
 		if (match) {
 			irq_chip = kmemdup(match->data,
 				sizeof(*irq_chip), GFP_KERNEL);
+			if (!irq_chip)
+				return -ENOMEM;
 			wkup_np = np;
 			break;
 		}
Signature · 1 line
2.9.3
author maintainer
#2 lore raw

PATCH 3/3 pinctrl: samsung: Explicitly cast pointer returned by of_iomap() to iomem

In reply to Krzysztof Kozlowski

For S5Pv210 retention control, the driver stores the iomem pointer from of_iomap() under void pointer priv member. This makes sparse unhappy:

drivers/pinctrl/samsung/pinctrl-exynos.c:664:36: warning: incorrect type in argument 1 (different address spaces)
drivers/pinctrl/samsung/pinctrl-exynos.c:664:36: expected void const volatile [noderef] <asn:2>*addr
drivers/pinctrl/samsung/pinctrl-exynos.c:664:36: got void *

The iomem pointer is used safely (stored under priv by s5pv210_retention_init(), used by s5pv210_retention_disable() thus we can add explicit casts to iomem silence the warning.

---
 drivers/pinctrl/samsung/pinctrl-exynos.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pinctrl/samsung/pinctrl-exynos.c +3 -3
index 66122627b3ed..a870af943bc7 100644
@@ -656,7 +656,7 @@ static void exynos_pinctrl_resume(struct samsung_pinctrl_drv_data *drvdata)
 
 static void s5pv210_retention_disable(struct samsung_pinctrl_drv_data *drvdata)
 {
-	void *clk_base = drvdata->retention_ctrl->priv;
+	void __iomem *clk_base = (void __iomem *)drvdata->retention_ctrl->priv;
 	u32 tmp;
 
 	tmp = __raw_readl(clk_base + S5P_OTHERS);
@@ -671,7 +671,7 @@ s5pv210_retention_init(struct samsung_pinctrl_drv_data *drvdata,
 {
 	struct samsung_retention_ctrl *ctrl;
 	struct device_node *np;
-	void *clk_base;
+	void __iomem *clk_base;
 
 	ctrl = devm_kzalloc(drvdata->dev, sizeof(*ctrl), GFP_KERNEL);
 	if (!ctrl)
@@ -690,7 +690,7 @@ s5pv210_retention_init(struct samsung_pinctrl_drv_data *drvdata,
 		return ERR_PTR(-EINVAL);
 	}
 
-	ctrl->priv = clk_base;
+	ctrl->priv = (void __force *)clk_base;
 	ctrl->disable = s5pv210_retention_disable;
 
 	return ctrl;
Signature · 1 line
2.9.3
#3 lore raw
In reply to Krzysztof Kozlowski
Quoted 7 lines · Krzysztof Kozlowski

Static exynos_irq_chip structures, containing driver specific data, are referenced only through opaque data pointer in const of_device_id table. The contents of pointed memory (exynos_irq_chip structure itself) is then copied with kmemdup() during wakeup initialization so exynos_irq_chip can be made const for code safenes.

All looks good to me, Acked-by.

Expecting to get this in a pull request.

Yours,
Linus Walleij