Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3857878imm; Mon, 1 Oct 2018 05:46:12 -0700 (PDT) X-Google-Smtp-Source: ACcGV62J+tU/Mq8DknQowsu+e3JF8G4UjGRPdY0fVliCt+2CKPcQPnqyHj3ofETNsHJeyVKIkrWH X-Received: by 2002:a63:5f03:: with SMTP id t3-v6mr10216330pgb.68.1538397972607; Mon, 01 Oct 2018 05:46:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538397972; cv=none; d=google.com; s=arc-20160816; b=rlJNziASp6ABDpOh7fApHedfN8Y0r+tZetzUj/rsPWYM7aAyT8jijnQvm842G2cUBO nqCpXNE48KA5cxzDzJ6f6ECbaoeT4j3WVxGOkN/VskvauO6wM4pIHGv9/MX42kbxBMLt pcmjzfZztiMp2T7pzzRBpx8o0eSZJt96wPQSZo6krCfXzSRyaD4JtcXbwPn1iO7/L3nP ktstmcH4rN4RMKsiCAVMNxbAAC1AVQPYZPBRnhFcBt7D8886U12fiPhBEXx6TmdHvrqS GGFnbgSYgzpc8+ClgV4M07HM+G52Q8IpcHdxYcggKHhcLEu3a7TBwCg+y1doz7f49TZN +6QA== 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=TM8L5a4kjNJXJQvHqXpT+QpKq+iu4oC8VHd7VrW7iN+hgEDEnvKz+j1pwOodWLPfP/ jqUQjjJavZhZKzD7bl1ildjEq8Vb+S0vGLz7Q4CJHPNbrEQXrhhU4WwjH3ATg+8Lr+Sj JobaQsKm0+j2br5lLHVT7+qZ/lzFFje+XSH888552AUsHSO8QmDyza5dRpVxq97nx+GQ 0SACxy4NhcxiRZZyUZkBdD7JJN+pCbYq8w1Kwmf3BYX9MoIOuAiSSTpI+I8rozxEKBmo 8gNz6r7gvJFLMhz/FmBaz6hEJkLIAhjDWwQCsWgCYocG3B9fP/8Uj4ogXynyaILBLV+0 ulxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mACUNn18; 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 m20-v6si12338230pgk.579.2018.10.01.05.45.57; Mon, 01 Oct 2018 05:46:12 -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=mACUNn18; 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 S1729527AbeJATVn (ORCPT + 99 others); Mon, 1 Oct 2018 15:21:43 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:44627 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729480AbeJATVm (ORCPT ); Mon, 1 Oct 2018 15:21:42 -0400 Received: by mail-ed1-f68.google.com with SMTP id t11-v6so14043891edq.11 for ; Mon, 01 Oct 2018 05:44:02 -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=mACUNn18Ky2W8FDSUPahbae8krLe3WGzpfzh1fvuHvaeqhiirNzHBgdjLSBYV2nA6s EMHqMbUYROmDvXxsjfPxW0iXFAu/OrSBhld04+aaTV9kAXXu83O6beIjKhBjeiE6ZXyT CHiMUX4bconTCmLc0b/8oGcvUo0nYv9u/cgNW5tjIt1z2UmNXauC31QW5LwezVvBtNzU J0QZIsQfn2Rrf3A2xCgqDT3TiH9o1enltFH/n1Q79RUAmSkca+xhdGGdT6l4bGKX8Q1J YL7e6S9+qR/0u9Iv1e4Rxs8stjvdQHrxCmtj0l815PbRZx7AvMO1+odKOiRPjDDrfDRp EHDg== 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=JA5yge+KkR4/Dfi0dkWBE+fq0xZ1LOagETI5m2mAv8Puu7/cYN3FpAunZevMpAstVx ZZz5BFMxNrIXpFe9fp08jNU/7s58iShn1T8gOII6XxDh1iBF/3TkSG013UYmrdTgnxMn td2sl8Kl3X4cNWSbocrNrvxCq2xgk4isZpNN/yxpNO9TdUmL5ih6yUi2CcLdu2RHTBkl 8E+WYbfXYSG0jvV2gjiSDByZeDnZ1LTJrmdHIvbw1Uu4nFGIlSL5a8RbGbvYxoXatYww rWiuiSkZD32uC5WleupHAzl3XQ06RvexPj5Q1/jPEoDY76z9D3qSS7oj8md1W7TGjDwI rBew== X-Gm-Message-State: ABuFfohxz/1Ta9uQa9PJTSbqXlTygNjm7u7wQRlT4iV1zxxYMHrgZO8l kV9+GlL8vOU8yL5zKoWNBSoFU/uE X-Received: by 2002:a50:9949:: with SMTP id l9-v6mr17051120edb.277.1538397842150; Mon, 01 Oct 2018 05:44:02 -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 h3-v6sm5278700ede.42.2018.10.01.05.44.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Oct 2018 05:44:00 -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 v4 5/8] mtd: maps: gpio-addr-flash: Replace array with an integer Date: Mon, 1 Oct 2018 14:43:48 +0200 Message-Id: <20181001124351.31615-5-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181001124351.31615-1-ricardo.ribalda@gmail.com> References: <20181001124351.31615-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