usb-storage: Check whether the media is initialized successfully
Subsystems (3)
PATCH v5 1/1 usb-storage: Check whether the media is initialized successfully
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().
---
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(-)
drivers/usb/storage/alauda.c +6 -3
@@ -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 ;
Signature · 1 line
2.34.1
Quoted 8 lines · Shichao Lai
The member "uzonesize" of struct
alauda_infowill remain 0 ifalauda_init_media()fails, potentially causing divide errors inalauda_read_data()andalauda_write_lba().
- Add a member "media_initialized" to structalauda_info.
- Change a condition inalauda_check_media()to ensure the first initialization.
- Add an error check for the return value ofalauda_init_media().
Quoted 5 lines
Reported-by xingwei lee <[email protected]>Reported-by yue sun <[email protected]>Signed-off-by Shichao Lai <[email protected]>---
Changes since v1:
You mean changes since v4. Regardless:
Quoted 38 lines
- 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(-)drivers/usb/storage/alauda.c +6
-3@@ -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 ;Signature · 1 line
2.34.1
…
Quoted 1 line
- Add an error check for the return value of
alauda_init_media().
Does such information indicate a need for the tag “Fixes”?
Regards,
Markus