linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yadi Hu <yadi.hu@windriver.com>
To: yadi.hu@windriver.com, wsa@the-dreams.de, jdelvare@suse.de
Cc: linux-i2c@vger.kernel.org
Subject: [PATCH] i2c-eg20t: fix race between i2c init and interrupt enable
Date: Wed, 7 Sep 2016 17:25:37 +0800	[thread overview]
Message-ID: <1473240337-5694-2-git-send-email-yadi.hu@windriver.com> (raw)
In-Reply-To: <1473240337-5694-1-git-send-email-yadi.hu@windriver.com>

From: "Yadi.hu" <yadi.hu@windriver.com>

the eg20t driver call request_irq() function before the pch_base_address, 
base address of i2c controller's register, isassigned an effective value.

it is one possible scenario that an interrupt which isn't inside eg20t 
arrives immediately after request_irq() is executed when i2c controller 
shares an interrupt number with others.  since the interrupt handler 
pch_i2c_handler() has already active as shared action, it will be called 
and read its own register to determine if this interrupt is from itself.

At that moment, since base address of i2c registers is not remapped 
in kernel space yet,so the INT handler will access an illegal address
and then a error occurs.

the new patch adds a check point on interrupt handler in case field
'pch_base_address' has not been initialed.

Signed-off-by: Yadi.hu <yadi.hu@windriver.com>
---
 drivers/i2c/busses/i2c-eg20t.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c
index 137125b..4ac8a49 100644
--- a/drivers/i2c/busses/i2c-eg20t.c
+++ b/drivers/i2c/busses/i2c-eg20t.c
@@ -152,6 +152,7 @@ struct i2c_algo_pch_data {
 	int pch_buff_mode_en;
 	u32 pch_event_flag;
 	bool pch_i2c_xfer_in_progress;
+	bool initflag;
 };
 
 /**
@@ -635,6 +636,8 @@ static irqreturn_t pch_i2c_handler(int irq, void *pData)
 	u32 mode;
 
 	for (i = 0, flag = 0; i < adap_info->ch_num; i++) {
+		if (!adap_info->pch_data[i].initflag)
+			continue;
 		p = adap_info->pch_data[i].pch_base_address;
 		mode = ioread32(p + PCH_I2CMOD);
 		mode &= BUFFER_MODE | EEPROM_SR_MODE;
@@ -783,6 +786,7 @@ static int pch_i2c_probe(struct pci_dev *pdev,
 	for (i = 0; i < adap_info->ch_num; i++) {
 		pch_adap = &adap_info->pch_data[i].pch_adapter;
 		adap_info->pch_i2c_suspended = false;
+		adap_info->pch_data[i].initflag = false;
 
 		adap_info->pch_data[i].p_adapter_info = adap_info;
 
@@ -806,6 +810,7 @@ static int pch_i2c_probe(struct pci_dev *pdev,
 			pch_pci_err(pdev, "i2c_add_adapter[ch:%d] FAILED\n", i);
 			goto err_add_adapter;
 		}
+		adap_info->pch_data[i].initflag = true;
 	}
 
 	pci_set_drvdata(pdev, adap_info);
-- 
2.9.3

  reply	other threads:[~2016-09-07  9:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-07  9:25 RESEND:i2c-eg20t: fix race between i2c init and interrupt enable Yadi Hu
2016-09-07  9:25 ` Yadi Hu [this message]
2016-09-12  0:41 ` Yadi
2016-09-14  6:39 ` Yadi
2016-09-14  7:28 ` Wolfram Sang
2016-09-14  7:49   ` Yadi
2016-09-16 20:04 ` Wolfram Sang
2016-09-18  2:55   ` Yadi
2016-09-18  7:53     ` Wolfram Sang
2016-09-18  8:51       ` Yadi
  -- strict thread matches above, loose matches on Subject: below --
2016-09-18 10:52 RESEND: V3 i2c-eg20t:fix " Yadi Hu
2016-09-18 10:52 ` [PATCH] i2c-eg20t: fix " Yadi Hu
2016-09-21 16:16   ` Wolfram Sang
2016-09-21 16:18     ` Wolfram Sang
2016-09-22  1:19       ` Yadi
2016-09-22  1:04     ` Yadi
2016-09-22  6:02       ` Wolfram Sang
2016-08-29  2:56 Yadi Hu
2016-09-02 10:05 ` Yadi
2016-08-23  9:07 Yadi Hu
2016-08-26 15:32 ` Jean Delvare
2016-08-29  3:02   ` Yadi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1473240337-5694-2-git-send-email-yadi.hu@windriver.com \
    --to=yadi.hu@windriver.com \
    --cc=jdelvare@suse.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).