@@ -2703,22 +2703,22 @@ static int resp_mode_sense(struct scsi_cmnd *scp,
27032703 ap = arr + offset ;
27042704 }
27052705
2706- if ((subpcode > 0x0 ) && (subpcode < 0xff ) && (0x19 != pcode )) {
2707- /* TODO: Control Extension page */
2708- mk_sense_invalid_fld (scp , SDEB_IN_CDB , 3 , -1 );
2709- return check_condition_result ;
2710- }
2711-
27122706 switch (pcode ) {
27132707 case 0x1 : /* Read-Write error recovery page, direct access */
2708+ if (subpcode > 0x0 && subpcode < 0xff )
2709+ goto bad_subpcode ;
27142710 len = resp_err_recov_pg (ap , pcontrol , target );
27152711 offset += len ;
27162712 break ;
27172713 case 0x2 : /* Disconnect-Reconnect page, all devices */
2714+ if (subpcode > 0x0 && subpcode < 0xff )
2715+ goto bad_subpcode ;
27182716 len = resp_disconnect_pg (ap , pcontrol , target );
27192717 offset += len ;
27202718 break ;
27212719 case 0x3 : /* Format device page, direct access */
2720+ if (subpcode > 0x0 && subpcode < 0xff )
2721+ goto bad_subpcode ;
27222722 if (is_disk ) {
27232723 len = resp_format_pg (ap , pcontrol , target );
27242724 offset += len ;
@@ -2727,6 +2727,8 @@ static int resp_mode_sense(struct scsi_cmnd *scp,
27272727 }
27282728 break ;
27292729 case 0x8 : /* Caching page, direct access */
2730+ if (subpcode > 0x0 && subpcode < 0xff )
2731+ goto bad_subpcode ;
27302732 if (is_disk || is_zbc ) {
27312733 len = resp_caching_pg (ap , pcontrol , target );
27322734 offset += len ;
@@ -2735,14 +2737,14 @@ static int resp_mode_sense(struct scsi_cmnd *scp,
27352737 }
27362738 break ;
27372739 case 0xa : /* Control Mode page, all devices */
2740+ if (subpcode > 0x0 && subpcode < 0xff )
2741+ goto bad_subpcode ;
27382742 len = resp_ctrl_m_pg (ap , pcontrol , target );
27392743 offset += len ;
27402744 break ;
27412745 case 0x19 : /* if spc==1 then sas phy, control+discover */
2742- if ((subpcode > 0x2 ) && (subpcode < 0xff )) {
2743- mk_sense_invalid_fld (scp , SDEB_IN_CDB , 3 , -1 );
2744- return check_condition_result ;
2745- }
2746+ if (subpcode > 0x2 && subpcode < 0xff )
2747+ goto bad_subpcode ;
27462748 len = 0 ;
27472749 if ((0x0 == subpcode ) || (0xff == subpcode ))
27482750 len += resp_sas_sf_m_pg (ap + len , pcontrol , target );
@@ -2754,35 +2756,31 @@ static int resp_mode_sense(struct scsi_cmnd *scp,
27542756 offset += len ;
27552757 break ;
27562758 case 0x1c : /* Informational Exceptions Mode page, all devices */
2759+ if (subpcode > 0x0 && subpcode < 0xff )
2760+ goto bad_subpcode ;
27572761 len = resp_iec_m_pg (ap , pcontrol , target );
27582762 offset += len ;
27592763 break ;
27602764 case 0x3f : /* Read all Mode pages */
2761- if ((0 == subpcode ) || (0xff == subpcode )) {
2762- len = resp_err_recov_pg (ap , pcontrol , target );
2763- len += resp_disconnect_pg (ap + len , pcontrol , target );
2764- if (is_disk ) {
2765- len += resp_format_pg (ap + len , pcontrol ,
2766- target );
2767- len += resp_caching_pg (ap + len , pcontrol ,
2768- target );
2769- } else if (is_zbc ) {
2770- len += resp_caching_pg (ap + len , pcontrol ,
2771- target );
2772- }
2773- len += resp_ctrl_m_pg (ap + len , pcontrol , target );
2774- len += resp_sas_sf_m_pg (ap + len , pcontrol , target );
2775- if (0xff == subpcode ) {
2776- len += resp_sas_pcd_m_spg (ap + len , pcontrol ,
2777- target , target_dev_id );
2778- len += resp_sas_sha_m_spg (ap + len , pcontrol );
2779- }
2780- len += resp_iec_m_pg (ap + len , pcontrol , target );
2781- offset += len ;
2782- } else {
2783- mk_sense_invalid_fld (scp , SDEB_IN_CDB , 3 , -1 );
2784- return check_condition_result ;
2765+ if (subpcode > 0x0 && subpcode < 0xff )
2766+ goto bad_subpcode ;
2767+ len = resp_err_recov_pg (ap , pcontrol , target );
2768+ len += resp_disconnect_pg (ap + len , pcontrol , target );
2769+ if (is_disk ) {
2770+ len += resp_format_pg (ap + len , pcontrol , target );
2771+ len += resp_caching_pg (ap + len , pcontrol , target );
2772+ } else if (is_zbc ) {
2773+ len += resp_caching_pg (ap + len , pcontrol , target );
2774+ }
2775+ len += resp_ctrl_m_pg (ap + len , pcontrol , target );
2776+ len += resp_sas_sf_m_pg (ap + len , pcontrol , target );
2777+ if (0xff == subpcode ) {
2778+ len += resp_sas_pcd_m_spg (ap + len , pcontrol , target ,
2779+ target_dev_id );
2780+ len += resp_sas_sha_m_spg (ap + len , pcontrol );
27852781 }
2782+ len += resp_iec_m_pg (ap + len , pcontrol , target );
2783+ offset += len ;
27862784 break ;
27872785 default :
27882786 goto bad_pcode ;
@@ -2796,6 +2794,10 @@ static int resp_mode_sense(struct scsi_cmnd *scp,
27962794bad_pcode :
27972795 mk_sense_invalid_fld (scp , SDEB_IN_CDB , 2 , 5 );
27982796 return check_condition_result ;
2797+
2798+ bad_subpcode :
2799+ mk_sense_invalid_fld (scp , SDEB_IN_CDB , 3 , -1 );
2800+ return check_condition_result ;
27992801}
28002802
28012803#define SDEBUG_MAX_MSELECT_SZ 512
0 commit comments