ath25: switch default kernel to 5.15
[openwrt/openwrt.git] / target / linux / generic / backport-5.10 / 791-v5.13-r8152-adjust-rtl8152_check_firmware-function.patch
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
5
6 commit a8a7be178e81a3d4b6972cbeb0ccd091ca2f9f89 upstream.
7
8 Use bits operations to record and check the firmware.
9
10 Signed-off-by: Hayes Wang <hayeswang@realtek.com>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
12 ---
13 drivers/net/usb/r8152.c | 51 +++++++++++++++++++++++------------------
14 1 file changed, 29 insertions(+), 22 deletions(-)
15
16 --- a/drivers/net/usb/r8152.c
17 +++ b/drivers/net/usb/r8152.c
18 @@ -874,6 +874,14 @@ struct fw_header {
19 struct fw_block blocks[];
20 } __packed;
21
22 +enum rtl8152_fw_flags {
23 + FW_FLAGS_USB = 0,
24 + FW_FLAGS_PLA,
25 + FW_FLAGS_START,
26 + FW_FLAGS_STOP,
27 + FW_FLAGS_NC,
28 +};
29 +
30 /**
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 @@ -3802,10 +3810,7 @@ static long rtl8152_check_firmware(struc
34 {
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;
42 long ret = -EFAULT;
43 int i;
44
45 @@ -3834,50 +3839,52 @@ static long rtl8152_check_firmware(struc
46 goto fail;
47 goto fw_end;
48 case RTL_FW_PLA:
49 - if (pla) {
50 + if (test_bit(FW_FLAGS_PLA, &fw_flags)) {
51 dev_err(&tp->intf->dev,
52 "multiple PLA firmware encountered");
53 goto fail;
54 }
55
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");
61 goto fail;
62 }
63 + __set_bit(FW_FLAGS_PLA, &fw_flags);
64 break;
65 case RTL_FW_USB:
66 - if (usb) {
67 + if (test_bit(FW_FLAGS_USB, &fw_flags)) {
68 dev_err(&tp->intf->dev,
69 "multiple USB firmware encountered");
70 goto fail;
71 }
72
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");
78 goto fail;
79 }
80 + __set_bit(FW_FLAGS_USB, &fw_flags);
81 break;
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");
89 goto fail;
90 }
91
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");
96 goto fail;
97 }
98 -
99 - start = (struct fw_phy_patch_key *)block;
100 + __set_bit(FW_FLAGS_START, &fw_flags);
101 break;
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");
108 goto fail;
109 @@ -3888,28 +3895,28 @@ static long rtl8152_check_firmware(struc
110 "Invalid length for PHY_STOP\n");
111 goto fail;
112 }
113 -
114 - stop = block;
115 + __set_bit(FW_FLAGS_STOP, &fw_flags);
116 break;
117 case RTL_FW_PHY_NC:
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");
123 goto fail;
124 }
125
126 - if (phy_nc) {
127 + if (test_bit(FW_FLAGS_NC, &fw_flags)) {
128 dev_err(&tp->intf->dev,
129 "multiple PHY NC encountered\n");
130 goto fail;
131 }
132
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");
138 goto fail;
139 }
140 + __set_bit(FW_FLAGS_NC, &fw_flags);
141
142 break;
143 default:
144 @@ -3923,7 +3930,7 @@ static long rtl8152_check_firmware(struc
145 }
146
147 fw_end:
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");
151 goto fail;
152 }