public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: fix crash with msgs is NULL points
@ 2023-05-10  8:40 wangyouwan
  2023-05-10  9:02 ` Mika Westerberg
  0 siblings, 1 reply; 4+ messages in thread
From: wangyouwan @ 2023-05-10  8:40 UTC (permalink / raw)
  To: jarkko.nikula, andriy.shevchenko, mika.westerberg, jsd
  Cc: linux-i2c, linux-kernel, youwan Wang

From: youwan Wang <wangyouwan@126.com>

There is some probability that msgs is empty

Signed-off-by: youwan Wang <wangyouwan@126.com>
---
 drivers/i2c/busses/i2c-designware-master.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index 55ea91a63382..e11a73fd0a41 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -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++) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: fix crash with msgs is NULL points
  2023-05-10  8:40 [PATCH] i2c: fix crash with msgs is NULL points wangyouwan
@ 2023-05-10  9:02 ` Mika Westerberg
       [not found]   ` <1943ca04.6ce1.18804f327f0.Coremail.wangyouwan@126.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Mika Westerberg @ 2023-05-10  9:02 UTC (permalink / raw)
  To: wangyouwan; +Cc: jarkko.nikula, andriy.shevchenko, jsd, linux-i2c, linux-kernel

On Wed, May 10, 2023 at 04:40:57PM +0800, wangyouwan@126.com wrote:
> From: youwan Wang <wangyouwan@126.com>
> 
> There is some probability that msgs is empty

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: [PATCH] i2c: fix crash with msgs is NULL points
       [not found]   ` <1943ca04.6ce1.18804f327f0.Coremail.wangyouwan@126.com>
@ 2023-05-10  9:23     ` Mika Westerberg
  2023-05-11  7:01       ` Jarkko Nikula
  0 siblings, 1 reply; 4+ messages in thread
From: Mika Westerberg @ 2023-05-10  9:23 UTC (permalink / raw)
  To: wangyouwan; +Cc: jarkko.nikula, andriy.shevchenko, jsd, linux-i2c, linux-kernel


On Wed, May 10, 2023 at 05:17:04PM +0800, wangyouwan wrote:
> 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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: fix crash with msgs is NULL points
  2023-05-10  9:23     ` Mika Westerberg
@ 2023-05-11  7:01       ` Jarkko Nikula
  0 siblings, 0 replies; 4+ messages in thread
From: Jarkko Nikula @ 2023-05-11  7:01 UTC (permalink / raw)
  To: Mika Westerberg, wangyouwan
  Cc: andriy.shevchenko, jsd, linux-i2c, linux-kernel

Hi

On 5/10/23 12:23, Mika Westerberg wrote:
> 
> On Wed, May 10, 2023 at 05:17:04PM +0800, wangyouwan wrote:
>> 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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-11  7:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-10  8:40 [PATCH] i2c: fix crash with msgs is NULL points wangyouwan
2023-05-10  9:02 ` Mika Westerberg
     [not found]   ` <1943ca04.6ce1.18804f327f0.Coremail.wangyouwan@126.com>
2023-05-10  9:23     ` Mika Westerberg
2023-05-11  7:01       ` Jarkko Nikula

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox