Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp946893imm; Thu, 4 Oct 2018 06:03:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV61T6mZLBAZcfzYUerFB0rwqnOI5vhomsKA2vYFJ16qMqhTH0xA2PvtMKdZt5LPZwUG261X2 X-Received: by 2002:a17:902:7244:: with SMTP id c4-v6mr6568942pll.339.1538658228962; Thu, 04 Oct 2018 06:03:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538658228; cv=none; d=google.com; s=arc-20160816; b=BJffa+esZ3bDFheed/5tyZLxtUUJQOGSrQWT02ms97YoDTngqPj/dvH3xfDvI+inLr vhQ+iUPB+wRbi6BdO1njSbuRDVuBszCyJNiRr7uNbykSojpJaf6bXPOcFRZjegyzVO4o WFGn835lKsC9uUcQYx4jLW0y6eOJcXlluZDoZ0Ny1O6wfGzfpa2afds5ihzhLCz8Jnbk Pp00vzBAKWmdnJL8/Hj7SYuUuhyZ4kHgZrKXoBHfM1sTzLffOPmfeAlgqVwz6s/Z/QTQ r6jaDEFPt+bSp7M356uoE9LIJfmaf/4EcZRcbxblCABaubIGVCugTIEK24yXNvUpK/Ge a6ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zPXLWgPAM9TKQD8PmLyfoPaLlJmlL7ExTK2t4PzAkrc=; b=Kf7QtTgj6koDdAS3mxp7lIJ3O3WoGh8sxtbosSGExU2Aub0ebIPFGv8SU7prfZJyKa UAnmhYlZT1bsq0dRX9opNPQz1wH2KiFg/+SDZGn7unysqk5Cr8dpMwp2MYRIyGVIMmEk SGIEeNa+/p/1fgmByetN90Q0mjTgt+aLeOKoFzOVxg3yF1bzo1Sp8fmQX+MaJd7eS6jx 3eYTONlz7Wsl7sYjiDRyw8yUEBzzxrvAivGmhzCyUn7le95Aho7QX3gFB+xlUiZM3ns1 S/DhWPXMzjSAIDhVavV2RbZUwZthHdb9B6oG/dWAeTkQt/N366n6jJmU1sZKPeKd/yO8 rsYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=blfNUV8L; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y15-v6si4888538plp.371.2018.10.04.06.03.32; Thu, 04 Oct 2018 06:03:48 -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=@gmail.com header.s=20161025 header.b=blfNUV8L; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727666AbeJDTyt (ORCPT + 99 others); Thu, 4 Oct 2018 15:54:49 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:33812 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727648AbeJDTyr (ORCPT ); Thu, 4 Oct 2018 15:54:47 -0400 Received: by mail-lf1-f65.google.com with SMTP id y10-v6so6712276lfj.1 for ; Thu, 04 Oct 2018 06:01:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zPXLWgPAM9TKQD8PmLyfoPaLlJmlL7ExTK2t4PzAkrc=; b=blfNUV8Li7VdqR7yIcIf84B8bEzopdp6zO2+jdYMtxaUWeE7vPvRwfRC1XZyR+EdlM Ji+D2LCET+bp//Ij4ln9k5E97+2Frp+5i/7xNuHiEnBdGQTzy7oFelCamYNnudUUJycY vduc0vY3MypB4oRiB18EG/p8eKzVRdvWmQNNDbGvDdZeciSCObexH3xCSfcFAhqKLh5x k5JR3HAlvoznDl20rZJDh9hhSH4HQgJOsWt6c+lwIJFDpVZGWXy5bYqRX8hZkc5HFs5R NEM3gsbxV5FQLGBATofBbMagLoWvO7077Qvm3X/lz7KSIKaKbWbaGF9Zyc0vE+Btc8gy pGqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zPXLWgPAM9TKQD8PmLyfoPaLlJmlL7ExTK2t4PzAkrc=; b=Pyr0IpeODh+eSLLh1CQdkVJY5HOEQkPA9szAfxN7YPlF/2dF/o0K3LZlv2LvtHHJFS /eaaUZn1RQXVDVmujVuwhw0Snt9FpWTaT3HSXH/iYrpGAp7+Z4FSB9M5MHgop8hacfCu C9ncO98z1fETLQriAZs1NKlMJKeiDexqIkq8MsgnnY7mKatibDVFbAEkBsFiB/0d5KoX mC5Xgz6jM5qrDv+P8gWu/jTQVDeBxYdMryGx4BD+oaEbkNCE9r/0n1x8bmiaAxGJHWm8 DtUQnUGProtndSYQVJFe/AVPSEZkimDHuukbOtZF6b/WNdkqZu+oyHcBNYw0vEoinFWs zpHQ== X-Gm-Message-State: ABuFfoiTJZvITtKVnbusNf+cV75Gr7NXE+88+1oYrbIOM5g51ruRHIHy 56lOjP8SjkU1hU8YAw9l2G0= X-Received: by 2002:a19:964e:: with SMTP id y75-v6mr3763927lfd.58.1538658094203; Thu, 04 Oct 2018 06:01:34 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id a1-v6sm421415lfk.63.2018.10.04.06.01.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 06:01:32 -0700 (PDT) From: Ricardo Ribalda Delgado To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Zhouyang Jia , linux-mtd@lists.infradead.org, open list Cc: Ricardo Ribalda Delgado Subject: [PATCH v6 07/10] mtd: maps: gpio-addr-flash: Replace array with an integer Date: Thu, 4 Oct 2018 15:01:07 +0200 Message-Id: <20181004130110.8496-7-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181004130110.8496-1-ricardo.ribalda@gmail.com> References: <20181004130110.8496-1-ricardo.ribalda@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By replacing the array with an integer we can avoid completely the bit comparison loop if the value has not changed (by far the most common case). Signed-off-by: Ricardo Ribalda Delgado --- drivers/mtd/maps/gpio-addr-flash.c | 34 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c index 89cc8cce161b..47b12a6fead4 100644 --- a/drivers/mtd/maps/gpio-addr-flash.c +++ b/drivers/mtd/maps/gpio-addr-flash.c @@ -43,7 +43,7 @@ struct async_state { struct map_info map; size_t gpio_count; unsigned *gpio_addrs; - int *gpio_values; + unsigned int gpio_values; unsigned int win_order; }; #define gf_map_info_to_state(mi) ((struct async_state *)(mi)->map_priv_1) @@ -55,22 +55,25 @@ struct async_state { * * Rather than call the GPIO framework every time, cache the last-programmed * value. This speeds up sequential accesses (which are by far the most common - * type). We rely on the GPIO framework to treat non-zero value as high so - * that we don't have to normalize the bits. + * type). */ static void gf_set_gpios(struct async_state *state, unsigned long ofs) { - size_t i = 0; - int value; + int i; ofs >>= state->win_order; - do { - value = ofs & (1 << i); - if (state->gpio_values[i] != value) { - gpio_set_value(state->gpio_addrs[i], value); - state->gpio_values[i] = value; - } - } while (++i < state->gpio_count); + + if (ofs == state->gpio_values) + return; + + for (i = 0; i < state->gpio_count; i++) { + if ((ofs & BIT(i)) == (state->gpio_values & BIT(i))) + continue; + + gpio_set_value(state->gpio_addrs[i], !!(ofs & BIT(i))); + } + + state->gpio_values = ofs; } /** @@ -202,7 +205,7 @@ static const char * const part_probe_types[] = { */ static int gpio_flash_probe(struct platform_device *pdev) { - size_t i, arr_size; + size_t i; struct physmap_flash_data *pdata; struct resource *memory; struct resource *gpios; @@ -215,8 +218,7 @@ static int gpio_flash_probe(struct platform_device *pdev) if (!memory || !gpios || !gpios->end) return -EINVAL; - arr_size = sizeof(int) * gpios->end; - state = devm_kzalloc(&pdev->dev, sizeof(*state) + arr_size, GFP_KERNEL); + state = devm_kzalloc(&pdev->dev, sizeof(*state), GFP_KERNEL); if (!state) return -ENOMEM; @@ -226,9 +228,7 @@ static int gpio_flash_probe(struct platform_device *pdev) */ state->gpio_count = gpios->end; state->gpio_addrs = (void *)(unsigned long)gpios->start; - state->gpio_values = (void *)(state + 1); state->win_order = get_bitmask_order(resource_size(memory)) - 1; - memset(state->gpio_values, 0xff, arr_size); state->map.name = DRIVER_NAME; state->map.read = gf_read; -- 2.19.0