Message ID | 20240228111521.3864-1-WeitaoWang-oc@zhaoxin.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-84463-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3110129dyb; Tue, 27 Feb 2024 19:16:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVU765vc1TrhqEGG9x6Oe2EMjxO/1YO7CR/PoSpPUAg0RnfUqK/oNsTJyGj8zG083hix2vcKeha0gx6cO76vv50ejpHuA== X-Google-Smtp-Source: AGHT+IHk1JYdopIxbi4ap1X8/oS4lXLpWJvtoD589j29HWhDLrD6d9EFY/P8h8aCaLQUuSVR6VVw X-Received: by 2002:a0c:f093:0:b0:690:47b:66d with SMTP id g19-20020a0cf093000000b00690047b066dmr3470329qvk.34.1709090168707; Tue, 27 Feb 2024 19:16:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709090168; cv=pass; d=google.com; s=arc-20160816; b=NpR86stZcwpwocWnw9saOgsl4Z/qvkPGxvVxRvaYP3oQayTyyQ/gK+SnQ2nnkaemIw RBhOBi0oHcbk3TmswV75rkvNghf72IocebQljyNQDeuNg0C99CfGn5McWzpSzEr1bR9z XLDGRh6nDPwpvs3du6VBEzwguxB7hb9q0xf/hXSnaTkXi7LuHGgmLxgpG4MS2uYUgVgW d3bda4kJdgtFp0uBTBSRQB90fjJgOf2ERpDtu22MGPJBb53haABbNJsJ7RAH7BB4lx57 ht8OXrZoNLji+V1cE9UsFee3mjuk7e4UAKp5jHM1FGB/+G+Mc80DmoPbJLv1T9b/Idlb qOWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=oKrNZuVBtDWuVPFr7vgnh2x04aSdjo/zXgxSAgNNjXA=; fh=FD4mKGy1ME82NXzsAuqqkN3U42pO0UI7+8Bexdoq69o=; b=s/tIHx/tcxc2vmwli6pBu2p8PTOFrMUZ41sdvWTjt3wD6Iw1MhFz2SI8Mo1BZT3Kw1 I0dqLSvxeaUtdZfhmtWJZr2pXfoP5E027Ncjg5u4/y1sIjZ1R254I77aWhLXPZmVAOdA iB5Z2EKmGxm8MZL8pMo7LpQdPVig/1YtItL7nWYpqBnK9oxNJiaty1almXrGPscJr3Tq MrbwVNRQwxzRGVNJO8IA7G6l1Hd4RYNqMjgHDbZ9M1ukoEZfKy83235kq/ILVyGCiwDi EGTNDhlt++VCNIHyCBOnGJ/eEdkLmXejWW70msaGckyLBksOocA4cQfAs4ebHDfDWiGe PxrA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=zhaoxin.com); spf=pass (google.com: domain of linux-kernel+bounces-84463-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84463-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f4-20020a0562141d2400b0068cbacd748fsi8929895qvd.520.2024.02.27.19.16.08 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 19:16:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84463-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zhaoxin.com); spf=pass (google.com: domain of linux-kernel+bounces-84463-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84463-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D36B11C25C5C for <ouuuleilei@gmail.com>; Wed, 28 Feb 2024 03:15:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5CE65200BA; Wed, 28 Feb 2024 03:15:31 +0000 (UTC) Received: from mx2.zhaoxin.com (mx2.zhaoxin.com [203.110.167.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40B511D681 for <linux-kernel@vger.kernel.org>; Wed, 28 Feb 2024 03:15:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.110.167.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709090129; cv=none; b=uY8MOMmnpe3KmwnKg9B8UT/DGVXqIDi3vu1Ci8YgXJl/o/gRawzIunB7LIM+CzbKKqqbHpNsq2T0ojtELS0eJB3CeCr0JgfprCeNKXc514wGWaaWfWsrg3GIRIPp+rOBBg2VD82QpE4NO4F9W1ipNYZpzdlJepuuYmFcaXzVwZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709090129; c=relaxed/simple; bh=fwjCOVuAe1e0TdDrUgm6xmn/efGbI2EduGdh+QYbqnk=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=UmcZmAMbc4B46TRVhmoC7GvUAiUkhge/PYCvWXIcW4QwM5KYV29ajEjHFm4id+HVbduPN89E6YCuTW+s0m35abbW65tXcYSCiwn958wl5jjkdxqqgKqPQ7njfaR99DB1mraOZcdiy9G1ryroTv5y4dGrrDBgqWXI7mimleSaMC0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com; spf=pass smtp.mailfrom=zhaoxin.com; arc=none smtp.client-ip=203.110.167.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zhaoxin.com X-ASG-Debug-ID: 1709090121-1eb14e0c7f4b750001-xx1T2L Received: from ZXSHMBX1.zhaoxin.com (ZXSHMBX1.zhaoxin.com [10.28.252.163]) by mx2.zhaoxin.com with ESMTP id J4vELxcXT5Px1eGw (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Wed, 28 Feb 2024 11:15:21 +0800 (CST) X-Barracuda-Envelope-From: WeitaoWang-oc@zhaoxin.com X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.163 Received: from zxbjmbx1.zhaoxin.com (10.29.252.163) by ZXSHMBX1.zhaoxin.com (10.28.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 28 Feb 2024 11:15:21 +0800 Received: from L440.zhaoxin.com (10.29.8.21) by zxbjmbx1.zhaoxin.com (10.29.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 28 Feb 2024 11:15:20 +0800 X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.163 From: Weitao Wang <WeitaoWang-oc@zhaoxin.com> X-Barracuda-RBL-Trusted-Forwarder: 10.29.252.163 To: <oneukum@suse.com>, <stern@rowland.harvard.edu>, <gregkh@linuxfoundation.org>, <linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linux-scsi@vger.kernel.org>, <usb-storage@lists.one-eyed-alien.net> CC: <WeitaoWang@zhaoxin.com>, <stable@vger.kernel.org> Subject: [PATCH v2] USB:UAS:return ENODEV when submit urbs fail with device not attached. Date: Wed, 28 Feb 2024 19:15:21 +0800 X-ASG-Orig-Subj: [PATCH v2] USB:UAS:return ENODEV when submit urbs fail with device not attached. Message-ID: <20240228111521.3864-1-WeitaoWang-oc@zhaoxin.com> X-Mailer: git-send-email 2.32.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: zxbjmbx1.zhaoxin.com (10.29.252.163) To zxbjmbx1.zhaoxin.com (10.29.252.163) X-Barracuda-Connect: ZXSHMBX1.zhaoxin.com[10.28.252.163] X-Barracuda-Start-Time: 1709090121 X-Barracuda-Encrypted: ECDHE-RSA-AES128-GCM-SHA256 X-Barracuda-URL: https://10.28.252.36:4443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at zhaoxin.com X-Barracuda-Scan-Msg-Size: 4337 X-Barracuda-BRTS-Status: 1 X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Spam-Score: 1.09 X-Barracuda-Spam-Status: No, SCORE=1.09 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests=DATE_IN_FUTURE_06_12, DATE_IN_FUTURE_06_12_2 X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.121424 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.01 DATE_IN_FUTURE_06_12 Date: is 6 to 12 hours after Received: date 3.10 DATE_IN_FUTURE_06_12_2 DATE_IN_FUTURE_06_12_2 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792110932370136739 X-GMAIL-MSGID: 1792110932370136739 |
Series |
[v2] USB:UAS:return ENODEV when submit urbs fail with device not attached.
|
|
Commit Message
Weitao Wang
Feb. 28, 2024, 11:15 a.m. UTC
In the scenario of entering hibernation with udisk in the system, if the
udisk was gone or resume fail in the thaw phase of hibernation. Its state
will be set to NOTATTACHED. At this point, usb_hub_wq was already freezed
and can't not handle disconnect event. Next, in the poweroff phase of
hibernation, SYNCHRONIZE_CACHE SCSI command will be sent to this udisk
when poweroff this scsi device, which will cause uas_submit_urbs to be
called to submit URB for sense/data/cmd pipe. However, these URBs will
submit fail as device was set to NOTATTACHED state. Then, uas_submit_urbs
will return a value SCSI_MLQUEUE_DEVICE_BUSY to the caller. That will lead
the SCSI layer go into an ugly loop and system fail to go into hibernation.
On the other hand, when we specially check for -ENODEV in function
uas_queuecommand_lck, returning DID_ERROR to SCSI layer will cause device
poweroff fail and system shutdown instead of entering hibernation.
To fix this issue, let uas_submit_urbs function to return a value -ENODEV
when submit URB fail with device in NOTATTACHED state. At the same time,
we need to translate -ENODEV to DID_NOT_CONNECT for the SCSI layer.
Cc: stable@vger.kernel.org
Signed-off-by: Weitao Wang <WeitaoWang-oc@zhaoxin.com>
---
v1->v2
- Modify the description of this patch.
drivers/usb/storage/uas.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
Comments
On 28.02.24 12:15, Weitao Wang wrote: Hi, sorry for going at this again, but there are a few technical issues left. Regards Oliver > --- > v1->v2 > - Modify the description of this patch. > > drivers/usb/storage/uas.c | 21 ++++++++++----------- > 1 file changed, 10 insertions(+), 11 deletions(-) > > diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c > index 9707f53cfda9..967f18db525a 100644 > --- a/drivers/usb/storage/uas.c > +++ b/drivers/usb/storage/uas.c > @@ -562,9 +561,9 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, > > lockdep_assert_held(&devinfo->lock); > if (cmdinfo->state & SUBMIT_STATUS_URB) { > - urb = uas_submit_sense_urb(cmnd, GFP_ATOMIC); > - if (!urb) > - return SCSI_MLQUEUE_DEVICE_BUSY; > + err = uas_submit_sense_urb(cmnd, GFP_ATOMIC); > + if (err) > + return (err == -ENODEV) ? -ENODEV : SCSI_MLQUEUE_DEVICE_BUSY; Either we ought to use SCSI error codes or generic error codes. There is no need to translate all but one error condition here. > cmdinfo->state &= ~SUBMIT_STATUS_URB; > } > > @@ -582,7 +581,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, > if (err) { > usb_unanchor_urb(cmdinfo->data_in_urb); > uas_log_cmd_state(cmnd, "data in submit err", err); > - return SCSI_MLQUEUE_DEVICE_BUSY; > + return (err == -ENODEV) ? -ENODEV : SCSI_MLQUEUE_DEVICE_BUSY; Same as above and below.
On 28.02.24 23:32, WeitaoWang-oc@zhaoxin.com wrote: > @@ -602,6 +606,8 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, > if (err) { > usb_unanchor_urb(cmdinfo->data_out_urb); > uas_log_cmd_state(cmnd, "data out submit err", err); > + if (err == -ENODEV) > + return -ENODEV; This is a generic error code from errno.h > return SCSI_MLQUEUE_DEVICE_BUSY; This is not. > } > cmdinfo->state &= ~SUBMIT_DATA_OUT_URB; > @@ -621,6 +627,8 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, > if (err) { > usb_unanchor_urb(cmdinfo->cmd_urb); > uas_log_cmd_state(cmnd, "cmd submit err", err); > + if (err == -ENODEV) > + return -ENODEV; > return SCSI_MLQUEUE_DEVICE_BUSY; > } > > I'm not sure I fully understand what your mean. > Whether the above code is more reasonable? If not,could you give me some > suggestion? Thanks for your help! You want to change uas_submit_urbs() to return the reason for errors, because -ENODEV needs to be handled differently. That is good. But why don't you just do return err; unconditionally? There is no point in using SCSI_MLQUEUE_DEVICE_BUSY Regards Oliver
On 2024/2/28 16:00, Oliver Neukum wrote: > >> @@ -562,9 +561,9 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, >> >> lockdep_assert_held(&devinfo->lock); >> if (cmdinfo->state & SUBMIT_STATUS_URB) { >> - urb = uas_submit_sense_urb(cmnd, GFP_ATOMIC); >> - if (!urb) >> - return SCSI_MLQUEUE_DEVICE_BUSY; >> + err = uas_submit_sense_urb(cmnd, GFP_ATOMIC); >> + if (err) >> + return (err == -ENODEV) ? -ENODEV : SCSI_MLQUEUE_DEVICE_BUSY; > > Either we ought to use SCSI error codes or generic error codes. > There is no need to translate all but one error condition here. > static int uas_submit_urbs(struct scsi_cmnd *cmnd, @@ -562,10 +561,13 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, lockdep_assert_held(&devinfo->lock); if (cmdinfo->state & SUBMIT_STATUS_URB) { - urb = uas_submit_sense_urb(cmnd, GFP_ATOMIC); - if (!urb) + err = uas_submit_sense_urb(cmnd, GFP_ATOMIC); + if (!err) + cmdinfo->state &= ~SUBMIT_STATUS_URB; + else if (err == -ENODEV) + return -ENODEV; + else return SCSI_MLQUEUE_DEVICE_BUSY; - cmdinfo->state &= ~SUBMIT_STATUS_URB; } if (cmdinfo->state & ALLOC_DATA_IN_URB) { @@ -582,6 +584,8 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, if (err) { usb_unanchor_urb(cmdinfo->data_in_urb); uas_log_cmd_state(cmnd, "data in submit err", err); + if (err == -ENODEV) + return -ENODEV; return SCSI_MLQUEUE_DEVICE_BUSY; } cmdinfo->state &= ~SUBMIT_DATA_IN_URB; @@ -602,6 +606,8 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, if (err) { usb_unanchor_urb(cmdinfo->data_out_urb); uas_log_cmd_state(cmnd, "data out submit err", err); + if (err == -ENODEV) + return -ENODEV; return SCSI_MLQUEUE_DEVICE_BUSY; } cmdinfo->state &= ~SUBMIT_DATA_OUT_URB; @@ -621,6 +627,8 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, if (err) { usb_unanchor_urb(cmdinfo->cmd_urb); uas_log_cmd_state(cmnd, "cmd submit err", err); + if (err == -ENODEV) + return -ENODEV; return SCSI_MLQUEUE_DEVICE_BUSY; } I'm not sure I fully understand what your mean. Whether the above code is more reasonable? If not,could you give me some suggestion? Thanks for your help! Weitao
On 29.02.24 12:19, WeitaoWang-oc@zhaoxin.com wrote: > When alloc urb fail in the same function uas_submit_urbs, > whether we should replace SCSI_MLQUEUE_DEVICE_BUSY with generic > error code -ENOMEM? Such like this: > > @@ -572,7 +571,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, > cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC, > cmnd, DMA_FROM_DEVICE); > if (!cmdinfo->data_in_urb) > - return SCSI_MLQUEUE_DEVICE_BUSY; > + return -ENOMEM; > cmdinfo->state &= ~ALLOC_DATA_IN_URB; > } Hi, yes, and then you translate in one central place for the SCSI layer into DID_ERROR or DID_NO_CONNECT. Regards Oliver
On 29.02.24 17:40, WeitaoWang-oc@zhaoxin.com wrote:
> OK, I'll submit a new version after you help to review the following patch.
Hi,
perfect.
Regards
Oliver
On 2024/2/28 22:47, Oliver Neukum wrote: >> I'm not sure I fully understand what your mean. >> Whether the above code is more reasonable? If not,could you give me some >> suggestion? Thanks for your help! > > You want to change uas_submit_urbs() to return the reason for > errors, because -ENODEV needs to be handled differently. That > is good. > But why don't you just do > > return err; > > unconditionally? There is no point in using SCSI_MLQUEUE_DEVICE_BUSY I got it, Thanks. New patch would like this sample: @@ -562,9 +561,9 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, lockdep_assert_held(&devinfo->lock); if (cmdinfo->state & SUBMIT_STATUS_URB) { - urb = uas_submit_sense_urb(cmnd, GFP_ATOMIC); - if (!urb) - return SCSI_MLQUEUE_DEVICE_BUSY; + err = uas_submit_sense_urb(cmnd, GFP_ATOMIC); + if (err) + return err; cmdinfo->state &= ~SUBMIT_STATUS_URB; } @@ -582,7 +581,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, if (err) { usb_unanchor_urb(cmdinfo->data_in_urb); uas_log_cmd_state(cmnd, "data in submit err", err); - return SCSI_MLQUEUE_DEVICE_BUSY; + return err; } When alloc urb fail in the same function uas_submit_urbs, whether we should replace SCSI_MLQUEUE_DEVICE_BUSY with generic error code -ENOMEM? Such like this: @@ -572,7 +571,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC, cmnd, DMA_FROM_DEVICE); if (!cmdinfo->data_in_urb) - return SCSI_MLQUEUE_DEVICE_BUSY; + return -ENOMEM; cmdinfo->state &= ~ALLOC_DATA_IN_URB; } Thanks and Best regards, Weitao
On 2024/2/29 16:08, Oliver Neukum wrote: > > On 29.02.24 12:19, WeitaoWang-oc@zhaoxin.com wrote: > >> When alloc urb fail in the same function uas_submit_urbs, >> whether we should replace SCSI_MLQUEUE_DEVICE_BUSY with generic >> error code -ENOMEM? Such like this: >> >> @@ -572,7 +571,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, >> cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC, >> cmnd, DMA_FROM_DEVICE); >> if (!cmdinfo->data_in_urb) >> - return SCSI_MLQUEUE_DEVICE_BUSY; >> + return -ENOMEM; >> cmdinfo->state &= ~ALLOC_DATA_IN_URB; >> } > > Hi, > > yes, and then you translate in one central place for the SCSI layer > into DID_ERROR or DID_NO_CONNECT. > OK, I'll submit a new version after you help to review the following patch. diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c index 9707f53cfda9..689396777b6f 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -533,7 +533,7 @@ static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp, * daft to me. */ -static struct urb *uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) +static int uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) { struct uas_dev_info *devinfo = cmnd->device->hostdata; struct urb *urb; @@ -541,16 +541,15 @@ static struct urb *uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) urb = uas_alloc_sense_urb(devinfo, gfp, cmnd); if (!urb) - return NULL; + return -ENOMEM; usb_anchor_urb(urb, &devinfo->sense_urbs); err = usb_submit_urb(urb, gfp); if (err) { usb_unanchor_urb(urb); uas_log_cmd_state(cmnd, "sense submit err", err); usb_free_urb(urb); - return NULL; } - return urb; + return err; } static int uas_submit_urbs(struct scsi_cmnd *cmnd, @@ -562,9 +561,9 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, lockdep_assert_held(&devinfo->lock); if (cmdinfo->state & SUBMIT_STATUS_URB) { - urb = uas_submit_sense_urb(cmnd, GFP_ATOMIC); - if (!urb) - return SCSI_MLQUEUE_DEVICE_BUSY; + err = uas_submit_sense_urb(cmnd, GFP_ATOMIC); + if (err) + return err; cmdinfo->state &= ~SUBMIT_STATUS_URB; } @@ -572,7 +571,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC, cmnd, DMA_FROM_DEVICE); if (!cmdinfo->data_in_urb) - return SCSI_MLQUEUE_DEVICE_BUSY; + return -ENOMEM; cmdinfo->state &= ~ALLOC_DATA_IN_URB; } @@ -582,7 +581,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, if (err) { usb_unanchor_urb(cmdinfo->data_in_urb); uas_log_cmd_state(cmnd, "data in submit err", err); - return SCSI_MLQUEUE_DEVICE_BUSY; + return err; } cmdinfo->state &= ~SUBMIT_DATA_IN_URB; cmdinfo->state |= DATA_IN_URB_INFLIGHT; @@ -592,7 +591,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC, cmnd, DMA_TO_DEVICE); if (!cmdinfo->data_out_urb) - return SCSI_MLQUEUE_DEVICE_BUSY; + return -ENOMEM; cmdinfo->state &= ~ALLOC_DATA_OUT_URB; } @@ -602,7 +601,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, if (err) { usb_unanchor_urb(cmdinfo->data_out_urb); uas_log_cmd_state(cmnd, "data out submit err", err); - return SCSI_MLQUEUE_DEVICE_BUSY; + return err; } cmdinfo->state &= ~SUBMIT_DATA_OUT_URB; cmdinfo->state |= DATA_OUT_URB_INFLIGHT; @@ -611,7 +610,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, if (cmdinfo->state & ALLOC_CMD_URB) { cmdinfo->cmd_urb = uas_alloc_cmd_urb(devinfo, GFP_ATOMIC, cmnd); if (!cmdinfo->cmd_urb) - return SCSI_MLQUEUE_DEVICE_BUSY; + return -ENOMEM; cmdinfo->state &= ~ALLOC_CMD_URB; } @@ -621,7 +620,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, if (err) { usb_unanchor_urb(cmdinfo->cmd_urb); uas_log_cmd_state(cmnd, "cmd submit err", err); - return SCSI_MLQUEUE_DEVICE_BUSY; + return err; } cmdinfo->cmd_urb = NULL; cmdinfo->state &= ~SUBMIT_CMD_URB; @@ -698,7 +697,7 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd) * of queueing, no matter how fatal the error */ if (err == -ENODEV) { - set_host_byte(cmnd, DID_ERROR); + set_host_byte(cmnd, DID_NO_CONNECT); scsi_done(cmnd); goto zombie; } Thanks and best regards, weitao
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c index 9707f53cfda9..967f18db525a 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -533,7 +533,7 @@ static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp, * daft to me. */ -static struct urb *uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) +static int uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) { struct uas_dev_info *devinfo = cmnd->device->hostdata; struct urb *urb; @@ -541,16 +541,15 @@ static struct urb *uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) urb = uas_alloc_sense_urb(devinfo, gfp, cmnd); if (!urb) - return NULL; + return -ENOMEM; usb_anchor_urb(urb, &devinfo->sense_urbs); err = usb_submit_urb(urb, gfp); if (err) { usb_unanchor_urb(urb); uas_log_cmd_state(cmnd, "sense submit err", err); usb_free_urb(urb); - return NULL; } - return urb; + return err; } static int uas_submit_urbs(struct scsi_cmnd *cmnd, @@ -562,9 +561,9 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, lockdep_assert_held(&devinfo->lock); if (cmdinfo->state & SUBMIT_STATUS_URB) { - urb = uas_submit_sense_urb(cmnd, GFP_ATOMIC); - if (!urb) - return SCSI_MLQUEUE_DEVICE_BUSY; + err = uas_submit_sense_urb(cmnd, GFP_ATOMIC); + if (err) + return (err == -ENODEV) ? -ENODEV : SCSI_MLQUEUE_DEVICE_BUSY; cmdinfo->state &= ~SUBMIT_STATUS_URB; } @@ -582,7 +581,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, if (err) { usb_unanchor_urb(cmdinfo->data_in_urb); uas_log_cmd_state(cmnd, "data in submit err", err); - return SCSI_MLQUEUE_DEVICE_BUSY; + return (err == -ENODEV) ? -ENODEV : SCSI_MLQUEUE_DEVICE_BUSY; } cmdinfo->state &= ~SUBMIT_DATA_IN_URB; cmdinfo->state |= DATA_IN_URB_INFLIGHT; @@ -602,7 +601,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, if (err) { usb_unanchor_urb(cmdinfo->data_out_urb); uas_log_cmd_state(cmnd, "data out submit err", err); - return SCSI_MLQUEUE_DEVICE_BUSY; + return (err == -ENODEV) ? -ENODEV : SCSI_MLQUEUE_DEVICE_BUSY; } cmdinfo->state &= ~SUBMIT_DATA_OUT_URB; cmdinfo->state |= DATA_OUT_URB_INFLIGHT; @@ -621,7 +620,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, if (err) { usb_unanchor_urb(cmdinfo->cmd_urb); uas_log_cmd_state(cmnd, "cmd submit err", err); - return SCSI_MLQUEUE_DEVICE_BUSY; + return (err == -ENODEV) ? -ENODEV : SCSI_MLQUEUE_DEVICE_BUSY; } cmdinfo->cmd_urb = NULL; cmdinfo->state &= ~SUBMIT_CMD_URB; @@ -698,7 +697,7 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd) * of queueing, no matter how fatal the error */ if (err == -ENODEV) { - set_host_byte(cmnd, DID_ERROR); + set_host_byte(cmnd, DID_NO_CONNECT); scsi_done(cmnd); goto zombie; }