Skip to content

Commit f982b9d

Browse files
bijudasgeertu
authored andcommitted
pinctrl: renesas: rzv2m: Fix NULL pointer dereference in rzv2m_dt_subnode_to_map()
Fix the below random NULL pointer crash during boot by serializing pinctrl group and function creation/remove calls in rzv2m_dt_subnode_to_map() with mutex lock. Crash logs: pc : __pi_strcmp+0x20/0x140 lr : pinmux_func_name_to_selector+0x68/0xa4 Call trace: __pi_strcmp+0x20/0x140 pinmux_generic_add_function+0x34/0xcc rzv2m_dt_subnode_to_map+0x2e4/0x418 rzv2m_dt_node_to_map+0x15c/0x18c pinctrl_dt_to_map+0x218/0x37c create_pinctrl+0x70/0x3d8 While at it, add a comment for lock. Fixes: 92a9b82 ("pinctrl: renesas: Add RZ/V2M pin and gpio controller driver") 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-3-biju.das.jz@bp.renesas.com Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
1 parent 661efa2 commit f982b9d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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)