From patchwork Thu Mar 24 14:45:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 64368 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp696694lbc; Thu, 24 Mar 2016 07:46:59 -0700 (PDT) X-Received: by 10.98.70.27 with SMTP id t27mr13205072pfa.107.1458830797278; Thu, 24 Mar 2016 07:46:37 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x14si1987457par.197.2016.03.24.07.46.37; Thu, 24 Mar 2016 07:46:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753902AbcCXOqd (ORCPT + 1 other); Thu, 24 Mar 2016 10:46:33 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:38043 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752272AbcCXOqS (ORCPT ); Thu, 24 Mar 2016 10:46:18 -0400 Received: by mail-wm0-f41.google.com with SMTP id l68so69339541wml.1 for ; Thu, 24 Mar 2016 07:46:17 -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=0KXSycVtXcBI2oQUZqNgySg44GLbTShs9EGiMb2A7J5H7cA1RHxfj/g4Rei7D/9Sek bAUrT5q4rdTlcgKxOqrjPC6qBUY4CgyWJZHkz6TjTmQ0ZIRCuHlH7kPtCspPOQZ9st9w ZmIgcsColq3npLemiiYhjJoWd3DIBbicPl9iEnCBIqYGdXAhyDgBVja2wxIwXEWi6/00 HQJz+TCbybgz3W4Qm6ULDYICFyZqwtuQHzVxWkmSkkvqkBtIjb3IFjxA/YDvRMsQ/H9E yb21ZZ6YPF55ryfnONJfYM4VUQr2Y/OVdrJfg81os2qPOJTH9PGvO18yTMaLuIcbhsZ1 Pe7A== 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=RQZbsvpR1we0YhKfeLpiHwHV2Qmiue1a537XlLPyPlVhY8XlEUpBWHiix9tcAUtzdu Ssacv8XpfdWcv9Bqw3RjHsyYRQ0HV4Sqss8MbweuJ53rURIfeyUkCe7E2tDyR660d5Xm XQhYTuE+F7sRBlW6pyuw2bS9aFBo+oHUEmhU6UHq17UfyBh36BIrPBYzj33nLcpyvi7v GrJ5L9qmb/FwmVsgJWSH+M09cdAKDLQJt8EWT7hNUrnPzQjxsF+1I4T1ba1T8gjBq23J PJcRRWB/sGApsVinNxX+hLBH/GZZHAIwOrWzZEt4Ctw/D1uBk3tzFCsTHhqzgrDjibkY 85UA== X-Gm-Message-State: AD7BkJI52uLkEhIk/i9kusg5Rljng6Lvc3FvaMSo8wfggZ0t4wofxDOkDnt+q2pydEMGdAry X-Received: by 10.28.179.7 with SMTP id c7mr11652245wmf.46.1458830775119; Thu, 24 Mar 2016 07:46:15 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id k125sm27255752wmb.14.2016.03.24.07.46.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 24 Mar 2016 07:46:14 -0700 (PDT) From: Bartosz Golaszewski To: Wolfram Sang , linux-i2c , LKML Cc: Andrew Lunn , Bartosz Golaszewski Subject: [PATCH 04/13] eeprom: at24: make locking more fine-grained Date: Thu, 24 Mar 2016 15:45:58 +0100 Message-Id: <1458830767-23816-5-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1458830767-23816-1-git-send-email-bgolaszewski@baylibre.com> References: <1458830767-23816-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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 -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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;