All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Álvaro Fernández Rojas" <noltari@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 05/14] cmd: cpu: refactor to ensure devices are probed and improve code style
Date: Sun, 23 Apr 2017 10:43:47 +0200	[thread overview]
Message-ID: <1492937036-31171-6-git-send-email-noltari@gmail.com> (raw)
In-Reply-To: <1492937036-31171-1-git-send-email-noltari@gmail.com>

Use uclass_first_device and uclass_next_device in order to avoid exceptions
for drivers that aren't probed when cpu ops are requested.
Improve code style and fix indentations.
Fix incorrect line break when cpu info is not available.
Remove unneeded brackets.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 v5: No changes.
 v4: Refactor code to use uclass_first_device and uclass_next_device as
  requested by Simon Glass.
 v3: add new patch to ensure that device is probed.

 cmd/cpu.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/cmd/cpu.c b/cmd/cpu.c
index adfd54a..6213c72 100644
--- a/cmd/cpu.c
+++ b/cmd/cpu.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2015 Google, Inc
  * Written by Simon Glass <sjg@chromium.org>
+ * Copyright (c) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
  *
  * SPDX-License-Identifier:	GPL-2.0+
  */
@@ -21,20 +22,15 @@ static const char *cpu_feature_name[CPU_FEAT_COUNT] = {
 static int print_cpu_list(bool detail)
 {
 	struct udevice *dev;
-	struct uclass *uc;
 	char buf[100];
-	int ret;
 
-	ret = uclass_get(UCLASS_CPU, &uc);
-	if (ret) {
-		printf("Cannot find CPU uclass\n");
-		return ret;
-	}
-	uclass_foreach_dev(dev, uc) {
+	for (uclass_first_device(UCLASS_CPU, &dev);
+		     dev;
+		     uclass_next_device(&dev)) {
 		struct cpu_platdata *plat = dev_get_parent_platdata(dev);
 		struct cpu_info info;
-		bool first;
-		int i;
+		bool first = true;
+		int ret, i;
 
 		ret = cpu_get_desc(dev, buf, sizeof(buf));
 		printf("%3d: %-10s %s\n", dev->seq, dev->name,
@@ -45,13 +41,12 @@ static int print_cpu_list(bool detail)
 		if (ret) {
 			printf("\t(no detail available");
 			if (ret != -ENOSYS)
-				printf(": err=%d\n", ret);
+				printf(": err=%d", ret);
 			printf(")\n");
 			continue;
 		}
 		printf("\tID = %d, freq = ", plat->cpu_id);
 		print_freq(info.cpu_freq, "");
-		first = true;
 		for (i = 0; i < CPU_FEAT_COUNT; i++) {
 			if (info.features & (1 << i)) {
 				printf("%s%s", first ? ": " : ", ",
@@ -60,10 +55,9 @@ static int print_cpu_list(bool detail)
 			}
 		}
 		printf("\n");
-		if (info.features & (1 << CPU_FEAT_UCODE)) {
+		if (info.features & (1 << CPU_FEAT_UCODE))
 			printf("\tMicrocode version %#x\n",
 			       plat->ucode_version);
-		}
 		if (info.features & (1 << CPU_FEAT_DEVICE_ID))
 			printf("\tDevice ID %#lx\n", plat->device_id);
 	}
@@ -71,7 +65,8 @@ static int print_cpu_list(bool detail)
 	return 0;
 }
 
-static int do_cpu_list(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+static int do_cpu_list(cmd_tbl_t *cmdtp, int flag, int argc,
+		       char *const argv[])
 {
 	if (print_cpu_list(false))
 		return CMD_RET_FAILURE;
@@ -97,7 +92,7 @@ static cmd_tbl_t cmd_cpu_sub[] = {
  * Process a cpu sub-command
  */
 static int do_cpu(cmd_tbl_t *cmdtp, int flag, int argc,
-		       char * const argv[])
+		  char * const argv[])
 {
 	cmd_tbl_t *c = NULL;
 
@@ -106,7 +101,8 @@ static int do_cpu(cmd_tbl_t *cmdtp, int flag, int argc,
 	argv++;
 
 	if (argc)
-		c = find_cmd_tbl(argv[0], cmd_cpu_sub, ARRAY_SIZE(cmd_cpu_sub));
+		c = find_cmd_tbl(argv[0], cmd_cpu_sub,
+				 ARRAY_SIZE(cmd_cpu_sub));
 
 	if (c)
 		return c->cmd(cmdtp, flag, argc, argv);
-- 
2.1.4

  parent reply	other threads:[~2017-04-23  8:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-23  8:43 [U-Boot] [PATCH v5 00/14] Add support for Broadcom MIPS SoCs Álvaro Fernández Rojas
2017-04-23  8:43 ` [U-Boot] [PATCH v5 01/14] cmd: cpu: fix NULL cpu feature prints Álvaro Fernández Rojas
2017-04-23  8:43 ` [U-Boot] [PATCH v5 02/14] sysreset: add syscon-reboot driver Álvaro Fernández Rojas
2017-04-23 20:16   ` Daniel Schwierzeck
2017-04-23  8:43 ` [U-Boot] [PATCH v5 03/14] MIPS: allow using generic sysreset drivers Álvaro Fernández Rojas
2017-04-23  8:43 ` [U-Boot] [PATCH v5 04/14] serial: add serial driver for BCM6345 Álvaro Fernández Rojas
2017-04-23 20:12   ` Daniel Schwierzeck
2017-04-23  8:43 ` Álvaro Fernández Rojas [this message]
2017-04-24  3:39   ` [U-Boot] [PATCH v5 05/14] cmd: cpu: refactor to ensure devices are probed and improve code style Simon Glass
2017-04-23  8:43 ` [U-Boot] [PATCH v5 06/14] cpu: add CPU driver for Broadcom MIPS SoCs Álvaro Fernández Rojas
2017-04-24  3:39   ` Simon Glass
2017-04-23  8:43 ` [U-Boot] [PATCH v5 07/14] ram: add RAM " Álvaro Fernández Rojas
2017-04-23  8:43 ` [U-Boot] [PATCH v5 08/14] MIPS: add initial infrastructure " Álvaro Fernández Rojas
2017-04-23 20:23   ` Daniel Schwierzeck
2017-04-24 10:25     ` Álvaro Fernández Rojas
2017-04-23  8:43 ` [U-Boot] [PATCH v5 09/14] MIPS: add support for Broadcom MIPS BCM6358 SoC family Álvaro Fernández Rojas
2017-04-23  8:43 ` [U-Boot] [PATCH v5 10/14] MIPS: add BMIPS Huawei HG556a board Álvaro Fernández Rojas
2017-04-23  8:43 ` [U-Boot] [PATCH v5 11/14] MIPS: add support for Broadcom MIPS BCM6328 SoC family Álvaro Fernández Rojas
2017-04-23  8:43 ` [U-Boot] [PATCH v5 12/14] MIPS: add BMIPS Comtrend AR-5387un board Álvaro Fernández Rojas
2017-04-23  8:43 ` [U-Boot] [PATCH v5 13/14] MIPS: add support for Broadcom MIPS BCM63268 SoC family Álvaro Fernández Rojas
2017-04-23  8:43 ` [U-Boot] [PATCH v5 14/14] MIPS: add BMIPS Comtrend VR-3032u board Álvaro Fernández Rojas

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=1492937036-31171-6-git-send-email-noltari@gmail.com \
    --to=noltari@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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.