From: Jean Delvare <khali@linux-fr.org>
To: Andy Walls <awalls@md.metrocast.net>
Cc: linux-media@vger.kernel.org, Mike Isely <isely@isely.net>,
Kenney Phillisjr <kphillisjr@gmail.com>,
Hans Verkuil <hverkuil@xs4all.nl>
Subject: Re: [PATCH 04/17] cx25840: Make cx25840 i2c register read transactions atomic
Date: Tue, 20 Jul 2010 08:42:17 +0200 [thread overview]
Message-ID: <20100720084217.4ab937a7@hyperion.delvare> (raw)
In-Reply-To: <1279588306.28153.6.camel@localhost>
Hi Andy,
On Mon, 19 Jul 2010 21:11:46 -0400, Andy Walls wrote:
> There was a small window between writing the cx25840 register
> address over the i2c bus and reading the register contents back from the
> cx25840 device that the i2c adapter lock was released. This change ensures the
> adapter lock is not released until the register read is done.
>
> Signed-off-by: Andy Walls <awalls@md.metrocast.net>
Good catch.
Acked-by: Jean Delvare <khali@linux-fr.org>
Note that cx25840_and_or() still has a (smaller and less dangerous)
race window. If several calls to cx25840_and_or() happen in parallel on
the same register, some of the changes may be lost. I don't know if
this can be a problem in practice though. If it is, then additional
locking around cx25840_and_or() would be needed.
> ---
> drivers/media/video/cx25840/cx25840-core.c | 58 +++++++++++++++++++---------
> 1 files changed, 39 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
> index bb4872b..4f908fa 100644
> --- a/drivers/media/video/cx25840/cx25840-core.c
> +++ b/drivers/media/video/cx25840/cx25840-core.c
> @@ -80,33 +80,53 @@ int cx25840_write4(struct i2c_client *client, u16 addr, u32 value)
>
> u8 cx25840_read(struct i2c_client * client, u16 addr)
> {
> - u8 buffer[2];
> - buffer[0] = addr >> 8;
> - buffer[1] = addr & 0xff;
> -
> - if (i2c_master_send(client, buffer, 2) < 2)
> - return 0;
> -
> - if (i2c_master_recv(client, buffer, 1) < 1)
> + struct i2c_msg msgs[2];
> + u8 tx_buf[2], rx_buf[1];
> +
> + /* Write register address */
> + tx_buf[0] = addr >> 8;
> + tx_buf[1] = addr & 0xff;
> + msgs[0].addr = client->addr;
> + msgs[0].flags = 0;
> + msgs[0].len = 2;
> + msgs[0].buf = (char *) tx_buf;
> +
> + /* Read data from register */
> + msgs[1].addr = client->addr;
> + msgs[1].flags = I2C_M_RD;
> + msgs[1].len = 1;
> + msgs[1].buf = (char *) rx_buf;
> +
> + if (i2c_transfer(client->adapter, msgs, 2) < 2)
> return 0;
>
> - return buffer[0];
> + return rx_buf[0];
> }
>
> u32 cx25840_read4(struct i2c_client * client, u16 addr)
> {
> - u8 buffer[4];
> - buffer[0] = addr >> 8;
> - buffer[1] = addr & 0xff;
> -
> - if (i2c_master_send(client, buffer, 2) < 2)
> - return 0;
> -
> - if (i2c_master_recv(client, buffer, 4) < 4)
> + struct i2c_msg msgs[2];
> + u8 tx_buf[2], rx_buf[4];
> +
> + /* Write register address */
> + tx_buf[0] = addr >> 8;
> + tx_buf[1] = addr & 0xff;
> + msgs[0].addr = client->addr;
> + msgs[0].flags = 0;
> + msgs[0].len = 2;
> + msgs[0].buf = (char *) tx_buf;
> +
> + /* Read data from registers */
> + msgs[1].addr = client->addr;
> + msgs[1].flags = I2C_M_RD;
> + msgs[1].len = 4;
> + msgs[1].buf = (char *) rx_buf;
> +
> + if (i2c_transfer(client->adapter, msgs, 2) < 2)
> return 0;
>
> - return (buffer[3] << 24) | (buffer[2] << 16) |
> - (buffer[1] << 8) | buffer[0];
> + return (rx_buf[3] << 24) | (rx_buf[2] << 16) | (rx_buf[1] << 8) |
> + rx_buf[0];
> }
>
> int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned and_mask,
--
Jean Delvare
next prev parent reply other threads:[~2010-07-20 7:30 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1279586511.git.awalls@md.metrocast.net>
2010-07-20 1:08 ` [PATCH 01/17] cx23885: Return -ENXIO on slave nack Andy Walls
2010-07-20 1:09 ` [PATCH 02/17] cx23885: Check for slave nack on all transactions Andy Walls
2010-07-20 1:10 ` [PATCH 03/17] cx23885: i2c_wait_done returns 0 or 1, don't check for < 0 return value Andy Walls
2010-07-20 1:11 ` [PATCH 04/17] cx25840: Make cx25840 i2c register read transactions atomic Andy Walls
2010-07-20 6:42 ` Jean Delvare [this message]
2010-07-20 12:35 ` Andy Walls
2010-07-20 12:46 ` Jean Delvare
2010-07-20 1:12 ` [PATCH 05/17] cx23885: Add correct detection of the HVR-1250 model 79501 Andy Walls
2010-07-20 1:12 ` [PATCH 06/17] cx23885: Add a VIDIOC_LOG_STATUS ioctl function for analog video devices Andy Walls
2010-07-20 1:16 ` [PATCH 07/17] v4l2_subdev: Add s_io_pin_config to v4l2_subdev_core_ops Andy Walls
2010-07-20 1:18 ` [PATCH 08/17] cx25840: Add s_io_pin_config core subdev ops for the CX2388[578] Andy Walls
2010-07-20 1:18 ` [PATCH 09/17] v4l2_subdev, cx23885: Differentiate IR carrier sense and I/O pin inversion Andy Walls
2010-07-20 1:19 ` [PATCH 10/17] cx23885: For CX23888 IR, configure the IO pin mux IR pins explcitly Andy Walls
2010-07-20 1:20 ` [PATCH 11/17] v4l2_subdev: Move interrupt_service_routine ptr to v4l2_subdev_core_ops Andy Walls
2010-07-20 1:22 ` [PATCH 12/17] cx25840: Add support for CX2388[57] A/V core integrated IR controllers Andy Walls
2010-07-20 1:22 ` [PATCH 13/17] cx23885: Add a v4l2_subdev group id for the CX2388[578] integrated AV core Andy Walls
2010-07-20 1:23 ` [PATCH 14/17] cx23885: Add preliminary IR Rx support for the HVR-1250 and TeVii S470 Andy Walls
2010-07-20 1:25 ` [PATCH 15/17] cx23885: Protect PCI interrupt mask manipulations with a spinlock Andy Walls
2010-07-20 1:25 ` [PATCH 16/17] cx23885: Move AV Core irq handling to a work handler Andy Walls
2010-07-20 1:26 ` [PATCH 17/17] cx23885: Require user to explicitly enable CX2388[57] IR via module param Andy Walls
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=20100720084217.4ab937a7@hyperion.delvare \
--to=khali@linux-fr.org \
--cc=awalls@md.metrocast.net \
--cc=hverkuil@xs4all.nl \
--cc=isely@isely.net \
--cc=kphillisjr@gmail.com \
--cc=linux-media@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.