Skip to content

Commit dc850fa

Browse files
author
Bartosz Golaszewski
committed
hte: tegra194: don't access struct gpio_chip
Using struct gpio_chip is not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted struct gpio_device and its dedicated accessors. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Tested-by: Dipen Patel <dipenp@nvidia.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> [andy: used gpio_device_find_by_fwnode()] Reviewed-by: Dipen Patel <dipenp@nvidia.com> Link: https://lore.kernel.org/r/20231010151709.4104747-3-andriy.shevchenko@linux.intel.com Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
1 parent 8c85a10 commit dc850fa

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

drivers/hte/hte-tegra194.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ struct tegra_hte_soc {
132132
const struct tegra_hte_data *prov_data;
133133
struct tegra_hte_line_data *line_data;
134134
struct hte_chip *chip;
135-
struct gpio_chip *c;
135+
struct gpio_device *gdev;
136136
void __iomem *regs;
137137
};
138138

@@ -418,7 +418,7 @@ static int tegra_hte_line_xlate(struct hte_chip *gc,
418418
* HTE/GTE namespace.
419419
*/
420420
if (gs->prov_data->type == HTE_TEGRA_TYPE_GPIO && !args) {
421-
line_id = desc->attr.line_id - gs->c->base;
421+
line_id = desc->attr.line_id - gpio_device_get_base(gs->gdev);
422422
map = gs->prov_data->map;
423423
map_sz = gs->prov_data->map_sz;
424424
} else if (gs->prov_data->type == HTE_TEGRA_TYPE_GPIO && args) {
@@ -645,7 +645,7 @@ static bool tegra_hte_match_from_linedata(const struct hte_chip *chip,
645645
if (!hte_dev || (hte_dev->prov_data->type != HTE_TEGRA_TYPE_GPIO))
646646
return false;
647647

648-
return hte_dev->c == gpiod_to_chip(hdesc->attr.line_data);
648+
return hte_dev->gdev == gpiod_to_gpio_device(hdesc->attr.line_data);
649649
}
650650

651651
static const struct of_device_id tegra_hte_of_match[] = {
@@ -673,14 +673,11 @@ static void tegra_gte_disable(void *data)
673673
tegra_hte_writel(gs, HTE_TECTRL, 0);
674674
}
675675

676-
static int tegra_get_gpiochip_from_name(struct gpio_chip *chip, void *data)
676+
static void tegra_hte_put_gpio_device(void *data)
677677
{
678-
return !strcmp(chip->label, data);
679-
}
678+
struct gpio_device *gdev = data;
680679

681-
static int tegra_gpiochip_match(struct gpio_chip *chip, void *data)
682-
{
683-
return chip->fwnode == of_node_to_fwnode(data);
680+
gpio_device_put(gdev);
684681
}
685682

686683
static int tegra_hte_probe(struct platform_device *pdev)
@@ -760,8 +757,8 @@ static int tegra_hte_probe(struct platform_device *pdev)
760757

761758
if (of_device_is_compatible(dev->of_node,
762759
"nvidia,tegra194-gte-aon")) {
763-
hte_dev->c = gpiochip_find("tegra194-gpio-aon",
764-
tegra_get_gpiochip_from_name);
760+
hte_dev->gdev =
761+
gpio_device_find_by_label("tegra194-gpio-aon");
765762
} else {
766763
gpio_ctrl = of_parse_phandle(dev->of_node,
767764
"nvidia,gpio-controller",
@@ -772,14 +769,19 @@ static int tegra_hte_probe(struct platform_device *pdev)
772769
return -ENODEV;
773770
}
774771

775-
hte_dev->c = gpiochip_find(gpio_ctrl,
776-
tegra_gpiochip_match);
772+
hte_dev->gdev =
773+
gpio_device_find_by_fwnode(of_fwnode_handle(gpio_ctrl));
777774
of_node_put(gpio_ctrl);
778775
}
779776

780-
if (!hte_dev->c)
777+
if (!hte_dev->gdev)
781778
return dev_err_probe(dev, -EPROBE_DEFER,
782779
"wait for gpio controller\n");
780+
781+
ret = devm_add_action_or_reset(dev, tegra_hte_put_gpio_device,
782+
hte_dev->gdev);
783+
if (ret)
784+
return ret;
783785
}
784786

785787
hte_dev->chip = gc;

0 commit comments

Comments
 (0)