From patchwork Mon Apr 11 18:57:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 65567 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1519916qge; Mon, 11 Apr 2016 12:00:57 -0700 (PDT) X-Received: by 10.66.232.226 with SMTP id tr2mr32300673pac.44.1460401257337; Mon, 11 Apr 2016 12:00:57 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id jj8si5114758pac.83.2016.04.11.12.00.56; Mon, 11 Apr 2016 12:00:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755460AbcDKTAu (ORCPT + 29 others); Mon, 11 Apr 2016 15:00:50 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:34414 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755044AbcDKS5x (ORCPT ); Mon, 11 Apr 2016 14:57:53 -0400 Received: by mail-pf0-f180.google.com with SMTP id c20so129107461pfc.1 for ; Mon, 11 Apr 2016 11:57:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n8NiID+6CzUiC3xmwRs+DS3s4aRE8QZmw83sIiO19lA=; b=iI7RqtDlYkMItBhyEAIgBDx3bI4RHmNGvEi6a6vyfLojY2AkWTcPDam7XGw/6cXTZb GZl3lGvbNoswNQ7tZnvVlgsQ85va5wT+A6IwOpFs/r3ySw36sel5hY/mih/LIM6kzNFc PtM7llIG+EIBWuFyA3Kq6dxNHBbCRaaBuunKqDBNMfppvKMEceBz5X1Hi3nmDTIjqLoF qW7fHXapBl4MynDnSgBbG/d5lJ1b+gTbArAcbCA+X8gxmw22fklG3bnrGELkEJ4sH/6j 4SpmuSsTaFjopmOUEHCkSFXA+TkQnFYwJkvIKxrDDcwCpNmAkOXMLhTZUQdkIquGea2B CEPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=n8NiID+6CzUiC3xmwRs+DS3s4aRE8QZmw83sIiO19lA=; b=g0LpdZgaV3AR8sYlYdNRd1pYZTOA6QCAcWsGmdy8HDzu+iTBb7wZulghUVx3cpXwah GbZbTDVUWoRdq8wOQ39TgVk+W3BrfPIbJ80IsT3dmYcdgEfcY7Av0VScKLXR4LMM6j3e yxyMaynjU2zAnuwV1E6bLzs6XRHkCXfdp1refCRkmEHlne8mW5su4zT1D5ZeM0gI6/m6 ++j1+vW4DvmSuyI+5EWAGDWM/f+0dn3VizfDBKRVOnLSi3cCUHhB5BxxSEI8zmYmSFH6 j8QqqVjr9PY+TfJxdOfPFFnvoNa+2hgoj6vFM6XuIUyXtaIXwxEN4+kac6dffzNxmHpb tipA== X-Gm-Message-State: AD7BkJLL/njQpGWcqpIaRrzfdNp4wCL0jqvu3QCrglXWaKtaOk9b+VDL+8I9LtdRuckd3TPC X-Received: by 10.98.89.7 with SMTP id n7mr33991398pfb.81.1460401072979; Mon, 11 Apr 2016 11:57:52 -0700 (PDT) Received: from localhost.localdomain (cpe-172-248-200-249.socal.res.rr.com. [172.248.200.249]) by smtp.gmail.com with ESMTPSA id ke7sm22322404pad.44.2016.04.11.11.57.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Apr 2016 11:57:52 -0700 (PDT) From: Bartosz Golaszewski To: Wolfram Sang , linux-i2c , LKML , srinivas.kandagatla@linaro.org, maxime.ripard@free-electrons.com Cc: Andrew Lunn , Bartosz Golaszewski Subject: [RESEND PATCH v2 04/13] eeprom: at24: make locking more fine-grained Date: Mon, 11 Apr 2016 11:57:20 -0700 Message-Id: <1460401049-25459-5-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1460401049-25459-1-git-send-email-bgolaszewski@baylibre.com> References: <1460401049-25459-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The only field in struct at24_data that needs locking in the module code is u8 *writebuf. Other data is already protected by i2c core. Rename the lock in at24_data to wrbuf_lock and only use it where writebuf is accessed. Signed-off-by: Bartosz Golaszewski --- drivers/misc/eeprom/at24.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) -- 2.7.4 diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 744c526..9e01428 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -59,13 +59,8 @@ struct at24_data { int use_smbus; int use_smbus_write; - /* - * Lock protects against activities from other Linux tasks, - * but not from changes by other I2C masters. - */ - struct mutex lock; - u8 *writebuf; + struct mutex wrbuf_lock; unsigned write_max; unsigned num_addresses; @@ -260,12 +255,6 @@ static ssize_t at24_read(struct at24_data *at24, if (unlikely(!count)) return count; - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&at24->lock); - while (count) { ssize_t status; @@ -281,8 +270,6 @@ static ssize_t at24_read(struct at24_data *at24, retval += status; } - mutex_unlock(&at24->lock); - return retval; } @@ -322,6 +309,8 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf, msg.addr = client->addr; msg.flags = 0; + mutex_lock(&at24->wrbuf_lock); + /* msg.buf is u8 and casts will mask the values */ msg.buf = at24->writebuf; if (at24->chip.flags & AT24_FLAG_ADDR16) @@ -356,6 +345,7 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf, status = count; } else { status = i2c_transfer(client->adapter, &msg, 1); + mutex_unlock(&at24->wrbuf_lock); if (status == 1) status = count; } @@ -380,12 +370,6 @@ static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off, if (unlikely(!count)) return count; - /* - * Write data to chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&at24->lock); - while (count) { ssize_t status; @@ -401,8 +385,6 @@ static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off, retval += status; } - mutex_unlock(&at24->lock); - return retval; } @@ -566,7 +548,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) if (!at24) return -ENOMEM; - mutex_init(&at24->lock); + mutex_init(&at24->wrbuf_lock); at24->use_smbus = use_smbus; at24->use_smbus_write = use_smbus_write; at24->chip = chip;