Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3321945imu; Sun, 11 Nov 2018 12:20:07 -0800 (PST) X-Google-Smtp-Source: AJdET5cz7t2K7uIQIVgXz0Y0rG741GTbZkEsVijRmlHZ45xSksb2PzP/SA4aEmI1Sf3dLZv2Pfr7 X-Received: by 2002:a17:902:b18c:: with SMTP id s12-v6mr16915870plr.16.1541967607677; Sun, 11 Nov 2018 12:20:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541967607; cv=none; d=google.com; s=arc-20160816; b=WVgcqXnQRxSENcs4VzLmuqQCW3mOQe0uGZV2xtG6Bre2eufe3MPP6tvj2WAnv4yG2p nUfdMhrDVLI0StcQTBQxN3lJIgkZW0fZOJ8k5VBtBXrXYYt64oRPW4mzX02tuQrC/elT Xfg0k6BVPLKKaVPci2+S1TMYHzq2UnMvTTQys8fIFpZrklD2EzUcJ3ofZUrMrqMDYD4i hsKE5c0sol8QQp0Rob6sKeIKBxVvrqwp0Q+ddRnAhTHdkQCXDix4Rmk0B3kt5VSsNDzc 59TLHl2H8NLofgO0b5W2j5KoC0tg2b+q2kyuloM77CbQ/NOSHoheSTdeuzi8qkS7Ex8b lt6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=lGDkt9XFK4bPUd46i4gC06oPlG6slOT9Pzo0HW5J2iE=; b=Ul/qjsg3tHNH1smjCnmH4e2of5Ti3S3am/QYkqIEK49Sh4uMAHNLLYB6jB0+J2iJbR vBhc6RY2BKs+vg/MbnjfBfSUIKPRyqZ6q9cAC+b5k5d0n7RWSc2sMiRJHJoJbP0ZY4fS KXvg4LwuEVKGgYQo7tuB74iQHkzYZbVfLYT5EFB97waaDKUPL/IJ2xCdwtU8ujP82mwQ 1/pLDbGuMBSlegZpEAbfppjV02h9LV1EfBlF9sh1zs0oe9WSZa1jS1owb8d/WENHJV/X tpMpQT/jDrKM+DrUMr7jfP3dr+vxahsJOFGqHg7rL8yF1RCVltg1qymNTKHungh0kGyM qE/g== ARC-Authentication-Results: i=1; mx.google.com; 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 u21si13862123pgg.463.2018.11.11.12.19.52; Sun, 11 Nov 2018 12:20:07 -0800 (PST) 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; 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 S1731854AbeKLGFc (ORCPT + 99 others); Mon, 12 Nov 2018 01:05:32 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:53100 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731493AbeKLGFb (ORCPT ); Mon, 12 Nov 2018 01:05:31 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvt6-0000oF-OU; Sun, 11 Nov 2018 19:59:16 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsQ-0001TS-AJ; Sun, 11 Nov 2018 19:58:34 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Felipe Balbi" , "Yoshihiro Shimoda" , "Greg Kroah-Hartman" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 086/366] usb: gadget: function: printer: avoid wrong list handling in printer_write() In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Yoshihiro Shimoda commit 4a014a7339f441b0851ce012f469c0fadac61c81 upstream. When printer_write() calls usb_ep_queue(), a udc driver (e.g. renesas_usbhs driver) may call usb_gadget_giveback_request() in the udc .queue ops immediately. Then, printer_write() calls list_add(&req->list, &dev->tx_reqs_active) wrongly. After that, if we do unbind the printer driver, WARN_ON() happens in printer_func_unbind() because the list entry is not removed. So, this patch moves list_add(&req->list, &dev->tx_reqs_active) calling before usb_ep_queue(). Signed-off-by: Yoshihiro Shimoda Acked-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman [bwh: Backported to 3.16: adjust filename] Signed-off-by: Ben Hutchings --- drivers/usb/gadget/printer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/usb/gadget/printer.c +++ b/drivers/usb/gadget/printer.c @@ -667,19 +667,19 @@ printer_write(struct file *fd, const cha return -EAGAIN; } + list_add(&req->list, &dev->tx_reqs_active); + /* here, we unlock, and only unlock, to avoid deadlock. */ spin_unlock(&dev->lock); value = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC); spin_lock(&dev->lock); if (value) { + list_del(&req->list); list_add(&req->list, &dev->tx_reqs); spin_unlock_irqrestore(&dev->lock, flags); mutex_unlock(&dev->lock_printer_io); return -EAGAIN; } - - list_add(&req->list, &dev->tx_reqs_active); - } spin_unlock_irqrestore(&dev->lock, flags);