Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2061184imm; Thu, 24 May 2018 05:15:15 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqRWfj8L2KUd1QUObSlJjsrbP/wemHKwWNH9pLSKQb2kgiD2279D3+dePCQSjw623o/g5Wn X-Received: by 2002:a17:902:8307:: with SMTP id bd7-v6mr7152401plb.234.1527164115067; Thu, 24 May 2018 05:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527164115; cv=none; d=google.com; s=arc-20160816; b=vk02JvSTFvClT0frZxKP6g2gOtJ03vHCZrd1bXfJuXeZtxnoT9UstNqbW4AbTxigA9 DgKZDhz7j5wlJVW17Jt0fFIzzKNIsbF9dEbdhpAnw8B1ez75e+rCUFaAG3pBbPLQjfMh m8O3RSqH8MGFf/X8KpyH85ZD/cIPWaU/JBeoLi1FT3J3Upay92rA6e1Bbf/EqOdzbGXa nPBlX0+ZQ23xwLhzmoqBpW+HH7zpMDom8U6C4bpXR1/8ubAebdffPh4Ut8U7px2iz/jb Jtr4ujmSVDAfN0RjfVAqRLp57bk6m++YCcIx+w+AHcCh7pguheX+abhurMasLxowXdDd C25w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=kq7DSAL813vpB18SHm0L/zMCIfQZB7R7vnd5F/XDtAA=; b=iTxekhbPT8/2bk6psKbBHVDfk0irvigcFnDWILhJn2iVOtUqrCakZwi1zUp+CosVLv kz4KWiqVod6P9nWOQq0o6tb96WnFraWd1PA25t7qJS6DUB2iUgP9k2pByj5cBw5H8Raa ud3dsU5fVN4vFIv7bEDpao73+OnkJhIe6iFNavtyiP+/Vo+EBf7DCXBAm0SD59s38RBf Cx6BT8t3apwzthDh8JN9Efj3S4srJJpMPG/xbszh8LOmf7ZDBhh40SW3K/PFbkwyeafT Kfu2udXttmXXb0HtAOFxxSi3WecwL4i1pp2aPa+0Pyi1CpZQTlm3mayJTS9IxfIPWI39 ZBVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y7QVgXnD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n2-v6si21927612plk.433.2018.05.24.05.14.59; Thu, 24 May 2018 05:15:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y7QVgXnD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969755AbeEXMM4 (ORCPT + 99 others); Thu, 24 May 2018 08:12:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:54356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966387AbeEXJmr (ORCPT ); Thu, 24 May 2018 05:42:47 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DDE1A20893; Thu, 24 May 2018 09:42:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527154967; bh=lYedLDZeHdPubaHwu5bB5w8//P2Zd+BGNYKpa0epMHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y7QVgXnD7NOSVz81wP4FxeABJf99WuJ0Q2Av5KF+kSkciqBJAxpAwr/cHDUo7yBoK jXw0HqtpyxqQ9aImIIeWZ1vjNzmacduCxGHus5dXGaluTA9wRmoabYDgSrou1gNWIM zDNNasbfa2bc1Z9dxHBKTNJblYBHMorV1K0NWgXM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Khoroshilov , Valentina Manea Subject: [PATCH 3.18 26/45] usbip: fix error handling in stub_probe() Date: Thu, 24 May 2018 11:38:34 +0200 Message-Id: <20180524093123.951287727@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093120.599252450@linuxfoundation.org> References: <20180524093120.599252450@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexey Khoroshilov commit 3ff67445750a84de67faaf52c6e1895cb09f2c56 upstream. If usb_hub_claim_port() fails, no resources are deallocated and if stub_add_files() fails, port is not released. The patch fixes these issues and rearranges error handling code. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov Acked-by: Valentina Manea Signed-off-by: Greg Kroah-Hartman --- drivers/usb/usbip/stub_dev.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) --- a/drivers/usb/usbip/stub_dev.c +++ b/drivers/usb/usbip/stub_dev.c @@ -313,7 +313,6 @@ static int stub_probe(struct usb_device { struct stub_device *sdev = NULL; const char *udev_busid = dev_name(&udev->dev); - int err = 0; struct bus_id_priv *busid_priv; int rc; @@ -374,23 +373,28 @@ static int stub_probe(struct usb_device (struct usb_dev_state *) udev); if (rc) { dev_dbg(&udev->dev, "unable to claim port\n"); - return rc; + goto err_port; } - err = stub_add_files(&udev->dev); - if (err) { + rc = stub_add_files(&udev->dev); + if (rc) { dev_err(&udev->dev, "stub_add_files for %s\n", udev_busid); - dev_set_drvdata(&udev->dev, NULL); - usb_put_dev(udev); - kthread_stop_put(sdev->ud.eh); - - busid_priv->sdev = NULL; - stub_device_free(sdev); - return err; + goto err_files; } busid_priv->status = STUB_BUSID_ALLOC; return 0; +err_files: + usb_hub_release_port(udev->parent, udev->portnum, + (struct usb_dev_state *) udev); +err_port: + dev_set_drvdata(&udev->dev, NULL); + usb_put_dev(udev); + kthread_stop_put(sdev->ud.eh); + + busid_priv->sdev = NULL; + stub_device_free(sdev); + return rc; } static void shutdown_busid(struct bus_id_priv *busid_priv)