Re: [PATCH 2/4] staging: typec: Restrict read pointer to 16 bit of tcpci_read16.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/11/2017 03:53 AM, ? ? wrote:
From: Pan Li <incarnation.p.lee@xxxxxxxxxxx>

     Restricted tcpci_read16 argument to 16 bit variable pointer,
in accord with the function name.

Signed-off-by: Pan Li <incarnation.p.lee@xxxxxxxxxxx>
---
  drivers/staging/typec/tcpci.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
index 2adb543..b6bf15b 100644
--- a/drivers/staging/typec/tcpci.c
+++ b/drivers/staging/typec/tcpci.c
@@ -46,8 +46,7 @@ static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc)
  	return container_of(tcpc, struct tcpci, tcpc);
  }
-static int tcpci_read16(struct tcpci *tcpci, unsigned int reg,
-			unsigned int *val)
+static int tcpci_read16(struct tcpci *tcpci, unsigned int reg, u16 *val)
  {

This only partially solves the problem. The returned value is really little endian,
not u16. Either tcpci_read16() would have to convert it to host byte order,
or the pointer has to be marked as little endian. The same is true for
tcpci_write16() - either the parameter has to be little endian, or tcpci_write16()
needs to convert it before sending it to the chip.

I would suggest to do the conversion in tcpci_read16() and tcpci_write16().
Maybe it would make sense to have a separate tcpci_read16_le() if the value
is needed as little endian.

Guenter

  	return regmap_raw_read(tcpci->regmap, reg, val, sizeof(u16));
  }
@@ -355,7 +354,8 @@ static int tcpci_init(struct tcpc_dev *tcpc)
  static irqreturn_t tcpci_irq(int irq, void *dev_id)
  {
  	struct tcpci *tcpci = dev_id;
-	unsigned int status, reg;
+	unsigned int reg;
+	u16 header, status;
tcpci_read16(tcpci, TCPC_ALERT, &status); @@ -389,8 +389,8 @@ static irqreturn_t tcpci_irq(int irq, void *dev_id) regmap_read(tcpci->regmap, TCPC_RX_BYTE_CNT, &cnt); - tcpci_read16(tcpci, TCPC_RX_HDR, &reg);
-		msg.header = reg;
+		tcpci_read16(tcpci, TCPC_RX_HDR, &header);
+		msg.header = header;
if (WARN_ON(cnt > sizeof(msg.payload)))
  			cnt = sizeof(msg.payload);


_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux