Skip to content

Commit 16637fe

Browse files
chaosraigregkh
authored andcommitted
usb-storage: alauda: Check whether the media is initialized
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: e80b0fa ("[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>
1 parent 8bdf8a4 commit 16637fe

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/usb/storage/alauda.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ struct alauda_info {
105105
unsigned char sense_key;
106106
unsigned long sense_asc; /* additional sense code */
107107
unsigned long sense_ascq; /* additional sense code qualifier */
108+
109+
bool media_initialized;
108110
};
109111

110112
#define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) )
@@ -476,11 +478,12 @@ static int alauda_check_media(struct us_data *us)
476478
}
477479

478480
/* Check for media change */
479-
if (status[0] & 0x08) {
481+
if (status[0] & 0x08 || !info->media_initialized) {
480482
usb_stor_dbg(us, "Media change detected\n");
481483
alauda_free_maps(&MEDIA_INFO(us));
482-
alauda_init_media(us);
483-
484+
rc = alauda_init_media(us);
485+
if (rc == USB_STOR_TRANSPORT_GOOD)
486+
info->media_initialized = true;
484487
info->sense_key = UNIT_ATTENTION;
485488
info->sense_asc = 0x28;
486489
info->sense_ascq = 0x00;

0 commit comments

Comments
 (0)