Skip to content

Commit 6046c35

Browse files
committed
Merge tag 'renesas-pinctrl-fixes-for-v6.5-tag2' of git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers into fixes
pinctrl: renesas: Fixes for v6.5 (take two) - Fix race conditions in pinctrl group and function creation/remove calls on the RZ/G2L, RZ/V2M, and RZ/A2 SoC families. Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2 parents 706a741 + 8fcc1c4 commit 6046c35

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

drivers/pinctrl/renesas/pinctrl-rza2.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/gpio/driver.h>
1515
#include <linux/io.h>
1616
#include <linux/module.h>
17+
#include <linux/mutex.h>
1718
#include <linux/of_device.h>
1819
#include <linux/pinctrl/pinmux.h>
1920

@@ -46,6 +47,7 @@ struct rza2_pinctrl_priv {
4647
struct pinctrl_dev *pctl;
4748
struct pinctrl_gpio_range gpio_range;
4849
int npins;
50+
struct mutex mutex; /* serialize adding groups and functions */
4951
};
5052

5153
#define RZA2_PDR(port) (0x0000 + (port) * 2) /* Direction 16-bit */
@@ -358,10 +360,14 @@ static int rza2_dt_node_to_map(struct pinctrl_dev *pctldev,
358360
psel_val[i] = MUX_FUNC(value);
359361
}
360362

363+
mutex_lock(&priv->mutex);
364+
361365
/* Register a single pin group listing all the pins we read from DT */
362366
gsel = pinctrl_generic_add_group(pctldev, np->name, pins, npins, NULL);
363-
if (gsel < 0)
364-
return gsel;
367+
if (gsel < 0) {
368+
ret = gsel;
369+
goto unlock;
370+
}
365371

366372
/*
367373
* Register a single group function where the 'data' is an array PSEL
@@ -390,6 +396,8 @@ static int rza2_dt_node_to_map(struct pinctrl_dev *pctldev,
390396
(*map)->data.mux.function = np->name;
391397
*num_maps = 1;
392398

399+
mutex_unlock(&priv->mutex);
400+
393401
return 0;
394402

395403
remove_function:
@@ -398,6 +406,9 @@ static int rza2_dt_node_to_map(struct pinctrl_dev *pctldev,
398406
remove_group:
399407
pinctrl_generic_remove_group(pctldev, gsel);
400408

409+
unlock:
410+
mutex_unlock(&priv->mutex);
411+
401412
dev_err(priv->dev, "Unable to parse DT node %s\n", np->name);
402413

403414
return ret;
@@ -473,6 +484,8 @@ static int rza2_pinctrl_probe(struct platform_device *pdev)
473484
if (IS_ERR(priv->base))
474485
return PTR_ERR(priv->base);
475486

487+
mutex_init(&priv->mutex);
488+
476489
platform_set_drvdata(pdev, priv);
477490

478491
priv->npins = (int)(uintptr_t)of_device_get_match_data(&pdev->dev) *

drivers/pinctrl/renesas/pinctrl-rzg2l.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/interrupt.h>
1212
#include <linux/io.h>
1313
#include <linux/module.h>
14+
#include <linux/mutex.h>
1415
#include <linux/of_device.h>
1516
#include <linux/of_irq.h>
1617
#include <linux/seq_file.h>
@@ -149,10 +150,11 @@ struct rzg2l_pinctrl {
149150
struct gpio_chip gpio_chip;
150151
struct pinctrl_gpio_range gpio_range;
151152
DECLARE_BITMAP(tint_slot, RZG2L_TINT_MAX_INTERRUPT);
152-
spinlock_t bitmap_lock;
153+
spinlock_t bitmap_lock; /* protect tint_slot bitmap */
153154
unsigned int hwirq[RZG2L_TINT_MAX_INTERRUPT];
154155

155-
spinlock_t lock;
156+
spinlock_t lock; /* lock read/write registers */
157+
struct mutex mutex; /* serialize adding groups and functions */
156158
};
157159

158160
static const unsigned int iolh_groupa_mA[] = { 2, 4, 8, 12 };
@@ -362,11 +364,13 @@ static int rzg2l_dt_subnode_to_map(struct pinctrl_dev *pctldev,
362364
name = np->name;
363365
}
364366

367+
mutex_lock(&pctrl->mutex);
368+
365369
/* Register a single pin group listing all the pins we read from DT */
366370
gsel = pinctrl_generic_add_group(pctldev, name, pins, num_pinmux, NULL);
367371
if (gsel < 0) {
368372
ret = gsel;
369-
goto done;
373+
goto unlock;
370374
}
371375

372376
/*
@@ -380,6 +384,8 @@ static int rzg2l_dt_subnode_to_map(struct pinctrl_dev *pctldev,
380384
goto remove_group;
381385
}
382386

387+
mutex_unlock(&pctrl->mutex);
388+
383389
maps[idx].type = PIN_MAP_TYPE_MUX_GROUP;
384390
maps[idx].data.mux.group = name;
385391
maps[idx].data.mux.function = name;
@@ -391,6 +397,8 @@ static int rzg2l_dt_subnode_to_map(struct pinctrl_dev *pctldev,
391397

392398
remove_group:
393399
pinctrl_generic_remove_group(pctldev, gsel);
400+
unlock:
401+
mutex_unlock(&pctrl->mutex);
394402
done:
395403
*index = idx;
396404
kfree(configs);
@@ -1509,6 +1517,7 @@ static int rzg2l_pinctrl_probe(struct platform_device *pdev)
15091517

15101518
spin_lock_init(&pctrl->lock);
15111519
spin_lock_init(&pctrl->bitmap_lock);
1520+
mutex_init(&pctrl->mutex);
15121521

15131522
platform_set_drvdata(pdev, pctrl);
15141523

drivers/pinctrl/renesas/pinctrl-rzv2m.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/gpio/driver.h>
1515
#include <linux/io.h>
1616
#include <linux/module.h>
17+
#include <linux/mutex.h>
1718
#include <linux/of_device.h>
1819
#include <linux/spinlock.h>
1920

@@ -123,7 +124,8 @@ struct rzv2m_pinctrl {
123124
struct gpio_chip gpio_chip;
124125
struct pinctrl_gpio_range gpio_range;
125126

126-
spinlock_t lock;
127+
spinlock_t lock; /* lock read/write registers */
128+
struct mutex mutex; /* serialize adding groups and functions */
127129
};
128130

129131
static const unsigned int drv_1_8V_group2_uA[] = { 1800, 3800, 7800, 11000 };
@@ -322,11 +324,13 @@ static int rzv2m_dt_subnode_to_map(struct pinctrl_dev *pctldev,
322324
name = np->name;
323325
}
324326

327+
mutex_lock(&pctrl->mutex);
328+
325329
/* Register a single pin group listing all the pins we read from DT */
326330
gsel = pinctrl_generic_add_group(pctldev, name, pins, num_pinmux, NULL);
327331
if (gsel < 0) {
328332
ret = gsel;
329-
goto done;
333+
goto unlock;
330334
}
331335

332336
/*
@@ -340,6 +344,8 @@ static int rzv2m_dt_subnode_to_map(struct pinctrl_dev *pctldev,
340344
goto remove_group;
341345
}
342346

347+
mutex_unlock(&pctrl->mutex);
348+
343349
maps[idx].type = PIN_MAP_TYPE_MUX_GROUP;
344350
maps[idx].data.mux.group = name;
345351
maps[idx].data.mux.function = name;
@@ -351,6 +357,8 @@ static int rzv2m_dt_subnode_to_map(struct pinctrl_dev *pctldev,
351357

352358
remove_group:
353359
pinctrl_generic_remove_group(pctldev, gsel);
360+
unlock:
361+
mutex_unlock(&pctrl->mutex);
354362
done:
355363
*index = idx;
356364
kfree(configs);
@@ -1071,6 +1079,7 @@ static int rzv2m_pinctrl_probe(struct platform_device *pdev)
10711079
}
10721080

10731081
spin_lock_init(&pctrl->lock);
1082+
mutex_init(&pctrl->mutex);
10741083

10751084
platform_set_drvdata(pdev, pctrl);
10761085

0 commit comments

Comments
 (0)