Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1131354lqb; Sat, 25 May 2024 07:10:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXbOxXxvvLoZwnTCc6gpV6y92R/8iRcASf+gtnGvjBknqOErQFps9aDKMVb4vUQX5bq9dhzqeHOLl6Fu+ovuEkD+t8Gw/PjXhqhAs8V3w== X-Google-Smtp-Source: AGHT+IE70UOhHsew+kzjbo/7DolWK9PBDuNHxGO6Nc58nnDSLxkwJD6MBYQ914NWQjscaqPbiYrp X-Received: by 2002:a19:3802:0:b0:524:34ad:ba7d with SMTP id 2adb3069b0e04-52966f8f47dmr3685053e87.42.1716646255647; Sat, 25 May 2024 07:10:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716646255; cv=pass; d=google.com; s=arc-20160816; b=cGYmcyd0UW2cknFMU7YmIPvJPXITu1f6CB4XXR08UU9V4aOBIcYC6u0lLwVRdqJuc9 i0dfCBmyNY+cxvbeBBVkeqW5zoH6YkK041fVKxRmOy8Us9C0zMTGztj4OrEl3ZadtBhb 7Cofoj2rWUdtH7Ag7PwRTjOWAjvGv1biHa+ViPvacwTuumHPhisGb1IA+rhN9PVgu+rH hUB13Gp1LWUZMnwU1DGNJgusM0fJQApLYRgQrD6iqtgbj4VdK0zZxMf9sQD4gIAl/lYi 6DMRxbbhel0F54zWgGjfifVvvQybl1iTq+3PP74WUS0IXJGgLYzu/gaeDyGF9JimqBE3 Z/1w== 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:dkim-signature; bh=wldvmv7DWJTk5N8y48gKwHLB5rZ3GSfo3AcMZE5/l5w=; fh=TrnCyeSXCQh3uP9cm2FYKW3Tn0ZgwQObzQ5f9CfzwrY=; b=BmkHCbjpekomLdV02FHVXdOBTF99aEVwFhQ8iMYSjz4BA26xZXopdXkThmh5pbuT2o xsRk+LybK6UTX/h9v04oTFGq6n0CO91ygtzsCTTJxHRwFEB3Hr91JsNwPO2ESjCPVocK ZqVFo61+ay3RxNFK1tRLFpOlY7sRBQ1nO4PUUGiUwP5egsNKYTa5ARH2xnKf9fFJSLTp pmOAZSJuxucjeOGxtFORiVuddVsT6boDfSaadk3bu/6RhblHrXCwBVemPi1eh1JUqnIP hm9peNrhLcmspOPn/rGdXcvp3u7/X6AXKA/r3Ba+VrOcxtfMI5Hk+x3HzxFCGXJ0oH71 3H4Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=egCEt90k; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-189376-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189376-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cdd06ebsi183676666b.940.2024.05.25.07.10.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 May 2024 07:10:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189376-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=egCEt90k; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-189376-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189376-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5E1B71F213B5 for ; Sat, 25 May 2024 14:10:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0F04B4EB51; Sat, 25 May 2024 14:10:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="egCEt90k" Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB1793BBD9; Sat, 25 May 2024 14:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716646246; cv=none; b=Onui221HXjbbKaP/7ResDAf5D/MxjvB8IROAK0jC8hiTvPqew+Y2ruGk27LX93Zp9SIp/ejZq1VubrapPrSOmU5znKav9YSjNlLNdfLGEKN4qu13qJlXz/mt2iDeNw3iMNNX8bTiurHAzeDFdAjFRB3T+gcpqaxGk5OFc6BNYEY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716646246; c=relaxed/simple; bh=5tPLxvC76dR1u+c6dlH6TKfwLycW990n5KJ1pd7w9Dk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=olkJJBKYzSGQ+SV+2H5h1Zes3s6uJex7UkMxZXQ3fn5DpwhgwYMWDv55g0gJhNvYEZr2Pc78AGhb0n912lsK2tieAaqCvMi/wEU/AqL/cw//hGXVMrMHmiKGKcPz2jmIYAB+c7LXkL70IBgB4bJQeF1wkcnAs6mghV0jfFd5D2Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=egCEt90k; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-6818e31e5baso1484195a12.1; Sat, 25 May 2024 07:10:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716646244; x=1717251044; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=wldvmv7DWJTk5N8y48gKwHLB5rZ3GSfo3AcMZE5/l5w=; b=egCEt90kkAjJELLhaejDK1OslC4XLYMhrTPDA5wOD3YxZ1AarZzuFQdOgUF+gy/qNV XPiIWpz2vJ55k3uMGB4NwIxooVZ0AwWjBXI1Pe6p6ER27yVdVPvLcD3hH/EhdcvUBuL1 wwjxqK23peBaN+RQaiVViYfBtKHH54leQWtdPyHwNS1as0R7N2+EaA/qeZWa9MBj3hOU nT/Hwf3aj/rRWFZh1BFEisrPILI8hYJKGCp/XdM2glEi33E1R1cvBDxXZcqbNbaKpmxc EGPTrCFMqIxrPH+RaRUfZ67yoati7knnrkxiHoHl4R407knNZ8FEtzF7jG31WZJQ1X/9 iqYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716646244; x=1717251044; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wldvmv7DWJTk5N8y48gKwHLB5rZ3GSfo3AcMZE5/l5w=; b=p75J9nc/EDk/5ssd0O4YWj3DKOYu4CbBhDQMb7Eci5QDGBfcAX71de2yWZTSsJr8Hl PNhDXyLiCE4/pdk4OxIHgmhNbMeQ8hJbwep7CRIGnsvNiwMzfSD2exbnxQBPOwAWEoge 3iPCpXtTHiy4DR6wQZW/LCOGfLVe2ugs1Exxgo1QKcgrXsLvVPJ/UfBaF8hH6a0G1BWz rn15vWM/H6wxqilng6R/z+F8LJ6e10r9V3yJGilbiWn/nGW8vmO6gCZ2QEKbkmUN4CSn f/oFxIhykyEwGX2psB1bnvSDW4IFL3W3bvp9RLXG4zpzqxNZJAImjRyMDjxNQp30x3Ol mzIA== X-Forwarded-Encrypted: i=1; AJvYcCVjO/QZrN0hIC6Hea/ojE2/Qfv8XPwVtKmsLdTS8zFZRUUf/0/cMnyTvxu12X22qhYjo5QmAkp22R29vrYKZXentyksV8NPEJgToKTdNm7tapYGnyUNKWHRSMrCLpvxRUE4hC4YYrWo X-Gm-Message-State: AOJu0Yxcfq9KZvD2vmrxUdPAXMBHr24NDT6Ya04dGjQ7z2dibWCiWU+e ClScGZOyJYIAVfFXfEP9Z9p3ghBym8g9nPOt2EIKMXZv0CBJJhwuBOklZCvd X-Received: by 2002:a17:90b:4393:b0:2bf:7ccb:b8c0 with SMTP id 98e67ed59e1d1-2bf7ccbbec5mr3416578a91.26.1716646244073; Sat, 25 May 2024 07:10:44 -0700 (PDT) Received: from velvet.. ([111.42.148.111]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2bde078426bsm3404256a91.0.2024.05.25.07.10.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 May 2024 07:10:43 -0700 (PDT) From: Shichao Lai To: stern@rowland.harvard.edu, gregkh@linuxfoundation.org Cc: oneukum@suse.com, linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, linux-kernel@vger.kernel.org, Shichao Lai , xingwei lee , yue sun Subject: [PATCH v5] usb-storage: Check whether the media is initialized successfully Date: Sat, 25 May 2024 22:10:20 +0800 Message-Id: <20240525141020.2520942-1-shichaorai@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: - 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