Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: typec: fix endianness mismatch identified by sparse

Eliminate the following sparse warnings:

tcpci.c:291:38: warning: incorrect type in argument 1 (different base types)
tcpci.c:291:38: expected unsigned short [unsigned] [usertype] header
tcpci.c:291:38: got restricted __le16 const [usertype] header
tcpci.c:296:16: warning: incorrect type in assignment (different base types)
tcpci.c:296:16: expected unsigned int [unsigned] header
tcpci.c:296:16: got restricted __le16
tcpci.c:394:28: warning: incorrect type in assignment (different base types)
tcpci.c:394:28: expected restricted __le16 [usertype] header
tcpci.c:394:28: got unsigned int [unsigned] [addressable] reg

Signed-off-by: Gabriel Somlo <gsomlo@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Gabriel L. Somlo and committed by
Greg Kroah-Hartman
81948cbc 7f9d04bc

+10 -7
+10 -7
drivers/staging/typec/tcpci.c
··· 47 47 } 48 48 49 49 static int tcpci_read16(struct tcpci *tcpci, unsigned int reg, 50 - unsigned int *val) 50 + u16 *val) 51 51 { 52 52 return regmap_raw_read(tcpci->regmap, reg, val, sizeof(u16)); 53 53 } ··· 285 285 const struct pd_message *msg) 286 286 { 287 287 struct tcpci *tcpci = tcpc_to_tcpci(tcpc); 288 - unsigned int reg, cnt, header; 288 + u16 header = msg ? le16_to_cpu(msg->header) : 0; 289 + unsigned int reg, cnt; 289 290 int ret; 290 291 291 - cnt = msg ? pd_header_cnt(msg->header) * 4 : 0; 292 + cnt = msg ? pd_header_cnt(header) * 4 : 0; 292 293 ret = regmap_write(tcpci->regmap, TCPC_TX_BYTE_CNT, cnt + 2); 293 294 if (ret < 0) 294 295 return ret; 295 296 296 - header = msg ? msg->header : 0; 297 297 ret = tcpci_write16(tcpci, TCPC_TX_HDR, header); 298 298 if (ret < 0) 299 299 return ret; ··· 356 356 static irqreturn_t tcpci_irq(int irq, void *dev_id) 357 357 { 358 358 struct tcpci *tcpci = dev_id; 359 - unsigned int status, reg; 359 + u16 status; 360 360 361 361 tcpci_read16(tcpci, TCPC_ALERT, &status); 362 362 ··· 372 372 tcpm_cc_change(tcpci->port); 373 373 374 374 if (status & TCPC_ALERT_POWER_STATUS) { 375 + unsigned int reg; 376 + 375 377 regmap_read(tcpci->regmap, TCPC_POWER_STATUS_MASK, &reg); 376 378 377 379 /* ··· 389 387 if (status & TCPC_ALERT_RX_STATUS) { 390 388 struct pd_message msg; 391 389 unsigned int cnt; 390 + u16 header; 392 391 393 392 regmap_read(tcpci->regmap, TCPC_RX_BYTE_CNT, &cnt); 394 393 395 - tcpci_read16(tcpci, TCPC_RX_HDR, &reg); 396 - msg.header = reg; 394 + tcpci_read16(tcpci, TCPC_RX_HDR, &header); 395 + msg.header = cpu_to_le16(header); 397 396 398 397 if (WARN_ON(cnt > sizeof(msg.payload))) 399 398 cnt = sizeof(msg.payload);