|
83 | 83 | #define OFFSET_PUMP_MODE 20 |
84 | 84 | #define OFFSET_PROFILE_LEN 26 |
85 | 85 |
|
86 | | -#if IS_REACHABLE(CONFIG_CRC8) |
87 | 86 | DECLARE_CRC8_TABLE(corsair_crc8_table); |
88 | | -#endif |
89 | 87 |
|
90 | 88 | struct hydro_platinum_data { |
91 | 89 | struct hid_device *hdev; |
@@ -129,32 +127,7 @@ struct hydro_platinum_device_info { |
129 | 127 | /* SMBus standard CRC-8 polynomial x^8 + x^2 + x + 1 (0x07) */ |
130 | 128 | static void hydro_platinum_init_crc(void) |
131 | 129 | { |
132 | | -#if IS_REACHABLE(CONFIG_CRC8) |
133 | 130 | crc8_populate_msb(corsair_crc8_table, 0x07); |
134 | | -#endif |
135 | | -} |
136 | | - |
137 | | -static u8 hydro_platinum_calc_crc(const u8 *data, size_t len, u8 crc) |
138 | | -{ |
139 | | -#if IS_REACHABLE(CONFIG_CRC8) |
140 | | - return crc8(corsair_crc8_table, data, len, crc); |
141 | | -#else |
142 | | - /* Table-less fallback for when CONFIG_CRC8 is disabled */ |
143 | | - size_t i, j; |
144 | | - u8 val; |
145 | | - |
146 | | - for (i = 0; i < len; i++) { |
147 | | - val = data[i]; |
148 | | - crc ^= val; |
149 | | - for (j = 0; j < 8; j++) { |
150 | | - if (crc & 0x80) |
151 | | - crc = (crc << 1) ^ 0x07; |
152 | | - else |
153 | | - crc <<= 1; |
154 | | - } |
155 | | - } |
156 | | - return crc; |
157 | | -#endif |
158 | 131 | } |
159 | 132 |
|
160 | 133 | /** |
@@ -195,8 +168,8 @@ static int hydro_platinum_send_command(struct hydro_platinum_data *priv, u8 feat |
195 | 168 |
|
196 | 169 | /* Calculate CRC over buf[2] to buf[REPORT_LENGTH-1+1] */ |
197 | 170 | /* Payload is buf[1]..buf[64]. CRC is usually last byte of payload. */ |
198 | | - priv->tx_buffer[REPORT_LENGTH] = hydro_platinum_calc_crc(priv->tx_buffer + 2, |
199 | | - REPORT_LENGTH - 2, 0); |
| 171 | + priv->tx_buffer[REPORT_LENGTH] = crc8(corsair_crc8_table, priv->tx_buffer + 2, |
| 172 | + REPORT_LENGTH - 2, 0); |
200 | 173 |
|
201 | 174 | /* Send Report - 65 bytes */ |
202 | 175 |
|
@@ -258,7 +231,7 @@ static int hydro_platinum_transaction(struct hydro_platinum_data *priv, u8 featu |
258 | 231 | * prevents the driver from processing invalid data, which could otherwise |
259 | 232 | * confuse the device state machine and cause firmware crashes/reboots. |
260 | 233 | */ |
261 | | - if (hydro_platinum_calc_crc(priv->rx_buffer + 1, REPORT_LENGTH - 1, 0) != 0) { |
| 234 | + if (crc8(corsair_crc8_table, priv->rx_buffer + 1, REPORT_LENGTH - 1, 0) != 0) { |
262 | 235 | dev_warn_ratelimited(&priv->hdev->dev, |
263 | 236 | "CRC check failed for command %02x - possible userspace collision\n", |
264 | 237 | command); |
|
0 commit comments