From patchwork Sun May 29 21:53:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 68810 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1113823qge; Sun, 29 May 2016 14:57:38 -0700 (PDT) X-Received: by 10.66.81.193 with SMTP id c1mr40957103pay.33.1464559058424; Sun, 29 May 2016 14:57:38 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si31800265pfs.35.2016.05.29.14.57.38; Sun, 29 May 2016 14:57:38 -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 S1161040AbcE2V5h (ORCPT + 1 other); Sun, 29 May 2016 17:57:37 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:36391 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753267AbcE2VyR (ORCPT ); Sun, 29 May 2016 17:54:17 -0400 Received: by mail-wm0-f41.google.com with SMTP id n129so61528847wmn.1 for ; Sun, 29 May 2016 14:54:16 -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=cjC/riXQItI3U1Bt2lLpSdmLanfLLGXBu+Vq3gfTNdnCg4rDwZQw3zUlXoZ4XbcuUM fmof8WukAIP1BnBJvRUvLKuH1nKL2DMCKK3Q6M9hxAWHWUz0JRxJA4aqITPfbTzFRpJW Oh2PY8fxBE4uos6apFyYywCgqiiyRJO5p9L4BYV6WtLSktV7jxV5VRXLhQy6NpzpEZpw 7xUA2mIL+a6bECkUbH4Edfz3horVwGGCnC8NewR65xdN3t1Wv0LftCitXtG0ZIgJQBlU /pKu2DPMDcPBwZTXS8wkoJDUnU3b1ng35E+XnHFVECb278hxHPdD6hGJFYzlmZsofFov 66Cw== 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=MxpPg9D6R5vFeIYQ8QzG+xOWb1gazNsQH7khO9/gKPiXYcyZdaP1ltJ3xciF8Dnmam 2VKyNQJNq10Xl+z8WeDSJN3xuI2TOHxgNMN047sVsxNlGw3XTopL55DH36HuHnjxPlKp zjttoKsbx/Hdpy8uVgz+S2BPJ1Nq4h7tEsnFEOTveoe/Ol0I1dJRE2M1bhFP8ZaWmIJ8 GC7FJH2cvFMBuvdxf1jVi9+oC0pTKPWfqzyHpkgixqL7fJ04hjZB56VAMT5ZTqHDIzLa I3rhJRwTW7iJDhmPavPvAqKt7kYPtO2AB24YaBGe/vw+lFvbb7IEM6xfbNzijSbdlD4g LLeg== X-Gm-Message-State: ALyK8tJOnZxXNG46PZsveSWRlmYbMRPHMaWHB7LonD7jRCALrSthdxDrhxLbqRVo7GVJkAAG X-Received: by 10.28.27.8 with SMTP id b8mr8008719wmb.78.1464558855811; Sun, 29 May 2016 14:54:15 -0700 (PDT) Received: from bgdev-debian.lan (jua06-1-82-242-157-225.fbx.proxad.net. [82.242.157.225]) by smtp.gmail.com with ESMTPSA id a128sm20490367wme.16.2016.05.29.14.54.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 29 May 2016 14:54:15 -0700 (PDT) From: Bartosz Golaszewski To: Wolfram Sang , linux-i2c , LKML , Andrew Lunn , Srinivas Kandagatla , Maxime Ripard , GregKH Cc: Bartosz Golaszewski Subject: [PATCH 04/14] eeprom: at24: call read/write functions via function pointers Date: Sun, 29 May 2016 23:53:42 +0200 Message-Id: <1464558832-2262-5-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464558832-2262-1-git-send-email-bgolaszewski@baylibre.com> References: <1464558832-2262-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 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 -- 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 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) {