From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 50E9B1DFC7; Wed, 3 Jul 2024 11:03:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720004614; cv=none; b=kl1PBWysH/N2w3S4w8+YDxlPP8w3OGNhiFifQeQXeFno1+Hn8hrCdsKRP+GPPRlE1uW1iwAD+j9hRzsDV/ggFe4npbF4h0G/aDSRo0LwMSaFTovW7vP75WUNjJx+tjjqrYwE6lsXLXm/wumueWXGPYDrdPdzbdQ8vXul4dTD8dk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720004614; c=relaxed/simple; bh=cdyQ+dz/bWN5HEdYsaQ4j+ScT3PPPLuIadCPjL5aF4c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YUmVx4Bz1J11P47M2tncLI4u4lPkUBBqU7NfGT3KdrK2Rg2qPfBx8/upjYuAeSE/BCIu4Nd/L/LzVc3rz3Fm6vycImc1Zyky9jmyK7WB5tAbNP7AFFoIgS82Gr4mlpfm1MLMQeRONLQqbglr3ypi59jIyE3QRenouYPrb9DlkbY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lmMxZwMM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="lmMxZwMM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB127C2BD10; Wed, 3 Jul 2024 11:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1720004614; bh=cdyQ+dz/bWN5HEdYsaQ4j+ScT3PPPLuIadCPjL5aF4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lmMxZwMMNjOYlTh7OYLCfqFfljHl4XQaK4t4HXIIehA8sWu19KLnORaM53dN6y3lv PJYvGWVeE/KVOuq5K1nmE4YKHptj+Hd3XB6Wd+UeMiGSVM0exD49gD1b49VuD4QTzV NtlZ3XHJWUbm0l0AJwdmpf3wO7U4FSq9gj+4Qmec= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, xingwei lee , yue sun , Alan Stern , Shichao Lai , Sasha Levin Subject: [PATCH 5.10 101/290] usb-storage: alauda: Check whether the media is initialized Date: Wed, 3 Jul 2024 12:38:02 +0200 Message-ID: <20240703102908.011837150@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240703102904.170852981@linuxfoundation.org> References: <20240703102904.170852981@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shichao Lai [ Upstream commit 16637fea001ab3c8df528a8995b3211906165a30 ] 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 Link: https://lore.kernel.org/r/20240526012745.2852061-1-shichaorai@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- 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 dcc4778d1ae99..17fe35083f048 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.43.0