From patchwork Mon Apr 10 13:51:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Klauser X-Patchwork-Id: 9672693 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 8D4E3600CB for ; Mon, 10 Apr 2017 13:51:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F58D27CAF for ; Mon, 10 Apr 2017 13:51:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 739AD2845F; Mon, 10 Apr 2017 13: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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 6C3BA27CAF for ; Mon, 10 Apr 2017 13:51:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752841AbdDJNvG (ORCPT ); Mon, 10 Apr 2017 09:51:06 -0400 Received: from mail.zhinst.com ([212.126.164.98]:51252 "EHLO mail.zhinst.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752518AbdDJNvF (ORCPT ); Mon, 10 Apr 2017 09:51:05 -0400 Received: from ziws08.zhinst.com ([10.42.0.7]) by mail.zhinst.com (Kerio Connect 9.2.2 patch 1) with ESMTP; Mon, 10 Apr 2017 15:51:03 +0200 From: Tobias Klauser To: Alan Tull , Moritz Fischer Cc: linux-fpga@vger.kernel.org Subject: [PATCH] fpga: region: release FPGA region reference in error path Date: Mon, 10 Apr 2017 15:51:03 +0200 Message-Id: <20170410135103.18612-1-tklauser@distanz.ch> X-Mailer: git-send-email 2.12.2 Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If fpga_region_get_manager() fails in fpga_region_program_fpga(), a reference to the fpga_manager instance previously acquired through fpga_region_get() is retained. Make sure to properly release it in the error case by using a separate jump label which will call fpga_region_put() in before returning. Signed-off-by: Tobias Klauser Acked-by: Moritz Fischer Signed-off-by: Alan Tull --- drivers/fpga/fpga-region.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c index ae4c61aada99..3b6b2f4182a1 100644 --- a/drivers/fpga/fpga-region.c +++ b/drivers/fpga/fpga-region.c @@ -245,7 +245,8 @@ static int fpga_region_program_fpga(struct fpga_region *region, mgr = fpga_region_get_manager(region); if (IS_ERR(mgr)) { pr_err("failed to get fpga region manager\n"); - return PTR_ERR(mgr); + ret = PTR_ERR(mgr); + goto err_put_region; } ret = fpga_region_get_bridges(region, overlay); @@ -281,6 +282,7 @@ static int fpga_region_program_fpga(struct fpga_region *region, fpga_bridges_put(®ion->bridge_list); err_put_mgr: fpga_mgr_put(mgr); +err_put_region: fpga_region_put(region); return ret;