Skip to contentSkip to conversation

i2c: fix crash with msgs is NULL points

PATCH In review [email protected] 3 participants 4 messages May 10, 2023 – May 11, 2023 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: fix crash with msgs is NULL points

From: youwan Wang <[email protected]>

There is some probability that msgs is empty

---
 drivers/i2c/busses/i2c-designware-master.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-master.c +6 -1
index 55ea91a63382..e11a73fd0a41 100644
@@ -366,12 +366,17 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
 	struct i2c_msg *msgs = dev->msgs;
 	u32 intr_mask;
 	int tx_limit, rx_limit;
-	u32 addr = msgs[dev->msg_write_idx].addr;
+	u32 addr;
 	u32 buf_len = dev->tx_buf_len;
 	u8 *buf = dev->tx_buf;
 	bool need_restart = false;
 	unsigned int flr;
 
+	if (WARN_ON(!msgs))
+		return;
+
+	addr = msgs[dev->msg_write_idx].addr;
+
 	intr_mask = DW_IC_INTR_MASTER_MASK;
 
 	for (; dev->msg_write_idx < dev->msgs_num; dev->msg_write_idx++) {
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 3 lines · On Wed, May 10, 2023 at 04:40:57PM +0800, [email protected] wrote:

From: youwan Wang <[email protected]>

There is some probability that msgs is empty

What probabability 0/100? ;-) Can you point a real case when this can happen?

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#3 lore raw
Quoted 4 lines · wangyouwan

After waking up from sleep, 100% of the time it occurred. I suspected that there was a firmware issue with the machine I was debugging, but other machines did not notice it. Therefore, I attempted to make a modification here to avoid it

Okay then I suggest to investigate what causes the ->msgs to be NULL and fix that. When the transfer function is called we expect there to be something to be sent out so this should not happen.

#4 lore raw

Hi

Quoted 10 lines · Mika Westerberg
Quoted 4 lines · wangyouwan

After waking up from sleep, 100% of the time it occurred. I suspected that there was a firmware issue with the machine I was debugging, but other machines did not notice it. Therefore, I attempted to make a modification here to avoid it

Okay then I suggest to investigate what causes the ->msgs to be NULL and fix that. When the transfer function is called we expect there to be something to be sent out so this should not happen.

Does you kernel include commit 301c8f5c32c8 ("i2c: designware: Fix handling of real but unexpected device interrupts")? Vanilla kernels after v6.1 have it and also linux-stable v5.15.75 and after.

I'm asking since issue sounds similar and wanted to clarify the kernel version you are using.