]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
usb-storage: alauda: Check whether the media is initialized
authorShichao Lai <shichaorai@gmail.com>
Sun, 26 May 2024 01:27:45 +0000 (09:27 +0800)
committerRoxana Nicolescu <roxana.nicolescu@canonical.com>
Fri, 2 Aug 2024 14:27:04 +0000 (16:27 +0200)
BugLink: https://bugs.launchpad.net/bugs/2074091
[ 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 <xrivendell7@gmail.com>
Reported-by: yue sun <samsun1006219@gmail.com>
Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Shichao Lai <shichaorai@gmail.com>
Link: https://lore.kernel.org/r/20240526012745.2852061-1-shichaorai@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Portia Stephens <portia.stephens@canonical.com>
Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
drivers/usb/storage/alauda.c

index 115f05a6201a16883f53a3d271f48adc05acd983..40d34cc28344a447c251c103c5979802cac8dd51 100644 (file)
@@ -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;