public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dipen Patel <dipenp@nvidia.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	timestamp@lists.linux.dev, linux-tegra@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Andy Shevchenko <andy@kernel.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>
Subject: Re: [PATCH v1 2/4] hte: tegra194: don't access struct gpio_chip
Date: Tue, 10 Oct 2023 12:31:29 -0700	[thread overview]
Message-ID: <147fe15c-13d3-60dc-bd49-cd0cb40126e9@nvidia.com> (raw)
In-Reply-To: <3e1e6acf-5862-9f35-cbe6-72bb17cf3851@nvidia.com>

On 10/10/23 9:19 AM, Dipen Patel wrote:
> On 10/10/23 8:17 AM, Andy Shevchenko wrote:
>> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>>
>> 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()]
>> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>> ---
>>  drivers/hte/hte-tegra194.c | 33 +++++++++++++++++++--------------
>>  1 file changed, 19 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/hte/hte-tegra194.c b/drivers/hte/hte-tegra194.c
>> index 9fd3c00ff695..339ff5921ec8 100644
>> --- a/drivers/hte/hte-tegra194.c
>> +++ b/drivers/hte/hte-tegra194.c
>> @@ -132,7 +132,7 @@ struct tegra_hte_soc {
>>  	const struct tegra_hte_data *prov_data;
>>  	struct tegra_hte_line_data *line_data;
>>  	struct hte_chip *chip;
>> -	struct gpio_chip *c;
>> +	struct gpio_device *gdev;
>>  	void __iomem *regs;
>>  };
>>  
>> @@ -421,7 +421,7 @@ static int tegra_hte_line_xlate(struct hte_chip *gc,
>>  	 * HTE/GTE namespace.
>>  	 */
>>  	if (gs->prov_data->type == HTE_TEGRA_TYPE_GPIO && !args) {
>> -		line_id = desc->attr.line_id - gs->c->base;
>> +		line_id = desc->attr.line_id - gpio_device_get_base(gs->gdev);
>>  		map = gs->prov_data->map;
>>  		map_sz = gs->prov_data->map_sz;
>>  	} else if (gs->prov_data->type == HTE_TEGRA_TYPE_GPIO && args) {
>> @@ -643,12 +643,15 @@ static irqreturn_t tegra_hte_isr(int irq, void *dev_id)
>>  static bool tegra_hte_match_from_linedata(const struct hte_chip *chip,
>>  					  const struct hte_ts_desc *hdesc)
>>  {
>> +	struct gpio_device *gdev __free(gpio_device_put) = NULL;
>>  	struct tegra_hte_soc *hte_dev = chip->data;
>>  
>>  	if (!hte_dev || (hte_dev->prov_data->type != HTE_TEGRA_TYPE_GPIO))
>>  		return false;
>>  
>> -	return hte_dev->c == gpiod_to_chip(hdesc->attr.line_data);
>> +	gdev = gpiod_to_device(hdesc->attr.line_data);
>> +
>> +	return hte_dev->gdev == gdev;
>>  }
>>  
>>  static const struct of_device_id tegra_hte_of_match[] = {
>> @@ -676,14 +679,11 @@ static void tegra_gte_disable(void *data)
>>  	tegra_hte_writel(gs, HTE_TECTRL, 0);
>>  }
>>  
>> -static int tegra_get_gpiochip_from_name(struct gpio_chip *chip, void *data)
>> +static void tegra_hte_put_gpio_device(void *data)
>>  {
>> -	return !strcmp(chip->label, data);
>> -}
>> +	struct gpio_device *gdev = data;
>>  
>> -static int tegra_gpiochip_match(struct gpio_chip *chip, void *data)
>> -{
>> -	return chip->fwnode == of_node_to_fwnode(data);
>> +	gpio_device_put(gdev);
>>  }
>>  
>>  static int tegra_hte_probe(struct platform_device *pdev)
>> @@ -763,8 +763,8 @@ static int tegra_hte_probe(struct platform_device *pdev)
>>  
>>  		if (of_device_is_compatible(dev->of_node,
>>  					    "nvidia,tegra194-gte-aon")) {
>> -			hte_dev->c = gpiochip_find("tegra194-gpio-aon",
>> -						tegra_get_gpiochip_from_name);
>> +			hte_dev->gdev =
>> +				gpio_device_find_by_label("tegra194-gpio-aon");
>>  		} else {
>>  			gpio_ctrl = of_parse_phandle(dev->of_node,
>>  						     "nvidia,gpio-controller",
>> @@ -775,14 +775,19 @@ static int tegra_hte_probe(struct platform_device *pdev)
>>  				return -ENODEV;
>>  			}
>>  
>> -			hte_dev->c = gpiochip_find(gpio_ctrl,
>> -						   tegra_gpiochip_match);
>> +			hte_dev->gdev =
>> +				gpio_device_find_by_fwnode(of_fnode_handle(gpio_ctrl));

I think there is typo for of_fnode*. Should it be of_fwnode*?

>>  			of_node_put(gpio_ctrl);
>>  		}
>>  
>> -		if (!hte_dev->c)
>> +		if (!hte_dev->gdev)
>>  			return dev_err_probe(dev, -EPROBE_DEFER,
>>  					     "wait for gpio controller\n");
>> +
>> +		ret = devm_add_action_or_reset(dev, tegra_hte_put_gpio_device,
>> +					       hte_dev->gdev);
>> +		if (ret)
>> +			return ret;
>>  	}
>>  
>>  	hte_dev->chip = gc;
> 
> Looks good to me, I will wait for others to comment and will test out (2,3,4
> also) probably end of the day 11th Oct.
> 


  reply	other threads:[~2023-10-10 19:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-10 15:17 [PATCH v1 0/4] hte: Improve GPIO handling and other cleanups Andy Shevchenko
2023-10-10 15:17 ` [PATCH v1 1/4] gpiolib: provide gpio_device_find_by_fwnode() Andy Shevchenko
2023-10-13  9:21   ` Linus Walleij
2023-10-10 15:17 ` [PATCH v1 2/4] hte: tegra194: don't access struct gpio_chip Andy Shevchenko
2023-10-10 16:19   ` Dipen Patel
2023-10-10 19:31     ` Dipen Patel [this message]
2023-10-11  5:54       ` Andy Shevchenko
2023-10-11 18:05         ` Dipen Patel
2023-10-10 15:17 ` [PATCH v1 3/4] hte: tegra194: Remove redundant dev_err() Andy Shevchenko
2023-10-11  2:19   ` Dipen Patel
2023-10-10 15:17 ` [PATCH v1 4/4] hte: tegra194: Switch to LATE_SIMPLE_DEV_PM_OPS() Andy Shevchenko
2023-10-10 19:36   ` Dipen Patel
2023-10-11  5:55     ` Andy Shevchenko
2023-10-11 18:06       ` Dipen Patel
2023-10-11  9:33 ` [PATCH v1 0/4] hte: Improve GPIO handling and other cleanups Bartosz Golaszewski
2023-10-11 10:06   ` Andy Shevchenko
2023-10-11 18:04     ` Dipen Patel
2023-10-11 11:43 ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=147fe15c-13d3-60dc-bd49-cd0cb40126e9@nvidia.com \
    --to=dipenp@nvidia.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy@kernel.org \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=jonathanh@nvidia.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=timestamp@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox