Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+16 -14
+16 -14
drivers/hte/hte-tegra194.c
··· 132 132 const struct tegra_hte_data *prov_data; 133 133 struct tegra_hte_line_data *line_data; 134 134 struct hte_chip *chip; 135 - struct gpio_chip *c; 135 + struct gpio_device *gdev; 136 136 void __iomem *regs; 137 137 }; 138 138 ··· 418 418 * HTE/GTE namespace. 419 419 */ 420 420 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); 422 422 map = gs->prov_data->map; 423 423 map_sz = gs->prov_data->map_sz; 424 424 } else if (gs->prov_data->type == HTE_TEGRA_TYPE_GPIO && args) { ··· 645 645 if (!hte_dev || (hte_dev->prov_data->type != HTE_TEGRA_TYPE_GPIO)) 646 646 return false; 647 647 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); 649 649 } 650 650 651 651 static const struct of_device_id tegra_hte_of_match[] = { ··· 673 673 tegra_hte_writel(gs, HTE_TECTRL, 0); 674 674 } 675 675 676 - static int tegra_get_gpiochip_from_name(struct gpio_chip *chip, void *data) 676 + static void tegra_hte_put_gpio_device(void *data) 677 677 { 678 - return !strcmp(chip->label, data); 679 - } 678 + struct gpio_device *gdev = data; 680 679 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); 684 681 } 685 682 686 683 static int tegra_hte_probe(struct platform_device *pdev) ··· 757 760 758 761 if (of_device_is_compatible(dev->of_node, 759 762 "nvidia,tegra194-gte-aon")) { 760 - hte_dev->c = gpiochip_find("tegra194-gpio-aon", 761 - tegra_get_gpiochip_from_name); 763 + hte_dev->gdev = 764 + gpio_device_find_by_label("tegra194-gpio-aon"); 762 765 } else { 763 766 gpio_ctrl = of_parse_phandle(dev->of_node, 764 767 "nvidia,gpio-controller", ··· 769 772 return -ENODEV; 770 773 } 771 774 772 - hte_dev->c = gpiochip_find(gpio_ctrl, 773 - tegra_gpiochip_match); 775 + hte_dev->gdev = 776 + gpio_device_find_by_fwnode(of_fwnode_handle(gpio_ctrl)); 774 777 of_node_put(gpio_ctrl); 775 778 } 776 779 777 - if (!hte_dev->c) 780 + if (!hte_dev->gdev) 778 781 return dev_err_probe(dev, -EPROBE_DEFER, 779 782 "wait for gpio controller\n"); 783 + 784 + ret = devm_add_action_or_reset(dev, tegra_hte_put_gpio_device, 785 + hte_dev->gdev); 786 + if (ret) 787 + return ret; 780 788 } 781 789 782 790 hte_dev->chip = gc;