Skip to content

Commit a8a7be1

Browse files
hayesorzdavem330
authored andcommitted
r8152: adjust rtl8152_check_firmware function
Use bits operations to record and check the firmware. Signed-off-by: Hayes Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5133bcc commit a8a7be1

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

drivers/net/usb/r8152.c

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,14 @@ struct fw_header {
874874
struct fw_block blocks[];
875875
} __packed;
876876

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+
877885
/**
878886
* struct fw_mac - a firmware block used by RTL_FW_PLA and RTL_FW_USB.
879887
* The layout of the firmware block is:
@@ -3800,10 +3808,7 @@ static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)
38003808
{
38013809
const struct firmware *fw = rtl_fw->fw;
38023810
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;
38073812
long ret = -EFAULT;
38083813
int i;
38093814

@@ -3832,50 +3837,52 @@ static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)
38323837
goto fail;
38333838
goto fw_end;
38343839
case RTL_FW_PLA:
3835-
if (pla) {
3840+
if (test_bit(FW_FLAGS_PLA, &fw_flags)) {
38363841
dev_err(&tp->intf->dev,
38373842
"multiple PLA firmware encountered");
38383843
goto fail;
38393844
}
38403845

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)) {
38433847
dev_err(&tp->intf->dev,
38443848
"check PLA firmware failed\n");
38453849
goto fail;
38463850
}
3851+
__set_bit(FW_FLAGS_PLA, &fw_flags);
38473852
break;
38483853
case RTL_FW_USB:
3849-
if (usb) {
3854+
if (test_bit(FW_FLAGS_USB, &fw_flags)) {
38503855
dev_err(&tp->intf->dev,
38513856
"multiple USB firmware encountered");
38523857
goto fail;
38533858
}
38543859

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)) {
38573861
dev_err(&tp->intf->dev,
38583862
"check USB firmware failed\n");
38593863
goto fail;
38603864
}
3865+
__set_bit(FW_FLAGS_USB, &fw_flags);
38613866
break;
38623867
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)) {
38643871
dev_err(&tp->intf->dev,
38653872
"check PHY_START fail\n");
38663873
goto fail;
38673874
}
38683875

3869-
if (__le32_to_cpu(block->length) != sizeof(*start)) {
3876+
if (__le32_to_cpu(block->length) != sizeof(struct fw_phy_patch_key)) {
38703877
dev_err(&tp->intf->dev,
38713878
"Invalid length for PHY_START\n");
38723879
goto fail;
38733880
}
3874-
3875-
start = (struct fw_phy_patch_key *)block;
3881+
__set_bit(FW_FLAGS_START, &fw_flags);
38763882
break;
38773883
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)) {
38793886
dev_err(&tp->intf->dev,
38803887
"Check PHY_STOP fail\n");
38813888
goto fail;
@@ -3886,28 +3893,28 @@ static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)
38863893
"Invalid length for PHY_STOP\n");
38873894
goto fail;
38883895
}
3889-
3890-
stop = block;
3896+
__set_bit(FW_FLAGS_STOP, &fw_flags);
38913897
break;
38923898
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)) {
38943901
dev_err(&tp->intf->dev,
38953902
"check PHY_NC fail\n");
38963903
goto fail;
38973904
}
38983905

3899-
if (phy_nc) {
3906+
if (test_bit(FW_FLAGS_NC, &fw_flags)) {
39003907
dev_err(&tp->intf->dev,
39013908
"multiple PHY NC encountered\n");
39023909
goto fail;
39033910
}
39043911

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)) {
39073913
dev_err(&tp->intf->dev,
39083914
"check PHY NC firmware failed\n");
39093915
goto fail;
39103916
}
3917+
__set_bit(FW_FLAGS_NC, &fw_flags);
39113918

39123919
break;
39133920
default:
@@ -3921,7 +3928,7 @@ static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)
39213928
}
39223929

39233930
fw_end:
3924-
if ((phy_nc || start) && !stop) {
3931+
if (test_bit(FW_FLAGS_START, &fw_flags) && !test_bit(FW_FLAGS_STOP, &fw_flags)) {
39253932
dev_err(&tp->intf->dev, "without PHY_STOP\n");
39263933
goto fail;
39273934
}

0 commit comments

Comments
 (0)