From patchwork Wed Apr 18 02:38:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133590 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp5390214ljb; Tue, 17 Apr 2018 19:39:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx48NVv71emox4t3FRBQh77gI7uR3etO8LXwd4VQX+6Y7BFhOWvKGMhDtYLXGwOKGtIUhlcWa X-Received: by 10.80.152.227 with SMTP id j90mr762561edb.89.1524019170851; Tue, 17 Apr 2018 19:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524019170; cv=none; d=google.com; s=arc-20160816; b=M7mgFylIyLt0Jhy1b8hz9lU44aCjwXMCm3ZEHBVSMQP9DZcBkdavVbH9PrAszLKEmB kHo0Au+r063Ri34l0J102Sp/O8V2v+kaOaYE+QV8+DinqihFwc+j9X5mjg9VQoTuRtyS yz+ltp4Y8unRUjBzGu2kOP4F+MZbanRJGkSuiyTKZd8VZIe/IbXDx2bQO53kMVflG2Hi Ev3gtwIbuuG+8t/qnTDe+yXH9788g2voxY7qQJi7P7zH+E8HRdPAese2DMtumJ1/MMKU hg67/bgtAnwL7/ixeLnpID4SFon18Znc+dhsPZhn0oSR1xxNfs46FUVOuDNeyM4U1QZ+ JwDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:dkim-filter:arc-authentication-results; bh=Xer/VdxesjFfDw1RoWtDZS9346EH8Rm1+dEQFpsyX1E=; b=fFlQyAjI04UOnxJEgNryGHBqH5nmP9imIhxkyC7v+p7gYt7cQQHudDzZq7whCxI+wv T9WP8c4t9G30M/C//uIGYIbL4/0vcIB3kEIVtIrBiQHucWHY6t7/qqnO0hxsWJwuy47w biStx69gpWGyrhxHL0kQhMApnRaiepckiNp9rxVNycS0FKdCXj74bhIUxLPKjUD64Ze+ DqZ23MGWAmEOmTX8qj+dh5vzcr5OpP+bkwbNRT/xsWnHh6mCqgnN2jdUbKYSureRpMDJ qvfyzDSSdrYwE9jniPbRPomV06oYOzVX7cbFP9YvAyY9BqJRLj8IEccGwH6lXpFoZndi IH3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=eBFWsj8v; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id q11si498925edj.185.2018.04.17.19.39.29; Tue, 17 Apr 2018 19:39:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=eBFWsj8v; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id B7F60C21DF3; Wed, 18 Apr 2018 02:39:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3B969C21DF3; Wed, 18 Apr 2018 02:39:26 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8D78CC21E0F; Wed, 18 Apr 2018 02:39:24 +0000 (UTC) Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lists.denx.de (Postfix) with ESMTPS id 9877EC21C27 for ; Wed, 18 Apr 2018 02:39:23 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id w3I2culD028728; Wed, 18 Apr 2018 11:38:57 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w3I2culD028728 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1524019138; bh=EaN3uTWbbNm2sWREhMs42a3PNI2jBtIthmWf2mrpiaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eBFWsj8vBOWmnB83UayGGCu3Y9HrmXsyu4syNzm4EzQzzLcYh18cpahdw5WaNfDED q4/qD+S4+LLi7PtKFLHZNN8/Ji2VAn1OfEpkL8NL/IL9aXp69B5/s491KS56cphMRb fIQ09y9reGIkmgO7lpBkxxdZkdBY60ZuE5udEPEsVWQM+aNLhYtzMy8cLKx25Q42YL n3QSC9XIyoMc3SPSN6JaUvUVbpGS2MAe1xfA0cFJ2zW9UQ81P/WUSbeYBXrHUK+GtM uKGC/sB/pou9Ckp2YnFqvyT+X8kEs4+8X/92w0Gvo4PnDXfzf5+tpRkXESKKDvwhBC 3JzeDZcMGm50Q== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Wed, 18 Apr 2018 11:38:42 +0900 Message-Id: <1524019125-26287-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524019125-26287-1-git-send-email-yamada.masahiro@socionext.com> References: <1524019125-26287-1-git-send-email-yamada.masahiro@socionext.com> Subject: [U-Boot] [PATCH 1/4] regmap: clean up regmap allocation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Putting zero length array at the end of struct is a common technique to embed arbitrary length of members. There is no good reason to let regmap_alloc_count() branch by "if (count <= 1)". As far as I understood the code, regmap->base is an alias of regmap->ranges[0].start, but it is not helpful but make the code just ugly. Rename regmap_alloc_count() to regmap_alloc() because the _count suffix seems pointless. Signed-off-by: Masahiro Yamada Reviewed-by: Simon Glass --- drivers/core/regmap.c | 31 +++++++++---------------------- include/regmap.h | 7 ++----- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c index 8a0e00f..6c3dbe9 100644 --- a/drivers/core/regmap.c +++ b/drivers/core/regmap.c @@ -18,22 +18,13 @@ DECLARE_GLOBAL_DATA_PTR; -static struct regmap *regmap_alloc_count(int count) +static struct regmap *regmap_alloc(int count) { struct regmap *map; - map = malloc(sizeof(struct regmap)); + map = malloc(sizeof(*map) + sizeof(map->ranges[0]) * count); if (!map) return NULL; - if (count <= 1) { - map->range = &map->base_range; - } else { - map->range = malloc(count * sizeof(struct regmap_range)); - if (!map->range) { - free(map); - return NULL; - } - } map->range_count = count; return map; @@ -46,12 +37,11 @@ int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count, struct regmap_range *range; struct regmap *map; - map = regmap_alloc_count(count); + map = regmap_alloc(count); if (!map) return -ENOMEM; - map->base = *reg; - for (range = map->range; count > 0; reg += 2, range++, count--) { + for (range = map->ranges; count > 0; reg += 2, range++, count--) { range->start = *reg; range->size = reg[1]; } @@ -84,11 +74,11 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp) if (!count) return -EINVAL; - map = regmap_alloc_count(count); + map = regmap_alloc(count); if (!map) return -ENOMEM; - for (range = map->range, index = 0; count > 0; + for (range = map->ranges, index = 0; count > 0; count--, range++, index++) { fdt_size_t sz; if (of_live_active()) { @@ -102,7 +92,6 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp) range->size = sz; } } - map->base = map->range[0].start; *mapp = map; @@ -116,15 +105,13 @@ void *regmap_get_range(struct regmap *map, unsigned int range_num) if (range_num >= map->range_count) return NULL; - range = &map->range[range_num]; + range = &map->ranges[range_num]; return map_sysmem(range->start, range->size); } int regmap_uninit(struct regmap *map) { - if (map->range_count > 1) - free(map->range); free(map); return 0; @@ -132,7 +119,7 @@ int regmap_uninit(struct regmap *map) int regmap_read(struct regmap *map, uint offset, uint *valp) { - uint32_t *ptr = map_physmem(map->base + offset, 4, MAP_NOCACHE); + u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE); *valp = le32_to_cpu(readl(ptr)); @@ -141,7 +128,7 @@ int regmap_read(struct regmap *map, uint offset, uint *valp) int regmap_write(struct regmap *map, uint offset, uint val) { - uint32_t *ptr = map_physmem(map->base + offset, 4, MAP_NOCACHE); + u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE); writel(cpu_to_le32(val), ptr); diff --git a/include/regmap.h b/include/regmap.h index 493a5d8..858aa7e 100644 --- a/include/regmap.h +++ b/include/regmap.h @@ -22,15 +22,12 @@ struct regmap_range { /** * struct regmap - a way of accessing hardware/bus registers * - * @base: Base address of register map * @range_count: Number of ranges available within the map - * @range: Pointer to the list of ranges, allocated if @range_count > 1 - * @base_range: If @range_count is <= 1, @range points here + * @ranges: Array of ranges */ struct regmap { - phys_addr_t base; int range_count; - struct regmap_range *range, base_range; + struct regmap_range ranges[]; }; /*