Skip to content

Commit a87eaff

Browse files
committed
Merge tag 'pinctrl-v6.5-4' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl
Pull pin control fixes from Linus Walleij: "Here are some Renesas and AMD driver fixes, the AMD fix affects important laptops in the wild so this one is pretty important. It seems a bit tough to get this right. - Fix DT parsing and related locking in the Renesas driver. - Fix wakeup IRQs in the AMD driver once again. Really tricky this one" * tag 'pinctrl-v6.5-4' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl: pinctrl: amd: Mask wake bits on probe again pinctrl: renesas: rza2: Add lock around pinctrl_generic{{add,remove}_group,{add,remove}_function} pinctrl: renesas: rzv2m: Fix NULL pointer dereference in rzv2m_dt_subnode_to_map() pinctrl: renesas: rzg2l: Fix NULL pointer dereference in rzg2l_dt_subnode_to_map()
2 parents ced5bf2 + 6bc3462 commit a87eaff

File tree

4 files changed

+68
-7
lines changed

4 files changed

+68
-7
lines changed

drivers/pinctrl/pinctrl-amd.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,33 @@ static const struct pinconf_ops amd_pinconf_ops = {
862862
.pin_config_group_set = amd_pinconf_group_set,
863863
};
864864

865+
static void amd_gpio_irq_init(struct amd_gpio *gpio_dev)
866+
{
867+
struct pinctrl_desc *desc = gpio_dev->pctrl->desc;
868+
unsigned long flags;
869+
u32 pin_reg, mask;
870+
int i;
871+
872+
mask = BIT(WAKE_CNTRL_OFF_S0I3) | BIT(WAKE_CNTRL_OFF_S3) |
873+
BIT(WAKE_CNTRL_OFF_S4);
874+
875+
for (i = 0; i < desc->npins; i++) {
876+
int pin = desc->pins[i].number;
877+
const struct pin_desc *pd = pin_desc_get(gpio_dev->pctrl, pin);
878+
879+
if (!pd)
880+
continue;
881+
882+
raw_spin_lock_irqsave(&gpio_dev->lock, flags);
883+
884+
pin_reg = readl(gpio_dev->base + pin * 4);
885+
pin_reg &= ~mask;
886+
writel(pin_reg, gpio_dev->base + pin * 4);
887+
888+
raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
889+
}
890+
}
891+
865892
#ifdef CONFIG_PM_SLEEP
866893
static bool amd_gpio_should_save(struct amd_gpio *gpio_dev, unsigned int pin)
867894
{
@@ -1099,6 +1126,9 @@ static int amd_gpio_probe(struct platform_device *pdev)
10991126
return PTR_ERR(gpio_dev->pctrl);
11001127
}
11011128

1129+
/* Disable and mask interrupts */
1130+
amd_gpio_irq_init(gpio_dev);
1131+
11021132
girq = &gpio_dev->gc.irq;
11031133
gpio_irq_chip_set_chip(girq, &amd_gpio_irqchip);
11041134
/* This will let us handle the parent IRQ in the driver */

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)