Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1135444lqb; Sat, 25 May 2024 07:18:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXOrjrliffTbY7kQ7Zjc+PNo8auvg1eI9fEWbgvCagJuWBJmW3kRYCGIwUUdsff60LnSUz6uRs0/dhQWJJN616Yc22FAI3zAMvcomlA8Q== X-Google-Smtp-Source: AGHT+IH/zToC//ulAhTESbUTocRMv5ZycE4o7am2HT6zwPEd58fQuBjW0ZPnSjQyN64s+RQuXN/p X-Received: by 2002:a67:fe84:0:b0:47b:e9ce:42ac with SMTP id ada2fe7eead31-48a38514990mr5041707137.4.1716646715223; Sat, 25 May 2024 07:18:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716646715; cv=pass; d=google.com; s=arc-20160816; b=M/SWd5eT2H5ZMVShxyIcQKUs9HW8y3MtU64HRRxqDsuIuRAcD0+XEsTx+A6Xf/aGrO jnvpTs9rnAAzalFhw4/xJkkXM5msQclND2Oc2tvgNxSoclmazTFFua/jrDMV1PHZcV7T MEbo2IMOHHcy+el66LvRIrbw9sp+fREEcXr2E+/20ikeWbJezAbuR0+I16VWGvhczjDh cLMkB8D0lzutSz9Xtf0MToRz4/5D/UykyjVfvUHiCD37fd26N/0RGUk9JjGPkXoKjfu9 yyO6eUEKBehTkoTvkDh+Husi/mEu73IZ1OsXxjAJLPvbe7JHnqXDVxaehR4EOO3rUu2A azrg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=dXxUM+nKGXOMiPGDgBfInY2CwLtfAdgPFXwgLtyrzKs=; fh=c0Oc7wSUMHapCIkD3ff/I1F1lRNZD+z7U3Hce7kK5Wc=; b=lmtGoggVY8vs+wjfBXkIeBodoBMYUczK0cevgbSGxwFQEAp/CxRUjpepF4OQFQ6NcZ Kv2x8hNl7buYnyJADMftzz1kQVc20JVokpZLtovRzel5KU8rgglD7Mz5ZagSCEHInXAA N6ZyLaLhXuN/qck/kGnUl4n8R090ZubbKrgimr8HxrwU8oR+abHgg7SH7uOwwQN50GNh aEJCUbPsgR2UkJbVohD7C4zqidl3A82sT6pOmm1GYXm1GV4v7q6m4wUUggWInJvq3khr LbuNJOm4MgxO2Q0NvWirtYuldPU1nHX7WCgwCbm/X69a72M++dl18mNs75clLXxoSXIG xusQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=netrider.rowland.org); spf=pass (google.com: domain of linux-kernel+bounces-189378-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189378-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ada2fe7eead31-48a3a20557esi747093137.94.2024.05.25.07.18.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 May 2024 07:18:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189378-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=netrider.rowland.org); spf=pass (google.com: domain of linux-kernel+bounces-189378-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189378-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu 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 C66681C20A45 for ; Sat, 25 May 2024 14:18:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A39FA4EB3C; Sat, 25 May 2024 14:18:28 +0000 (UTC) Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by smtp.subspace.kernel.org (Postfix) with SMTP id 2CB874F1E5 for ; Sat, 25 May 2024 14:18:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.131.102.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716646708; cv=none; b=MMCmqPswU7dhJBBLyuPAJm9YEE2lOCNvX9r+cBbZyp8+CZUBqzEmLzNvGMiYMWFg/krwd581IS8RryPBd8vm6SfMhmRwoyZVzyY0eQ9gZaDaZ6XWcscCqmnJfrvi7/ZgE9wj+VvzpH/Va/A3civbv1SKwMlil40i4dG4kTnvvtE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716646708; c=relaxed/simple; bh=wbrXg/b1lNy7sgScKy9Bm4Ynn5Glx/YJGDrRYEX3l7Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nPiQVSd8qUHNsB2OqVTbP0lRdAPNQvueRYj5yzODFjkjU75asDX5UixIFv+aZ5k2K0G0qDuHZdw8FmAflDXem8jz3VE+V1vqnNY6DMNj1z45dOcR81BpVoo/PnfZaC80nUzWC19/GZF8fldHVSZGN7YfsypkuuVteQqGYHbMnH4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=rowland.harvard.edu; spf=pass smtp.mailfrom=netrider.rowland.org; arc=none smtp.client-ip=192.131.102.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=rowland.harvard.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netrider.rowland.org Received: (qmail 607144 invoked by uid 1000); 25 May 2024 10:18:25 -0400 Date: Sat, 25 May 2024 10:18:25 -0400 From: Alan Stern To: Shichao Lai Cc: gregkh@linuxfoundation.org, oneukum@suse.com, linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, linux-kernel@vger.kernel.org, xingwei lee , yue sun Subject: Re: [PATCH v5] usb-storage: Check whether the media is initialized successfully Message-ID: References: <20240525141020.2520942-1-shichaorai@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240525141020.2520942-1-shichaorai@gmail.com> On Sat, May 25, 2024 at 10:10:20PM +0800, Shichao Lai wrote: > The member "uzonesize" of struct alauda_info will remain 0 > if alauda_init_media() fails, potentially causing divide errors > in alauda_read_data() and alauda_write_lba(). > - Add a member "media_initialized" to struct alauda_info. > - Change a condition in alauda_check_media() to ensure the > first initialization. > - Add an error check for the return value of alauda_init_media(). > > Reported-by: xingwei lee > Reported-by: yue sun > Signed-off-by: Shichao Lai > --- > Changes since v1: You mean changes since v4. Regardless: Reviewed-by: Alan Stern > - Check the initialization of alauda_check_media() > which is the root cause. > > drivers/usb/storage/alauda.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c > index 115f05a6201a..40d34cc28344 100644 > --- a/drivers/usb/storage/alauda.c > +++ b/drivers/usb/storage/alauda.c > @@ -105,6 +105,8 @@ struct alauda_info { > unsigned char sense_key; > unsigned long sense_asc; /* additional sense code */ > unsigned long sense_ascq; /* additional sense code qualifier */ > + > + bool media_initialized; > }; > > #define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) ) > @@ -476,11 +478,12 @@ static int alauda_check_media(struct us_data *us) > } > > /* Check for media change */ > - if (status[0] & 0x08) { > + if (status[0] & 0x08 || !info->media_initialized) { > usb_stor_dbg(us, "Media change detected\n"); > alauda_free_maps(&MEDIA_INFO(us)); > - alauda_init_media(us); > - > + rc = alauda_init_media(us); > + if (rc == USB_STOR_TRANSPORT_GOOD) > + info->media_initialized = true; > info->sense_key = UNIT_ATTENTION; > info->sense_asc = 0x28; > info->sense_ascq = 0x00; > -- > 2.34.1 >