Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2052929imm; Thu, 24 May 2018 05:08:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZowABTp4oByTuxwafHltrTQvKlY/uQ659JRsv7MfLR7C/Fpd33/n1jPz0adLfitB+A2fHs0 X-Received: by 2002:a65:48c9:: with SMTP id o9-v6mr5803908pgs.106.1527163698108; Thu, 24 May 2018 05:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527163698; cv=none; d=google.com; s=arc-20160816; b=sjDdn6eZEgzmkHTJTh2EjHkjgW+F37vKMch9LYv12tZGg6zkky+bl3dsR2xqYvGC4o 8o4pnuvt1pasOiEMjPNWfwaowh4FnYEY8cRPXXoIbe49IcUE3lcp9+dv+67ND0Zm1H/J GFKAQfgj6cYtFLgVUexwxUfRDWdsJfeij2dThs42+aic/mMfJ3BBlZ//q//key5HqLet c62hzlXg+KP+YvBfMggPCSnwL1msM/IHGXdBu3o+Q1OnpFIvSWYiXFBq7zcQKGsxp+/X Zg3UX41K3bx+nV1Klptdjrxn5zc6Vf0Y4fRlt10f22Z11//Sj9bMZuV8somYHX+bk4uq /RXA== 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=Prv/RnUiAv17z0H7Ldy3uvdCMlXtcYUq/H1e6bvHJCs=; b=tqOQpbv+MAAx85EYCCk56j2tjPGuqFtK/nQxVkEcDs419KmKydI3O9a0IVY7o9B5o8 6i58PKfZmZv+yD+fPyvPtuuLVe4/IM9ObOvI6ELbKoxzvFF8eay7gp9lGtZKJAzj2swt 0ibkhkSpZ32Ss5QXag6KccSxQedjeIcgA6w6t9kcnbCnSoBsnmj5TcoiJ+PSp/+4BNMe eYNM5YTvdx8yonzFKkljjizrwzso3hLelzLusuHj6CejKzrOsVNn1ImzOfimlD+A0o4q kJv9gllBtVDxkTWhX2lsTIMdE32F6sk/iiq97pskwXij6je0ZPJUzVE6XC/ADtjoRAZF 8GdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GEqC9ofZ; 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 r76-v6si20526335pfb.65.2018.05.24.05.08.03; Thu, 24 May 2018 05:08:18 -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=GEqC9ofZ; 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 S969593AbeEXMF5 (ORCPT + 99 others); Thu, 24 May 2018 08:05:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:55516 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966321AbeEXJoK (ORCPT ); Thu, 24 May 2018 05:44:10 -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 2B9582087E; Thu, 24 May 2018 09:44:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155049; bh=EzSlWyqagi7a0rI2hEdzgeA6ix7Rx3EdKtzjHmz1QTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GEqC9ofZpBn08DDWDyjbVUcyybo5KtJ/MkyHQBjIjMGbWTYFJ7JbemBfkHSvDQ2bd hRu+dzyK+Ufxt6svaqqj+acHFVhkU9a+qnitRJVwfbej9d6aW4OYUDD8xT02114lOo Sog6jh7ck5qiKHMEYojPBJImTmCE1jbpvjEA3UC4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Shuah Khan (Samsung OSG)" Subject: [PATCH 4.4 35/92] usbip: usbip_host: run rebind from exit when module is removed Date: Thu, 24 May 2018 11:38:12 +0200 Message-Id: <20180524093202.285951462@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093159.286472249@linuxfoundation.org> References: <20180524093159.286472249@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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shuah Khan (Samsung OSG) commit 7510df3f29d44685bab7b1918b61a8ccd57126a9 upstream. After removing usbip_host module, devices it releases are left without a driver. For example, when a keyboard or a mass storage device are bound to usbip_host when it is removed, these devices are no longer bound to any driver. Fix it to run device_attach() from the module exit routine to restore the devices to their original drivers. This includes cleanup changes and moving device_attach() code to a common routine to be called from rebind_store() and usbip_host_exit(). Signed-off-by: Shuah Khan (Samsung OSG) Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/usbip/stub_dev.c | 6 ---- drivers/usb/usbip/stub_main.c | 60 +++++++++++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 14 deletions(-) --- a/drivers/usb/usbip/stub_dev.c +++ b/drivers/usb/usbip/stub_dev.c @@ -463,12 +463,8 @@ static void stub_disconnect(struct usb_d busid_priv->sdev = NULL; stub_device_free(sdev); - if (busid_priv->status == STUB_BUSID_ALLOC) { + if (busid_priv->status == STUB_BUSID_ALLOC) busid_priv->status = STUB_BUSID_ADDED; - } else { - busid_priv->status = STUB_BUSID_OTHER; - del_match_busid((char *)udev_busid); - } } #ifdef CONFIG_PM --- a/drivers/usb/usbip/stub_main.c +++ b/drivers/usb/usbip/stub_main.c @@ -28,6 +28,7 @@ #define DRIVER_DESC "USB/IP Host Driver" struct kmem_cache *stub_priv_cache; + /* * busid_tables defines matching busids that usbip can grab. A user can change * dynamically what device is locally used and what device is exported to a @@ -184,6 +185,51 @@ static ssize_t store_match_busid(struct static DRIVER_ATTR(match_busid, S_IRUSR | S_IWUSR, show_match_busid, store_match_busid); +static int do_rebind(char *busid, struct bus_id_priv *busid_priv) +{ + int ret; + + /* device_attach() callers should hold parent lock for USB */ + if (busid_priv->udev->dev.parent) + device_lock(busid_priv->udev->dev.parent); + ret = device_attach(&busid_priv->udev->dev); + if (busid_priv->udev->dev.parent) + device_unlock(busid_priv->udev->dev.parent); + if (ret < 0) { + dev_err(&busid_priv->udev->dev, "rebind failed\n"); + return ret; + } + return 0; +} + +static void stub_device_rebind(void) +{ +#if IS_MODULE(CONFIG_USBIP_HOST) + struct bus_id_priv *busid_priv; + int i; + + /* update status to STUB_BUSID_OTHER so probe ignores the device */ + spin_lock(&busid_table_lock); + for (i = 0; i < MAX_BUSID; i++) { + if (busid_table[i].name[0] && + busid_table[i].shutdown_busid) { + busid_priv = &(busid_table[i]); + busid_priv->status = STUB_BUSID_OTHER; + } + } + spin_unlock(&busid_table_lock); + + /* now run rebind */ + for (i = 0; i < MAX_BUSID; i++) { + if (busid_table[i].name[0] && + busid_table[i].shutdown_busid) { + busid_priv = &(busid_table[i]); + do_rebind(busid_table[i].name, busid_priv); + } + } +#endif +} + static ssize_t rebind_store(struct device_driver *dev, const char *buf, size_t count) { @@ -204,16 +250,9 @@ static ssize_t rebind_store(struct devic /* mark the device for deletion so probe ignores it during rescan */ bid->status = STUB_BUSID_OTHER; - /* device_attach() callers should hold parent lock for USB */ - if (bid->udev->dev.parent) - device_lock(bid->udev->dev.parent); - ret = device_attach(&bid->udev->dev); - if (bid->udev->dev.parent) - device_unlock(bid->udev->dev.parent); - if (ret < 0) { - dev_err(&bid->udev->dev, "rebind failed\n"); + ret = do_rebind((char *) buf, bid); + if (ret < 0) return ret; - } /* delete device from busid_table */ del_match_busid((char *) buf); @@ -339,6 +378,9 @@ static void __exit usbip_host_exit(void) */ usb_deregister_device_driver(&stub_driver); + /* initiate scan to attach devices */ + stub_device_rebind(); + kmem_cache_destroy(stub_priv_cache); }