From patchwork Mon Jan 30 16:47:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 9545703 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 DC33360417 for ; Mon, 30 Jan 2017 16:51:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAFA120243 for ; Mon, 30 Jan 2017 16:51:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF8DC27E5A; Mon, 30 Jan 2017 16:51:07 +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=ham 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 848D220243 for ; Mon, 30 Jan 2017 16:51:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752768AbdA3Qsx (ORCPT ); Mon, 30 Jan 2017 11:48:53 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:33444 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751578AbdA3QsV (ORCPT ); Mon, 30 Jan 2017 11:48:21 -0500 Received: by mail-lf0-f65.google.com with SMTP id x1so31938113lff.0; Mon, 30 Jan 2017 08:48:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=Y8qFXfeyDW1tqC3iioH0dt+6wj13smP9NqERL7KKxwA=; b=npo19Yp2Jeco6ZEqO0WCUxtOZMyNtRJWtZRU/231nfvgFIlPH8dAPuOMo5ehhSXzrF Afhujp00duojxVHizw+xwsKs7ts/ItrDFDAM40GK1HA63l3Sx03SkAZHEapEvDKU3Zqf XBoVU9ssB7ZKjay53nL8ZN4iq6JPwmDKBFmBN06wFpKVX9rTG/7vb9XK/Ml9ZA7svnZM gzH/KOzb5Fw7hTLjj/Pg0Sh+r+tTgne3LeXsP+Ng+ovZocMMh4SjUYPf7GO7x949DXMs IEArsrT3Un++4OegEksu59t/e+Yq5UGvU2M6y8lwhTg1BNDbDR2DBgme/o5mn3U03+kQ YiuA== 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; bh=Y8qFXfeyDW1tqC3iioH0dt+6wj13smP9NqERL7KKxwA=; b=QI9PlD3b4Y0sLxwYJVptuX+Lhegf1x/XRa08c13PU09nzFqWFY8jjaNZZMyNbTs8A7 bUyUT94ZVCfAbG+pafE+uQjlKHna14ip43+lEPsnpadr0ORVL+yD8IW7HlmZuLAWkYDm NAnS/kO6FEFDYO0Uptzu1KuO60IM4PtxHckmsHU4YipApjMyRW2y/UmYMHKhmjyoYAeS /kemQzFYI8nnYk+WkJ/aigdRiFMwVuHURB9UJnpoQB00jVT00rHSO5YjPQ4qgb2pDOUt jw6ptFDlXz8KDtHzhQt2vyT1a+hIm5XexMgAZT/k6Cgx6kQOTEOGDwQmGqSJX2vBlMdQ YK4w== X-Gm-Message-State: AIkVDXKiouLj4g/tgHS4/YQEufNhfN+sFKBtan5RcJTP6ACsq5ZRc2rIpDu4dQ5nRNmoow== X-Received: by 10.25.215.103 with SMTP id o100mr7226974lfg.126.1485794899103; Mon, 30 Jan 2017 08:48:19 -0800 (PST) Received: from xi.terra ([84.216.234.102]) by smtp.gmail.com with ESMTPSA id h23sm3892102lji.34.2017.01.30.08.48.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jan 2017 08:48:18 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.88) (envelope-from ) id 1cYF7o-0005hn-LI; Mon, 30 Jan 2017 17:48:17 +0100 From: Johan Hovold To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH] spi: fix device-node leaks Date: Mon, 30 Jan 2017 17:47:05 +0100 Message-Id: <20170130164705.21727-1-johan@kernel.org> X-Mailer: git-send-email 2.10.2 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make sure to release the device-node reference taken in of_register_spi_device() on errors and when deregistering the device. Fixes: 284b01897340 ("spi: Add OF binding support for SPI busses") Signed-off-by: Johan Hovold --- drivers/spi/spi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 656dd3e3220c..730e3c9794db 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -621,8 +621,10 @@ void spi_unregister_device(struct spi_device *spi) if (!spi) return; - if (spi->dev.of_node) + if (spi->dev.of_node) { of_node_clear_flag(spi->dev.of_node, OF_POPULATED); + of_node_put(spi->dev.of_node); + } if (ACPI_COMPANION(&spi->dev)) acpi_device_clear_enumerated(ACPI_COMPANION(&spi->dev)); device_unregister(&spi->dev); @@ -1603,11 +1605,13 @@ of_register_spi_device(struct spi_master *master, struct device_node *nc) if (rc) { dev_err(&master->dev, "spi_device register error %s\n", nc->full_name); - goto err_out; + goto err_of_node_put; } return spi; +err_of_node_put: + of_node_put(nc); err_out: spi_dev_put(spi); return ERR_PTR(rc);