Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1350064lqb; Sat, 25 May 2024 18:29:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVmPK0Ej2rD34Y1AscqUbOE+Nb5Ur2B4CVBDZ7TbwyrLxXRj5pb5/qXUjJx+017qCQmxZ5lvwGQYNYqX/ObQN+Bz+u7MWoNeuVTeMYk4w== X-Google-Smtp-Source: AGHT+IE8FL/q91PqRGxddlTfrxBYg96mqcDchL5v5o4mTV8DrrJDthsirUH2faMxkkp5Gw60mmFA X-Received: by 2002:a17:902:6545:b0:1f3:33f1:ff5 with SMTP id d9443c01a7336-1f4486fd458mr51117885ad.3.1716686996261; Sat, 25 May 2024 18:29:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716686996; cv=pass; d=google.com; s=arc-20160816; b=v9xYq2fg0bAMII38E4Sij4HKVgTlXReYRPz9IxZbDvcNvf7h2oLZrno2B98oPHrb2p hc68CJIrxy7c4HyB0admdF4JE6k7JClwT0Z+2onqq6oLw1f3VltjtPL1QjM8nxcVtTKi WDNvUN9wl0vK/hXOks/9/bmRhuZDdvakuxiBgTPM7CGI1ToDoyJj7Af+2w2taib0uQRy twhGTGtCX0ThI21YMRai00Uw7kgjsyDDhblZjxQ+ABrrqdoxFXg0rd74CLWc5C2fwdkP G4WakNS/4cJ6+63k6rJFtUPvcLnNENKiCqN+JqmygFSzAcI0OkMOWDik/O1Qr3SLrulS z2FQ== 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=u07Iey81j3k5fLr1Slpz2mVuu45UdaoKvFPM3aZm1t0=; fh=pq9kDgzzHn4Q5Mg4YgnwpoEB0ypvsWJrNhMYTCEjfpQ=; b=fsO+8lq1bQFlEIdFKLG9Nysv47aBKpMN7AG6fnOe/TFQnn+qR6ibtk+KtR0manCghK G2e89Of38b8Ux+lUmGOR0TTHqk+AqtCkWTxllhjnnhXmbd3f8O4MIkL6WXc/9cFUX9kJ Gv9+WF/O+97iJieQKlTU6wV/VeRAqQfLGIP8KKWnktlSaOAG+p7pXZrxyFHM1n+i/7Rs ne8Sh2PeZ2BCkv7fOkuK2834U+ryUvg+3KvTH638vdhCQZ3t5BIZXauIQX3q6wCb2dV7 P611UEZZ+WDjFz7LAQzcShSMFVi8wQQON5fOimrb0UeWnnv5MEa0wTT4BFr5L3CeA060 HL9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=g4U+w72A; 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-189583-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189583-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c785758si36968125ad.29.2024.05.25.18.29.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 May 2024 18:29:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189583-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=g4U+w72A; 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-189583-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189583-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 23A8F2814C7 for ; Sun, 26 May 2024 01:29:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E21801392; Sun, 26 May 2024 01:29:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g4U+w72A" Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 BB65A79C0; Sun, 26 May 2024 01:29:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716686987; cv=none; b=s2IwoC/PVwVjQq1oSh2qsacuPtdZV2e11UJyMyDyvpaRo17qHL4zZGEcFYzjgLMJ5wFbH9TB5F9JZwEE0EsIuE9O2f9fa0TXxc8WOE1iiUE8goW5tbdssmj6s1gJhsAKhmlatrXVsF3IC/nJ8gUP9hAmwd1ma2dM3993wGp3boc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716686987; c=relaxed/simple; bh=bTy4rHKWsDHxnt4C0C4Rpj9eCADgsmB6J6v0c5MyoUs=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=lq05dBgrcI5TokK81dATml6Zw9TiQ4IJVkVcak/MiY99SwESwizU3AYed8O7bzIfg/e6WFyhyQQ5rh3Hb1V6u/X73OFFnR9nZ0N2hqEUQqi4GsXzFYtK3n7EPoScHmZ6+Kd8nQwpJM3QLdvmHbovNNokdAZrqNja+U/vSBOUfvs= 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=g4U+w72A; arc=none smtp.client-ip=209.85.215.171 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-f171.google.com with SMTP id 41be03b00d2f7-681907af4e7so1592734a12.1; Sat, 25 May 2024 18:29:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716686985; x=1717291785; 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=u07Iey81j3k5fLr1Slpz2mVuu45UdaoKvFPM3aZm1t0=; b=g4U+w72AYr9cSCMLwEq8euzsQ8PUg4LY7rAW0Qlf59ks5HGbf6OVmykg2J0VtulRd6 u39XJQSlP6ekvXfSfGomilXMGDt30ETJ+dBhYnVKQKUyUwVB+bR2Xi5BDLteGNAQONrG YCNJUhVrD3iy3IM38wJx4Q7gY9qz8WuCJbFA0lbS2HrzJ/6ix6eMalJrZKor1qJqt2Ju juFKlcJ3IvKzLUk3tc51B6S0WogJQ1raXmBk5GJjhmgsw/hulX8hzG7HUWZTO/LVu2ma gkbp2Zxey6gxMfbJz6SZb3NrtyVHzWNd261bqxvBzmF10ROYJTctGPsuaZ4PIAwj9rmm YumA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716686985; x=1717291785; 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=u07Iey81j3k5fLr1Slpz2mVuu45UdaoKvFPM3aZm1t0=; b=cMQcilWYTWwNRJcT3SPgKonXjBNCDXMCk3Z6GwOeZED9gCj4Rvuv6lC2zAoNrp0Xc+ kICDo3f8ErubXSVa1aHXHXt8PkDZ5mrZL3GA+mPWo5jrpMpq5bnyVO1eR8SGVfF/pxP2 fgR/yoGgy4wIrrAIoOYdqSJhi2t/Kl2DyNxhpJ1xaMjQQ22izPRT7CE9IS6x8Ge6MPeW jYZRI0PvXvmqnBXg8sb8Qna2F4jKBTEYXnJvgievpdJna5MRaOHPKORxWqwl+/5MG/zx 7C++KlLEOr188Is6r4UGWiN1sABpvFygusuJ+DCCQD2R3AABoFhsjy56ptsz1zQk08kL nQeA== X-Forwarded-Encrypted: i=1; AJvYcCWlubc4i2iyVSil0uNqw7SPhgDmk6X13vy2liAp+CHcKguntgvTNePDCXT9COY9gmj2kkhU3hoDyYm29dt5jKXd7KWMe0+kUMCFZJZpJAAKNyXuUYOfvV4+y5layzvouIluMZhLHCRo X-Gm-Message-State: AOJu0Yym/UlRIBwfy/82AiMBodsE1z1lJsJe0hkxtgoTsEQeJRR7onYq a9iEHCOUe4TfDaaYVjeZoI2K2f1V4c+h/1nsOm8pGgltXvsN0M+3 X-Received: by 2002:a17:902:e995:b0:1f3:50e7:36db with SMTP id d9443c01a7336-1f4498ec1ebmr49195605ad.48.1716686984752; Sat, 25 May 2024 18:29:44 -0700 (PDT) Received: from velvet.. ([111.42.148.111]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f481de3d78sm4156025ad.75.2024.05.25.18.29.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 May 2024 18:29:44 -0700 (PDT) From: Shichao Lai To: stern@rowland.harvard.edu, gregkh@linuxfoundation.org, Markus.Elfring@web.de 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 v6] usb-storage: alauda: Check whether the media is initialized Date: Sun, 26 May 2024 09:27:45 +0800 Message-Id: <20240526012745.2852061-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(). Fixes: e80b0fade09e ("[PATCH] USB Storage: add alauda support") Reported-by: xingwei lee Reported-by: yue sun Reviewed-by: Alan Stern Signed-off-by: Shichao Lai --- Changes since v5: - 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