@@ -874,6 +874,14 @@ struct fw_header {
874
874
struct fw_block blocks [];
875
875
} __packed ;
876
876
877
+ enum rtl8152_fw_flags {
878
+ FW_FLAGS_USB = 0 ,
879
+ FW_FLAGS_PLA ,
880
+ FW_FLAGS_START ,
881
+ FW_FLAGS_STOP ,
882
+ FW_FLAGS_NC ,
883
+ };
884
+
877
885
/**
878
886
* struct fw_mac - a firmware block used by RTL_FW_PLA and RTL_FW_USB.
879
887
* The layout of the firmware block is:
@@ -3800,10 +3808,7 @@ static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)
3800
3808
{
3801
3809
const struct firmware * fw = rtl_fw -> fw ;
3802
3810
struct fw_header * fw_hdr = (struct fw_header * )fw -> data ;
3803
- struct fw_mac * pla = NULL , * usb = NULL ;
3804
- struct fw_phy_patch_key * start = NULL ;
3805
- struct fw_phy_nc * phy_nc = NULL ;
3806
- struct fw_block * stop = NULL ;
3811
+ unsigned long fw_flags = 0 ;
3807
3812
long ret = - EFAULT ;
3808
3813
int i ;
3809
3814
@@ -3832,50 +3837,52 @@ static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)
3832
3837
goto fail ;
3833
3838
goto fw_end ;
3834
3839
case RTL_FW_PLA :
3835
- if (pla ) {
3840
+ if (test_bit ( FW_FLAGS_PLA , & fw_flags ) ) {
3836
3841
dev_err (& tp -> intf -> dev ,
3837
3842
"multiple PLA firmware encountered" );
3838
3843
goto fail ;
3839
3844
}
3840
3845
3841
- pla = (struct fw_mac * )block ;
3842
- if (!rtl8152_is_fw_mac_ok (tp , pla )) {
3846
+ if (!rtl8152_is_fw_mac_ok (tp , (struct fw_mac * )block )) {
3843
3847
dev_err (& tp -> intf -> dev ,
3844
3848
"check PLA firmware failed\n" );
3845
3849
goto fail ;
3846
3850
}
3851
+ __set_bit (FW_FLAGS_PLA , & fw_flags );
3847
3852
break ;
3848
3853
case RTL_FW_USB :
3849
- if (usb ) {
3854
+ if (test_bit ( FW_FLAGS_USB , & fw_flags ) ) {
3850
3855
dev_err (& tp -> intf -> dev ,
3851
3856
"multiple USB firmware encountered" );
3852
3857
goto fail ;
3853
3858
}
3854
3859
3855
- usb = (struct fw_mac * )block ;
3856
- if (!rtl8152_is_fw_mac_ok (tp , usb )) {
3860
+ if (!rtl8152_is_fw_mac_ok (tp , (struct fw_mac * )block )) {
3857
3861
dev_err (& tp -> intf -> dev ,
3858
3862
"check USB firmware failed\n" );
3859
3863
goto fail ;
3860
3864
}
3865
+ __set_bit (FW_FLAGS_USB , & fw_flags );
3861
3866
break ;
3862
3867
case RTL_FW_PHY_START :
3863
- if (start || phy_nc || stop ) {
3868
+ if (test_bit (FW_FLAGS_START , & fw_flags ) ||
3869
+ test_bit (FW_FLAGS_NC , & fw_flags ) ||
3870
+ test_bit (FW_FLAGS_STOP , & fw_flags )) {
3864
3871
dev_err (& tp -> intf -> dev ,
3865
3872
"check PHY_START fail\n" );
3866
3873
goto fail ;
3867
3874
}
3868
3875
3869
- if (__le32_to_cpu (block -> length ) != sizeof (* start )) {
3876
+ if (__le32_to_cpu (block -> length ) != sizeof (struct fw_phy_patch_key )) {
3870
3877
dev_err (& tp -> intf -> dev ,
3871
3878
"Invalid length for PHY_START\n" );
3872
3879
goto fail ;
3873
3880
}
3874
-
3875
- start = (struct fw_phy_patch_key * )block ;
3881
+ __set_bit (FW_FLAGS_START , & fw_flags );
3876
3882
break ;
3877
3883
case RTL_FW_PHY_STOP :
3878
- if (stop || !start ) {
3884
+ if (test_bit (FW_FLAGS_STOP , & fw_flags ) ||
3885
+ !test_bit (FW_FLAGS_START , & fw_flags )) {
3879
3886
dev_err (& tp -> intf -> dev ,
3880
3887
"Check PHY_STOP fail\n" );
3881
3888
goto fail ;
@@ -3886,28 +3893,28 @@ static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)
3886
3893
"Invalid length for PHY_STOP\n" );
3887
3894
goto fail ;
3888
3895
}
3889
-
3890
- stop = block ;
3896
+ __set_bit (FW_FLAGS_STOP , & fw_flags );
3891
3897
break ;
3892
3898
case RTL_FW_PHY_NC :
3893
- if (!start || stop ) {
3899
+ if (!test_bit (FW_FLAGS_START , & fw_flags ) ||
3900
+ test_bit (FW_FLAGS_STOP , & fw_flags )) {
3894
3901
dev_err (& tp -> intf -> dev ,
3895
3902
"check PHY_NC fail\n" );
3896
3903
goto fail ;
3897
3904
}
3898
3905
3899
- if (phy_nc ) {
3906
+ if (test_bit ( FW_FLAGS_NC , & fw_flags ) ) {
3900
3907
dev_err (& tp -> intf -> dev ,
3901
3908
"multiple PHY NC encountered\n" );
3902
3909
goto fail ;
3903
3910
}
3904
3911
3905
- phy_nc = (struct fw_phy_nc * )block ;
3906
- if (!rtl8152_is_fw_phy_nc_ok (tp , phy_nc )) {
3912
+ if (!rtl8152_is_fw_phy_nc_ok (tp , (struct fw_phy_nc * )block )) {
3907
3913
dev_err (& tp -> intf -> dev ,
3908
3914
"check PHY NC firmware failed\n" );
3909
3915
goto fail ;
3910
3916
}
3917
+ __set_bit (FW_FLAGS_NC , & fw_flags );
3911
3918
3912
3919
break ;
3913
3920
default :
@@ -3921,7 +3928,7 @@ static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)
3921
3928
}
3922
3929
3923
3930
fw_end :
3924
- if (( phy_nc || start ) && !stop ) {
3931
+ if (test_bit ( FW_FLAGS_START , & fw_flags ) && !test_bit ( FW_FLAGS_STOP , & fw_flags ) ) {
3925
3932
dev_err (& tp -> intf -> dev , "without PHY_STOP\n" );
3926
3933
goto fail ;
3927
3934
}
0 commit comments