1 From f10c9edf47d3fa240d965e151a48c670f5035b73 Mon Sep 17 00:00:00 2001
2 From: Hayes Wang <hayeswang@realtek.com>
3 Date: Fri, 16 Apr 2021 16:04:33 +0800
4 Subject: [PATCH] r8152: adjust rtl8152_check_firmware function
6 commit a8a7be178e81a3d4b6972cbeb0ccd091ca2f9f89 upstream.
8 Use bits operations to record and check the firmware.
10 Signed-off-by: Hayes Wang <hayeswang@realtek.com>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
13 drivers/net/usb/r8152.c | 51 +++++++++++++++++++++++------------------
14 1 file changed, 29 insertions(+), 22 deletions(-)
16 --- a/drivers/net/usb/r8152.c
17 +++ b/drivers/net/usb/r8152.c
18 @@ -875,6 +875,14 @@ struct fw_header {
19 struct fw_block blocks[];
22 +enum rtl8152_fw_flags {
31 * struct fw_mac - a firmware block used by RTL_FW_PLA and RTL_FW_USB.
32 * The layout of the firmware block is:
33 @@ -3801,10 +3809,7 @@ static long rtl8152_check_firmware(struc
35 const struct firmware *fw = rtl_fw->fw;
36 struct fw_header *fw_hdr = (struct fw_header *)fw->data;
37 - struct fw_mac *pla = NULL, *usb = NULL;
38 - struct fw_phy_patch_key *start = NULL;
39 - struct fw_phy_nc *phy_nc = NULL;
40 - struct fw_block *stop = NULL;
41 + unsigned long fw_flags = 0;
45 @@ -3833,50 +3838,52 @@ static long rtl8152_check_firmware(struc
50 + if (test_bit(FW_FLAGS_PLA, &fw_flags)) {
51 dev_err(&tp->intf->dev,
52 "multiple PLA firmware encountered");
56 - pla = (struct fw_mac *)block;
57 - if (!rtl8152_is_fw_mac_ok(tp, pla)) {
58 + if (!rtl8152_is_fw_mac_ok(tp, (struct fw_mac *)block)) {
59 dev_err(&tp->intf->dev,
60 "check PLA firmware failed\n");
63 + __set_bit(FW_FLAGS_PLA, &fw_flags);
67 + if (test_bit(FW_FLAGS_USB, &fw_flags)) {
68 dev_err(&tp->intf->dev,
69 "multiple USB firmware encountered");
73 - usb = (struct fw_mac *)block;
74 - if (!rtl8152_is_fw_mac_ok(tp, usb)) {
75 + if (!rtl8152_is_fw_mac_ok(tp, (struct fw_mac *)block)) {
76 dev_err(&tp->intf->dev,
77 "check USB firmware failed\n");
80 + __set_bit(FW_FLAGS_USB, &fw_flags);
82 case RTL_FW_PHY_START:
83 - if (start || phy_nc || stop) {
84 + if (test_bit(FW_FLAGS_START, &fw_flags) ||
85 + test_bit(FW_FLAGS_NC, &fw_flags) ||
86 + test_bit(FW_FLAGS_STOP, &fw_flags)) {
87 dev_err(&tp->intf->dev,
88 "check PHY_START fail\n");
92 - if (__le32_to_cpu(block->length) != sizeof(*start)) {
93 + if (__le32_to_cpu(block->length) != sizeof(struct fw_phy_patch_key)) {
94 dev_err(&tp->intf->dev,
95 "Invalid length for PHY_START\n");
99 - start = (struct fw_phy_patch_key *)block;
100 + __set_bit(FW_FLAGS_START, &fw_flags);
102 case RTL_FW_PHY_STOP:
103 - if (stop || !start) {
104 + if (test_bit(FW_FLAGS_STOP, &fw_flags) ||
105 + !test_bit(FW_FLAGS_START, &fw_flags)) {
106 dev_err(&tp->intf->dev,
107 "Check PHY_STOP fail\n");
109 @@ -3887,28 +3894,28 @@ static long rtl8152_check_firmware(struc
110 "Invalid length for PHY_STOP\n");
115 + __set_bit(FW_FLAGS_STOP, &fw_flags);
118 - if (!start || stop) {
119 + if (!test_bit(FW_FLAGS_START, &fw_flags) ||
120 + test_bit(FW_FLAGS_STOP, &fw_flags)) {
121 dev_err(&tp->intf->dev,
122 "check PHY_NC fail\n");
127 + if (test_bit(FW_FLAGS_NC, &fw_flags)) {
128 dev_err(&tp->intf->dev,
129 "multiple PHY NC encountered\n");
133 - phy_nc = (struct fw_phy_nc *)block;
134 - if (!rtl8152_is_fw_phy_nc_ok(tp, phy_nc)) {
135 + if (!rtl8152_is_fw_phy_nc_ok(tp, (struct fw_phy_nc *)block)) {
136 dev_err(&tp->intf->dev,
137 "check PHY NC firmware failed\n");
140 + __set_bit(FW_FLAGS_NC, &fw_flags);
144 @@ -3922,7 +3929,7 @@ static long rtl8152_check_firmware(struc
148 - if ((phy_nc || start) && !stop) {
149 + if (test_bit(FW_FLAGS_START, &fw_flags) && !test_bit(FW_FLAGS_STOP, &fw_flags)) {
150 dev_err(&tp->intf->dev, "without PHY_STOP\n");