From: Arina Kharlamova <arin…@mbzuai.ac.ae> nfcmrvl_nci_uart_open() runs every time the N_NCI line discipline is set and passes the tty device to the code that requests the reset GPIO with devm helpers. The tty device outlives the line discipline, and nfcmrvl_nci_uart_close() does not release the GPIO. The next open gets -EBUSY and falls back to the module parameters, without the reset line and without the DT settings. This needs a marvell,nfc-uart child node under the UART and a kernel without serdev ttyport (SERIAL_DEV_CTRL_TTYPORT=n). Commit 0cbe40112f42 ("NFC: nfcmrvl: do not use device-managed resources") removed devres from this driver for this reason, and the conversion to GPIO descriptors brought it back. Request the GPIO with the unmanaged helpers and put it in nfcmrvl_nci_unregister_dev() and in the error paths of nfcmrvl_nci_register_dev(). Fixes: 253350dbf3e7 ("nfc: nfcmrvl: convert to gpio descriptors") Signed-off-by: Arina Kharlamova <arin…@mbzuai.ac.ae> --- drivers/nfc/nfcmrvl/main.c | 9 +++++++-- drivers/nfc/nfcmrvl/uart.c | 15 +++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/nfc/nfcmrvl/main.c b/drivers/nfc/nfcmrvl/main.c index 6efa83219117..0e2a7f8353b2 100644 --- a/drivers/nfc/nfcmrvl/main.c +++ b/drivers/nfc/nfcmrvl/main.c @@ -102,8 +102,10 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy, u32 protocols; priv = kzalloc_obj(*priv); - if (!priv) + if (!priv) { + gpiod_put(pdata->reset_gpio); return ERR_PTR(-ENOMEM); + } priv->drv_data = drv_data; priv->if_ops = ops; @@ -114,7 +116,7 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy, if (!priv->config.reset_gpio) { priv->config.reset_gpio = - devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); if (IS_ERR(priv->config.reset_gpio)) { priv->config.reset_gpio = NULL; nfc_err(dev, "failed to get reset gpio\n"); @@ -171,6 +173,7 @@ error_fw_dnld_deinit: error_free_dev: nci_free_device(priv->ndev); error_free: + gpiod_put(priv->config.reset_gpio); kfree(priv); return ERR_PTR(rc); } @@ -186,6 +189,8 @@ void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv) nfcmrvl_fw_dnld_deinit(priv); + gpiod_put(priv->config.reset_gpio); + nci_free_device(ndev); kfree(priv); } diff --git a/drivers/nfc/nfcmrvl/uart.c b/drivers/nfc/nfcmrvl/uart.c index 9aedd168759c..3023757ab976 100644 --- a/drivers/nfc/nfcmrvl/uart.c +++ b/drivers/nfc/nfcmrvl/uart.c @@ -62,8 +62,7 @@ static const struct nfcmrvl_if_ops uart_ops = { }; static int nfcmrvl_uart_parse_dt(struct device_node *node, - struct nfcmrvl_platform_data *pdata, - struct device *dev) + struct nfcmrvl_platform_data *pdata) { struct device_node *matched_node; struct gpio_desc *reset_gpio; @@ -86,11 +85,11 @@ static int nfcmrvl_uart_parse_dt(struct device_node *node, pdata->flow_control = of_property_read_bool(matched_node, "flow-control"); pdata->break_control = of_property_read_bool(matched_node, "break-control"); - reset_gpio = devm_fwnode_gpiod_get_optional(dev, - of_fwnode_handle(matched_node), - "reset", GPIOD_OUT_HIGH, - "nfcmrvl_reset_n"); - if (IS_ERR(reset_gpio)) { + reset_gpio = fwnode_gpiod_get(of_fwnode_handle(matched_node), "reset", + GPIOD_OUT_HIGH, "nfcmrvl_reset_n"); + if (reset_gpio == ERR_PTR(-ENOENT)) { + reset_gpio = NULL; + } else if (IS_ERR(reset_gpio)) { of_node_put(matched_node); return PTR_ERR(reset_gpio); } @@ -119,7 +118,7 @@ static int nfcmrvl_nci_uart_open(struct nci_uart *nu) */ if (dev && dev->parent && dev->parent->of_node) - if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config, dev) == 0) + if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config) == 0) pdata = &config; if (!pdata) {
-- Git-157)