NFC: nfcmrvl: fix gpio-handling regression [Linux 4.19.66]

This Linux kernel change "NFC: nfcmrvl: fix gpio-handling regression" is included in the Linux 4.19.66 release. This change is authored by Johan Hovold <johan [at]> on Mon Aug 5 12:00:55 2019 +0200. The commit for this change in Linux stable tree is cd7f02f (patch) which is from upstream commit c3953a3. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream c3953a3.

NFC: nfcmrvl: fix gpio-handling regression

[ Upstream commit c3953a3c2d3175d2f9f0304c9a1ba89e7743c5e4 ]

Fix two reset-gpio sanity checks which were never converted to use
gpio_is_valid(), and make sure to use -EINVAL to indicate a missing
reset line also for the UART-driver module parameter and for the USB

This specifically prevents the UART and USB drivers from incidentally
trying to request and use gpio 0, and also avoids triggering a WARN() in
gpio_to_desc() during probe when no valid reset line has been specified.

Fixes: e33a3f84f88f ("NFC: nfcmrvl: allow gpio 0 for reset signalling")
Reported-by: [email protected]
Tested-by: [email protected]
Signed-off-by: Johan Hovold <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

There are 9 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/nfc/nfcmrvl/main.c | 4 ++--
 drivers/nfc/nfcmrvl/uart.c | 4 ++--
 drivers/nfc/nfcmrvl/usb.c  | 1 +
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/nfc/nfcmrvl/main.c b/drivers/nfc/nfcmrvl/main.c
index e65d027..529be35a 100644
--- a/drivers/nfc/nfcmrvl/main.c
+++ b/drivers/nfc/nfcmrvl/main.c
@@ -244,7 +244,7 @@ void nfcmrvl_chip_reset(struct nfcmrvl_private *priv)
    /* Reset possible fault of previous session */
    clear_bit(NFCMRVL_PHY_ERROR, &priv->flags);

-   if (priv->config.reset_n_io) {
+   if (gpio_is_valid(priv->config.reset_n_io)) {
        nfc_info(priv->dev, "reset the chip\n");
        gpio_set_value(priv->config.reset_n_io, 0);
        usleep_range(5000, 10000);
@@ -255,7 +255,7 @@ void nfcmrvl_chip_reset(struct nfcmrvl_private *priv)

 void nfcmrvl_chip_halt(struct nfcmrvl_private *priv)
-   if (priv->config.reset_n_io)
+   if (gpio_is_valid(priv->config.reset_n_io))
        gpio_set_value(priv->config.reset_n_io, 0);

diff --git a/drivers/nfc/nfcmrvl/uart.c b/drivers/nfc/nfcmrvl/uart.c
index 9a22056..e5a622c 100644
--- a/drivers/nfc/nfcmrvl/uart.c
+++ b/drivers/nfc/nfcmrvl/uart.c
@@ -26,7 +26,7 @@
 static unsigned int hci_muxed;
 static unsigned int flow_control;
 static unsigned int break_control;
-static unsigned int reset_n_io;
+static int reset_n_io = -EINVAL;

@@ -231,5 +231,5 @@ static void nfcmrvl_uart_exit_module(void)
 module_param(hci_muxed, uint, 0);
 MODULE_PARM_DESC(hci_muxed, "Tell if transport is muxed in HCI one.");

-module_param(reset_n_io, uint, 0);
+module_param(reset_n_io, int, 0);
 MODULE_PARM_DESC(reset_n_io, "GPIO that is wired to RESET_N signal.");
diff --git a/drivers/nfc/nfcmrvl/usb.c b/drivers/nfc/nfcmrvl/usb.c
index 945cc90..888e298 100644
--- a/drivers/nfc/nfcmrvl/usb.c
+++ b/drivers/nfc/nfcmrvl/usb.c
@@ -305,6 +305,7 @@ static int nfcmrvl_probe(struct usb_interface *intf,

    /* No configuration for USB */
    memset(&config, 0, sizeof(config));
+   config.reset_n_io = -EINVAL;

    nfc_info(&udev->dev, "intf %p id %p\n", intf, id);

Leave a Reply

Your email address will not be published. Required fields are marked *