From patchwork Thu Mar 30 10:15:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 9653629 X-Patchwork-Delegate: sameo@linux.intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A028560349 for ; Thu, 30 Mar 2017 10:23:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8ADB028531 for ; Thu, 30 Mar 2017 10:23:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FA1D2853B; Thu, 30 Mar 2017 10:23:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0497128531 for ; Thu, 30 Mar 2017 10:23:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933235AbdC3KWV (ORCPT ); Thu, 30 Mar 2017 06:22:21 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:32875 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933040AbdC3KQE (ORCPT ); Thu, 30 Mar 2017 06:16:04 -0400 Received: by mail-lf0-f65.google.com with SMTP id r36so4146371lfi.0; Thu, 30 Mar 2017 03:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=fDMwBjY8eCQlaz+IgnmI/cCAE4G+tNR1aK4N3qhqMi8=; b=Zu3ycAo/CbKYa3+OaPgvUpWL7fnCzYc3r8RZfgHno/Rd7GA8MfzQdx2vVoy+7F3wkP TnYFo7VV1T8VYZf9V1olC6bNvgkhI6RyeKGuJYbpQR97qDyLFjXQlrzajhb4dZY4im0F V23XUWZ34tCEadIK+JoIXD8gAwKWqDVDK7rTKTF7Xgs/QhvEOFlBgoiPNoVsiM5EbZr6 Psxs8sbCoD5fpVHhtbl89BJKq0GtPGJsS3NP1I38HyDFfY+G1b49iHOXODFvINZR92GT 7tUTQUu0CONuFynPlTG5NqciuLJUjdXva370WbULAL6W/V0rV5x7P/UexnS7qbUwZpQu JOKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=fDMwBjY8eCQlaz+IgnmI/cCAE4G+tNR1aK4N3qhqMi8=; b=oLP7OELdrvzJ6Wwzavusmvqw2znhhUML090Mswp967gKxnBeRZ5fBdgdBfhIxwtVgq q6o3WfOqYGghRyR+SA4PXtK4RP6sqkiqQuP28F3GmjKppv8ke5LaGK1GDzZPxriWsQRm wdr7dN7eBAnM9VleHKUp2Q1zQHTPZUxiYoyNAnOkDQZ0091Ua4R8VZO7HNfoHkzPHRYT rNJMAQhq9LG23HRZHCxBXkQDQa6ADVyhmjFz4+GPxpbxbrT9i0MQQAoV8Qun7usmFXT+ yWQ6Sg40U3+BNSsabQJAIoiug+jPUYc/KSycBpxdzWPhFFD/m3sTwMhI/BRQ6ssMl/Dv N9gQ== X-Gm-Message-State: AFeK/H1pfAEqpGjICjZQzs3KcOeQM9DVDWJR7zYR3mwy6TadrnkHKM2eC9Pq+b8lHOqe+w== X-Received: by 10.25.155.132 with SMTP id d126mr1735103lfe.110.1490868961951; Thu, 30 Mar 2017 03:16:01 -0700 (PDT) Received: from xi.terra ([84.216.234.102]) by smtp.gmail.com with ESMTPSA id y25sm300844lja.7.2017.03.30.03.15.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 03:16:00 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.89) (envelope-from ) id 1ctX7R-00041B-Aj; Thu, 30 Mar 2017 12:15:53 +0200 From: Johan Hovold To: Lauro Ramos Venancio , Aloisio Almeida Jr , Samuel Ortiz Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable , Vincent Cuissard Subject: [PATCH v2 3/8] NFC: nfcmrvl: do not use device-managed resources Date: Thu, 30 Mar 2017 12:15:37 +0200 Message-Id: <20170330101542.15384-4-johan@kernel.org> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170330101542.15384-1-johan@kernel.org> References: <20170330101542.15384-1-johan@kernel.org> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This specifically fixes resource leaks in the registration error paths. Device-managed resources is a bad fit for this driver as devices can be registered from the n_nci line discipline. Firstly, a tty may not even have a corresponding device (should it be part of a Unix98 pty) something which would lead to a NULL-pointer dereference when registering resources. Secondly, if the tty has a class device, its lifetime exceeds that of the line discipline, which means that resources would leak every time the line discipline is closed (or if registration fails). Currently, the devres interface was only being used to request a reset gpio despite the fact that it was already explicitly freed in nfcmrvl_nci_unregister_dev() (along with the private data), something which also prevented the resource leak at close. Note that the driver treats gpio number 0 as invalid despite it being perfectly valid. This will be addressed in a follow-up patch. Fixes: b2fe288eac72 ("NFC: nfcmrvl: free reset gpio") Fixes: 4a2b947f56b3 ("NFC: nfcmrvl: add chip reset management") Cc: stable # 4.2: b2fe288eac72 Cc: Vincent Cuissard Signed-off-by: Johan Hovold --- drivers/nfc/nfcmrvl/main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/nfc/nfcmrvl/main.c b/drivers/nfc/nfcmrvl/main.c index 51c8240a1672..3e3fc9588f10 100644 --- a/drivers/nfc/nfcmrvl/main.c +++ b/drivers/nfc/nfcmrvl/main.c @@ -124,12 +124,13 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy, memcpy(&priv->config, pdata, sizeof(*pdata)); if (priv->config.reset_n_io) { - rc = devm_gpio_request_one(dev, - priv->config.reset_n_io, - GPIOF_OUT_INIT_LOW, - "nfcmrvl_reset_n"); - if (rc < 0) + rc = gpio_request_one(priv->config.reset_n_io, + GPIOF_OUT_INIT_LOW, + "nfcmrvl_reset_n"); + if (rc < 0) { + priv->config.reset_n_io = 0; nfc_err(dev, "failed to request reset_n io\n"); + } } if (phy == NFCMRVL_PHY_SPI) { @@ -154,7 +155,7 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy, if (!priv->ndev) { nfc_err(dev, "nci_allocate_device failed\n"); rc = -ENOMEM; - goto error; + goto error_free_gpio; } nci_set_drvdata(priv->ndev, priv); @@ -179,7 +180,9 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy, error_free_dev: nci_free_device(priv->ndev); -error: +error_free_gpio: + if (priv->config.reset_n_io) + gpio_free(priv->config.reset_n_io); kfree(priv); return ERR_PTR(rc); } @@ -195,7 +198,7 @@ void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv) nfcmrvl_fw_dnld_deinit(priv); if (priv->config.reset_n_io) - devm_gpio_free(priv->dev, priv->config.reset_n_io); + gpio_free(priv->config.reset_n_io); nci_unregister_device(ndev); nci_free_device(ndev);