linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joonyoung Shim <jy0922.shim@samsung.com>
To: Jean Delvare <khali@linux-fr.org>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	linux-input@vger.kernel.org, kyungmin.park@samsung.com,
	rydberg@euromail.se
Subject: Re: [PATCH v3] input: qt602240 - Add ATMEL QT602240 touchscreen driver
Date: Tue, 06 Jul 2010 17:23:44 +0900	[thread overview]
Message-ID: <4C32E810.2000301@samsung.com> (raw)
In-Reply-To: <20100706101803.6d13ac65@hyperion.delvare>

On 7/6/2010 5:18 PM, Jean Delvare wrote:
> On Tue, 06 Jul 2010 16:44:14 +0900, Joonyoung Shim wrote:
>> On 6/29/2010 8:11 PM, Jean Delvare wrote:
>>> On Tue, 29 Jun 2010 11:13:05 +0900, Joonyoung Shim wrote:
>>>> On 6/29/2010 2:55 AM, Dmitry Torokhov wrote:
>>>>> Also, please CC Jean Delvare to make sure I2C bits look good.
>>>> I add him to CC.
>>> I can't comment without seeing the full patch.
>>>
>> Sorry for late response, you can see the full patch in follow site.
>>
>> https://patchwork.kernel.org/patch/108363/
> 
> OK, overall it's OK, but your driver is vulnerable to a race condition
> due to the use of i2c_master_send() and i2c_master_recv().
> 
>> +static int qt602240_read_reg(struct i2c_client *client, u16 reg)
>> +{
>> +	u8 buf[2];
>> +	u8 val;
>> +
>> +	buf[0] = reg & 0xff;
>> +	buf[1] = (reg >> 8) & 0xff;
>> +
>> +	if (i2c_master_send(client, buf, 2) != 2) {
>> +		dev_err(&client->dev, "%s: i2c send failed\n", __func__);
>> +		return -EIO;
>> +	}
>> +
>> +	if (i2c_master_recv(client, &val, 1) != 1) {
>> +		dev_err(&client->dev, "%s: i2c recv failed\n", __func__);
>> +		return -EIO;
>> +	}
>> +
>> +	return val;
>> +}
> 
> As you don't have any locking in place, there is no guarantee that
> another I2C access to the device won't happen between i2c_master_send()
> which sets the register pointer and i2c_master_recv() which reads the
> value back.
> 
> There are 2 ways to fix this. First way is to add locking around all
> your device register accesses. Second way (much better IMHO) is to use
> i2c_transfer() with 2 messages instead of i2c_master_send() +
> i2c_master_recv(). i2c_transfer() is guaranteed to be atomic (as far as
> the device register pointer is concerned) by i2c-core.
> 

OK, i think second solution is better too. I will fix it.

Thanks.

> Same applies to qt602240_read_object_table() and
> qt602240_read_message(), and maybe other functions I haven't seen.
> 


      reply	other threads:[~2010-07-06  8:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-28 11:38 [PATCH v3] input: qt602240 - Add ATMEL QT602240 touchscreen driver Joonyoung Shim
2010-06-28 12:27 ` Henrik Rydberg
2010-06-28 17:55 ` Dmitry Torokhov
2010-06-29  2:13   ` Joonyoung Shim
2010-06-29 11:11     ` Jean Delvare
2010-07-06  7:44       ` Joonyoung Shim
2010-07-06  8:18         ` Jean Delvare
2010-07-06  8:23           ` Joonyoung Shim [this message]

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=4C32E810.2000301@samsung.com \
    --to=jy0922.shim@samsung.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=khali@linux-fr.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-input@vger.kernel.org \
    --cc=rydberg@euromail.se \
    /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).