All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>,
	Russell King <linux@armlinux.org.uk>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] ARM: cache-uniphier: call kzalloc() after DT property parsing
Date: Fri,  4 Nov 2016 20:43:34 +0900	[thread overview]
Message-ID: <1478259816-24965-2-git-send-email-yamada.masahiro@socionext.com> (raw)
In-Reply-To: <1478259816-24965-1-git-send-email-yamada.masahiro@socionext.com>

Allocate memory after DT property parsing that has more possibility
of failure.  This will decrease the number of bail-out points for
kfree().

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 arch/arm/mm/cache-uniphier.c | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/arch/arm/mm/cache-uniphier.c b/arch/arm/mm/cache-uniphier.c
index dfe97b4..58f2ddb 100644
--- a/arch/arm/mm/cache-uniphier.c
+++ b/arch/arm/mm/cache-uniphier.c
@@ -328,7 +328,7 @@ static int __init __uniphier_cache_init(struct device_node *np,
 					unsigned int *cache_level)
 {
 	struct uniphier_cache_data *data;
-	u32 level, cache_size;
+	u32 level, line_size, nsets, cache_size;
 	struct device_node *next_np;
 	int ret = 0;
 
@@ -354,36 +354,34 @@ static int __init __uniphier_cache_init(struct device_node *np,
 		return -EINVAL;
 	}
 
-	data = kzalloc(sizeof(*data), GFP_KERNEL);
-	if (!data)
-		return -ENOMEM;
-
-	if (of_property_read_u32(np, "cache-line-size", &data->line_size) ||
-	    !is_power_of_2(data->line_size)) {
+	if (of_property_read_u32(np, "cache-line-size", &line_size) |
+	    !is_power_of_2(line_size)) {
 		pr_err("L%d: cache-line-size is unspecified or invalid\n",
 		       *cache_level);
-		ret = -EINVAL;
-		goto err;
+		return -EINVAL;
 	}
 
-	if (of_property_read_u32(np, "cache-sets", &data->nsets) ||
-	    !is_power_of_2(data->nsets)) {
+	if (of_property_read_u32(np, "cache-sets", &nsets) ||
+	    !is_power_of_2(nsets)) {
 		pr_err("L%d: cache-sets is unspecified or invalid\n",
 		       *cache_level);
-		ret = -EINVAL;
-		goto err;
+		return -EINVAL;
 	}
 
 	if (of_property_read_u32(np, "cache-size", &cache_size) ||
-	    cache_size == 0 || cache_size % (data->nsets * data->line_size)) {
+	    cache_size == 0 || cache_size % (nsets * line_size)) {
 		pr_err("L%d: cache-size is unspecified or invalid\n",
 		       *cache_level);
-		ret = -EINVAL;
-		goto err;
+		return -EINVAL;
 	}
 
-	data->way_present_mask =
-		((u32)1 << cache_size / data->nsets / data->line_size) - 1;
+	data = kzalloc(sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->line_size = line_size;
+	data->nsets = nsets;
+	data->way_present_mask = ((u32)1 << cache_size / nsets / line_size) - 1;
 
 	data->ctrl_base = of_iomap(np, 0);
 	if (!data->ctrl_base) {
-- 
1.9.1

WARNING: multiple messages have this Message-ID (diff)
From: yamada.masahiro@socionext.com (Masahiro Yamada)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/3] ARM: cache-uniphier: call kzalloc() after DT property parsing
Date: Fri,  4 Nov 2016 20:43:34 +0900	[thread overview]
Message-ID: <1478259816-24965-2-git-send-email-yamada.masahiro@socionext.com> (raw)
In-Reply-To: <1478259816-24965-1-git-send-email-yamada.masahiro@socionext.com>

Allocate memory after DT property parsing that has more possibility
of failure.  This will decrease the number of bail-out points for
kfree().

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 arch/arm/mm/cache-uniphier.c | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/arch/arm/mm/cache-uniphier.c b/arch/arm/mm/cache-uniphier.c
index dfe97b4..58f2ddb 100644
--- a/arch/arm/mm/cache-uniphier.c
+++ b/arch/arm/mm/cache-uniphier.c
@@ -328,7 +328,7 @@ static int __init __uniphier_cache_init(struct device_node *np,
 					unsigned int *cache_level)
 {
 	struct uniphier_cache_data *data;
-	u32 level, cache_size;
+	u32 level, line_size, nsets, cache_size;
 	struct device_node *next_np;
 	int ret = 0;
 
@@ -354,36 +354,34 @@ static int __init __uniphier_cache_init(struct device_node *np,
 		return -EINVAL;
 	}
 
-	data = kzalloc(sizeof(*data), GFP_KERNEL);
-	if (!data)
-		return -ENOMEM;
-
-	if (of_property_read_u32(np, "cache-line-size", &data->line_size) ||
-	    !is_power_of_2(data->line_size)) {
+	if (of_property_read_u32(np, "cache-line-size", &line_size) |
+	    !is_power_of_2(line_size)) {
 		pr_err("L%d: cache-line-size is unspecified or invalid\n",
 		       *cache_level);
-		ret = -EINVAL;
-		goto err;
+		return -EINVAL;
 	}
 
-	if (of_property_read_u32(np, "cache-sets", &data->nsets) ||
-	    !is_power_of_2(data->nsets)) {
+	if (of_property_read_u32(np, "cache-sets", &nsets) ||
+	    !is_power_of_2(nsets)) {
 		pr_err("L%d: cache-sets is unspecified or invalid\n",
 		       *cache_level);
-		ret = -EINVAL;
-		goto err;
+		return -EINVAL;
 	}
 
 	if (of_property_read_u32(np, "cache-size", &cache_size) ||
-	    cache_size == 0 || cache_size % (data->nsets * data->line_size)) {
+	    cache_size == 0 || cache_size % (nsets * line_size)) {
 		pr_err("L%d: cache-size is unspecified or invalid\n",
 		       *cache_level);
-		ret = -EINVAL;
-		goto err;
+		return -EINVAL;
 	}
 
-	data->way_present_mask =
-		((u32)1 << cache_size / data->nsets / data->line_size) - 1;
+	data = kzalloc(sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->line_size = line_size;
+	data->nsets = nsets;
+	data->way_present_mask = ((u32)1 << cache_size / nsets / line_size) - 1;
 
 	data->ctrl_base = of_iomap(np, 0);
 	if (!data->ctrl_base) {
-- 
1.9.1

  reply	other threads:[~2016-11-04 11:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-04 11:43 [PATCH 0/3] ARM: cache-uniphier: slight cleanups and trivial coding style fix Masahiro Yamada
2016-11-04 11:43 ` Masahiro Yamada
2016-11-04 11:43 ` Masahiro Yamada [this message]
2016-11-04 11:43   ` [PATCH 1/3] ARM: cache-uniphier: call kzalloc() after DT property parsing Masahiro Yamada
2016-11-04 11:43 ` [PATCH 2/3] ARM: cache-uniphier: refactor jump label to follow coding style guideline Masahiro Yamada
2016-11-04 11:43   ` Masahiro Yamada
2016-11-04 12:23   ` Russell King - ARM Linux
2016-11-04 12:23     ` Russell King - ARM Linux
2016-11-04 12:50     ` Masahiro Yamada
2016-11-04 12:50       ` Masahiro Yamada
2016-11-04 13:32       ` Russell King - ARM Linux
2016-11-04 13:32         ` Russell King - ARM Linux
2016-11-05  3:17         ` Masahiro Yamada
2016-11-05  3:17           ` Masahiro Yamada
2016-11-04 11:43 ` [PATCH 3/3] ARM: cache-uniphier: clean up active way setup code Masahiro Yamada
2016-11-04 11:43   ` Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1478259816-24965-2-git-send-email-yamada.masahiro@socionext.com \
    --to=yamada.masahiro@socionext.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.