Skip to content

Commit 6f0ec09

Browse files
ribaldalinusw
authored andcommitted
pinctrl: msm: Use init_valid_mask exported function
The current code produces XPU violation if get_direction is called just after the initialization. Signed-off-by: Ricardo Ribalda Delgado <[email protected]> Acked-by: Timur Tabi <[email protected]> Tested-by: Jeffrey Hugo <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent f8ec92a commit 6f0ec09

File tree

1 file changed

+37
-42
lines changed

1 file changed

+37
-42
lines changed

drivers/pinctrl/qcom/pinctrl-msm.c

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,42 @@ static void msm_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
566566
#define msm_gpio_dbg_show NULL
567567
#endif
568568

569+
static int msm_gpio_init_valid_mask(struct gpio_chip *chip)
570+
{
571+
struct msm_pinctrl *pctrl = gpiochip_get_data(chip);
572+
int ret;
573+
unsigned int len, i;
574+
unsigned int max_gpios = pctrl->soc->ngpios;
575+
u16 *tmp;
576+
577+
/* The number of GPIOs in the ACPI tables */
578+
len = ret = device_property_read_u16_array(pctrl->dev, "gpios", NULL,
579+
0);
580+
if (ret < 0)
581+
return 0;
582+
583+
if (ret > max_gpios)
584+
return -EINVAL;
585+
586+
tmp = kmalloc_array(len, sizeof(*tmp), GFP_KERNEL);
587+
if (!tmp)
588+
return -ENOMEM;
589+
590+
ret = device_property_read_u16_array(pctrl->dev, "gpios", tmp, len);
591+
if (ret < 0) {
592+
dev_err(pctrl->dev, "could not read list of GPIOs\n");
593+
goto out;
594+
}
595+
596+
bitmap_zero(chip->valid_mask, max_gpios);
597+
for (i = 0; i < len; i++)
598+
set_bit(tmp[i], chip->valid_mask);
599+
600+
out:
601+
kfree(tmp);
602+
return ret;
603+
}
604+
569605
static const struct gpio_chip msm_gpio_template = {
570606
.direction_input = msm_gpio_direction_input,
571607
.direction_output = msm_gpio_direction_output,
@@ -575,6 +611,7 @@ static const struct gpio_chip msm_gpio_template = {
575611
.request = gpiochip_generic_request,
576612
.free = gpiochip_generic_free,
577613
.dbg_show = msm_gpio_dbg_show,
614+
.init_valid_mask = msm_gpio_init_valid_mask,
578615
};
579616

580617
/* For dual-edge interrupts in software, since some hardware has no
@@ -831,41 +868,6 @@ static void msm_gpio_irq_handler(struct irq_desc *desc)
831868
chained_irq_exit(chip, desc);
832869
}
833870

834-
static int msm_gpio_init_valid_mask(struct gpio_chip *chip,
835-
struct msm_pinctrl *pctrl)
836-
{
837-
int ret;
838-
unsigned int len, i;
839-
unsigned int max_gpios = pctrl->soc->ngpios;
840-
u16 *tmp;
841-
842-
/* The number of GPIOs in the ACPI tables */
843-
len = ret = device_property_read_u16_array(pctrl->dev, "gpios", NULL, 0);
844-
if (ret < 0)
845-
return 0;
846-
847-
if (ret > max_gpios)
848-
return -EINVAL;
849-
850-
tmp = kmalloc_array(len, sizeof(*tmp), GFP_KERNEL);
851-
if (!tmp)
852-
return -ENOMEM;
853-
854-
ret = device_property_read_u16_array(pctrl->dev, "gpios", tmp, len);
855-
if (ret < 0) {
856-
dev_err(pctrl->dev, "could not read list of GPIOs\n");
857-
goto out;
858-
}
859-
860-
bitmap_zero(chip->valid_mask, max_gpios);
861-
for (i = 0; i < len; i++)
862-
set_bit(tmp[i], chip->valid_mask);
863-
864-
out:
865-
kfree(tmp);
866-
return ret;
867-
}
868-
869871
static bool msm_gpio_needs_valid_mask(struct msm_pinctrl *pctrl)
870872
{
871873
return device_property_read_u16_array(pctrl->dev, "gpios", NULL, 0) > 0;
@@ -902,13 +904,6 @@ static int msm_gpio_init(struct msm_pinctrl *pctrl)
902904
return ret;
903905
}
904906

905-
ret = msm_gpio_init_valid_mask(chip, pctrl);
906-
if (ret) {
907-
dev_err(pctrl->dev, "Failed to setup irq valid bits\n");
908-
gpiochip_remove(&pctrl->chip);
909-
return ret;
910-
}
911-
912907
/*
913908
* For DeviceTree-supported systems, the gpio core checks the
914909
* pinctrl's device node for the "gpio-ranges" property.

0 commit comments

Comments
 (0)