From patchwork Mon Jun 6 08:48:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 69380 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp1376916qgf; Mon, 6 Jun 2016 01:54:45 -0700 (PDT) X-Received: by 10.98.92.133 with SMTP id q127mr24623319pfb.103.1465203284934; Mon, 06 Jun 2016 01:54:44 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xu8si25419665pac.159.2016.06.06.01.54.44; Mon, 06 Jun 2016 01:54:44 -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 S1752321AbcFFIyl (ORCPT + 31 others); Mon, 6 Jun 2016 04:54:41 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:38497 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751291AbcFFItL (ORCPT ); Mon, 6 Jun 2016 04:49:11 -0400 Received: by mail-wm0-f48.google.com with SMTP id m124so62171189wme.1 for ; Mon, 06 Jun 2016 01:49:11 -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=GJk3oAd8JaDSV06lsxhbMu/t/JDfjL14nScojTdq8hA=; b=vrJr/JB/z+Q79iqSx87t+R85F6xOoUw+hvaq9JYOY7ymfKQcqTGaLOF+eZmjKED1ff +KpTVc0jsCE0E1QK4qkVLuNlDkn+3FiFQoIQXryKcHfXB+WMmZPcLHapp2XLGcMZPH0M ie4emK3vWS01ytmVlnWkYRpUI8+X7GUVkTitLi52glWErTOimobOuq104oxrZN5oExPv FCOAyd6P6odJ3uvn9hDlMKLonERq7CVv5/+Wb03EWyHYhIl7l75NXyYzT7mWYsljz9FX dCgqYN6IQs5NF/IJTLiK4HX6LNqMb258crjL9DZprm7jm/VJrPflV71kfl9hRpVTsqKx V6HQ== 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=GJk3oAd8JaDSV06lsxhbMu/t/JDfjL14nScojTdq8hA=; b=Y24GTQs+G1K1/jLmrJneD35D7eS1F/N5epfT5twGl8+akKL4mmICPgN5jqQ02POxkL PJOwdB6qPEs+RPuX4clN8/97SofWMhIR9j7PP7DYrZKaqkgZiintp54r4qNrx705Dn4z qkvuDmLm1JomuF9P3qQwYTXFmOE6m6uLuViceYhjJos0NNS/8OsARLc58mVBS2G8PwlV nK6t7T3bjSX71VhkKz2JmeR+qdtHWt/pFyFnwdMZON4tJxyKv9kgyfleHZ4oHcbtZix8 FrCDmPtm/7nhBKHhhWShukD5iiDfe8ueuyS18UQclGFxhNd/6iqYk34MP6srScgyZ+ci SBNQ== X-Gm-Message-State: ALyK8tKwgvpQViDBt3cXt+OkGr+I4Bl4762nogWIQP/Jn2uyJ4BWfFtf3VUJIP7cQJVoqwhS X-Received: by 10.28.12.199 with SMTP id 190mr10431077wmm.15.1465202950338; Mon, 06 Jun 2016 01:49:10 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id dd7sm19090384wjb.22.2016.06.06.01.49.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Jun 2016 01:49:09 -0700 (PDT) From: Bartosz Golaszewski To: Wolfram Sang , linux-i2c , LKML , Andrew Lunn , Srinivas Kandagatla , Maxime Ripard , GregKH Cc: Bartosz Golaszewski Subject: [RESEND PATCH 04/14] eeprom: at24: call read/write functions via function pointers Date: Mon, 6 Jun 2016 10:48:46 +0200 Message-Id: <1465202936-16832-5-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1465202936-16832-1-git-send-email-bgolaszewski@baylibre.com> References: <1465202936-16832-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 first step in simplifying the read and write functions is to call them via function pointers stored in at24_data. When we eventually split the routines into smaller ones (depending on whether they use smbus or i2c operations) we'll simply assign them to said pointers instead of checking the flags at runtime every time we read/write. Signed-off-by: Bartosz Golaszewski --- drivers/misc/eeprom/at24.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 564a201..0621937 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -58,6 +58,10 @@ struct at24_data { int use_smbus; int use_smbus_write; + ssize_t (*read_func)(struct at24_data *, char *, unsigned int, size_t); + ssize_t (*write_func)(struct at24_data *, + const char *, unsigned int, size_t); + /* * Lock protects against activities from other Linux tasks, * but not from changes by other I2C masters. @@ -351,7 +355,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count) while (count) { int status; - status = at24_eeprom_read(at24, buf, off, count); + status = at24->read_func(at24, buf, off, count); if (status < 0) { mutex_unlock(&at24->lock); return status; @@ -383,7 +387,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count) while (count) { int status; - status = at24_eeprom_write(at24, buf, off, count); + status = at24->write_func(at24, buf, off, count); if (status < 0) { mutex_unlock(&at24->lock); return status; @@ -518,6 +522,9 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) at24->chip = chip; at24->num_addresses = num_addresses; + at24->read_func = at24_eeprom_read; + at24->write_func = at24_eeprom_write; + writable = !(chip.flags & AT24_FLAG_READONLY); if (writable) { if (!use_smbus || use_smbus_write) {