Skip to content

Commit 8fcc1c4

Browse files
bijudasgeertu
authored andcommitted
pinctrl: renesas: rza2: Add lock around pinctrl_generic{{add,remove}_group,{add,remove}_function}
The pinctrl group and function creation/remove calls expect caller to take care of locking. Add lock around these functions. Fixes: b59d0e7 ("pinctrl: Add RZ/A2 pin and gpio controller") Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Link: https://lore.kernel.org/r/20230815131558.33787-4-biju.das.jz@bp.renesas.com Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
1 parent f982b9d commit 8fcc1c4

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
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) *

0 commit comments

Comments
 (0)