From patchwork Thu Mar 24 16:19:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 64410 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp757112lbc; Thu, 24 Mar 2016 09:21:30 -0700 (PDT) X-Received: by 10.98.75.147 with SMTP id d19mr13888399pfj.29.1458836472145; Thu, 24 Mar 2016 09:21:12 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o4si2946545pap.178.2016.03.24.09.21.11; Thu, 24 Mar 2016 09:21:12 -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 S1757623AbcCXQVK (ORCPT + 1 other); Thu, 24 Mar 2016 12:21:10 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:37907 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756172AbcCXQTw (ORCPT ); Thu, 24 Mar 2016 12:19:52 -0400 Received: by mail-wm0-f48.google.com with SMTP id l68so73702540wml.1 for ; Thu, 24 Mar 2016 09:19:51 -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=EuwkC0qJ2l6MzG9MSwW98+aaBogV/1i+2uUmfzSpCweRIpRWdZ0oPlfZKX6D/8/zoU TI5pLAtGkRzNsXfWMRC731LDSXnUY3rA4p5qLZEItmEp2PBls17b5Wqd+yQFBXWp87ym BvbXdk0AWVSDi17oe2jgC/D77pzadRb/CeIHlkrbrMCdZNGRhTkq+2PZlWG2i8I508OE +WUswkz+Hm1RrCMXZPt/6hH1fvA34o9fZoKt+F5H7t0Y+NG57At8tZdke7zpTpqyyDBX VcfasPmNvIHo8VgooO/eOYPiuQH8p047AatQUN1Ttpgwr9hwaemDZ7cIgP9nwVe5XGPd /pkQ== 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=IAArVomSM4BJ6zJWaKQ0fZCTfpoTLyeYhKZ9Hk3luG21MIr6mmIYK4hu8QycY4N18S OeFmd6JcL1WrpRFlPecr+tBK8ZV8iZ2TFPH910G51rOq2vM6V2h+78uR2YifYwI8viY9 XyA8FAKBLzRH/cGaBfwvnO2umq7QRdrJtOMNHBbnqRulSggUgNaT0FExwk7gJyitMjUE 2PdI+EJh/33qNI8OOFCml8hw5ohm7i/ahrv52EFXHwftMCDo5iIJqued/hCDxBUUMMG+ 9KwBwYI+5q2ZFDaRU7f4pUgUoMmDVyyDxPBwMD2SkMqf0wljkT2SxWmJ4GZZmugQhGdM iAlA== X-Gm-Message-State: AD7BkJKIZKI8fRDXhg4IN/jqAMAc7rXcXW7iC3srjFZ8tw+ptRtp6HlCeylFvqKjbp44KYfd X-Received: by 10.28.21.14 with SMTP id 14mr11168074wmv.39.1458836390602; Thu, 24 Mar 2016 09:19:50 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id k124sm8370718wmb.11.2016.03.24.09.19.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 24 Mar 2016 09:19:50 -0700 (PDT) From: Bartosz Golaszewski To: Wolfram Sang , linux-i2c , LKML Cc: Andrew Lunn , Bartosz Golaszewski Subject: [PATCH v2 04/13] eeprom: at24: make locking more fine-grained Date: Thu, 24 Mar 2016 17:19:34 +0100 Message-Id: <1458836383-6668-5-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1458836383-6668-1-git-send-email-bgolaszewski@baylibre.com> References: <1458836383-6668-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;