linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jean Delvare <khali@linux-fr.org>
To: Joonyoung Shim <jy0922.shim@samsung.com>
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, 6 Jul 2010 10:18:03 +0200	[thread overview]
Message-ID: <20100706101803.6d13ac65@hyperion.delvare> (raw)
In-Reply-To: <4C32DECE.2030009@samsung.com>

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.

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

-- 
Jean Delvare

  reply	other threads:[~2010-07-06  8:18 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 [this message]
2010-07-06  8:23           ` Joonyoung Shim

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=20100706101803.6d13ac65@hyperion.delvare \
    --to=khali@linux-fr.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jy0922.shim@samsung.com \
    --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).