mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 08/32] usb: otg: always propagate failure to register parameters
Date: Mon,  5 Sep 2022 11:55:33 +0200	[thread overview]
Message-ID: <20220905095557.596891-9-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220905095557.596891-1-a.fatoum@pengutronix.de>

We assign the result of the first dev_add_param_enum() to a variable,
but don't use the variable for anything. Refactor device registration
and parameter addition to a new helper function and do error checking
right.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/usb/otg/otgdev.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/otg/otgdev.c b/drivers/usb/otg/otgdev.c
index 129b1cf5e14b..29cb0d362b9b 100644
--- a/drivers/usb/otg/otgdev.c
+++ b/drivers/usb/otg/otgdev.c
@@ -42,6 +42,22 @@ static const char *otg_mode_names[] = {
 	[USB_DR_MODE_OTG] = "otg",
 };
 
+static int register_otg_device(struct device_d *dev, struct otg_mode *otg)
+{
+	struct param_d *param_mode;
+	int ret;
+
+	ret = register_device(dev);
+	if (ret)
+		return ret;
+
+	param_mode = dev_add_param_enum(dev, "mode",
+			otg_set_mode, NULL, &otg->var_mode,
+			otg_mode_names, ARRAY_SIZE(otg_mode_names), otg);
+
+	return PTR_ERR_OR_ZERO(param_mode);
+}
+
 static struct device_d otg_device = {
 	.name = "otg",
 	.id = DEVICE_ID_SINGLE,
@@ -51,7 +67,6 @@ int usb_register_otg_device(struct device_d *parent,
 			    int (*set_mode)(void *ctx, enum usb_dr_mode mode), void *ctx)
 {
 	int ret;
-	struct param_d *param_mode;
 	struct otg_mode *otg;
 
 	otg = xzalloc(sizeof(*otg));
@@ -68,22 +83,10 @@ int usb_register_otg_device(struct device_d *parent,
 	/* register otg.mode as an alias of otg0.mode */
 	if (otg_device.parent == NULL) {
 		otg_device.parent = parent;
-		ret = register_device(&otg_device);
+		ret = register_otg_device(&otg_device, otg);
 		if (ret)
 			return ret;
-
-		param_mode = dev_add_param_enum(&otg_device, "mode",
-				otg_set_mode, NULL, &otg->var_mode,
-				otg_mode_names, ARRAY_SIZE(otg_mode_names), otg);
 	}
 
-	ret = register_device(&otg->dev);
-	if (ret)
-		return ret;
-
-	param_mode = dev_add_param_enum(&otg->dev, "mode",
-			otg_set_mode, NULL, &otg->var_mode,
-			otg_mode_names, ARRAY_SIZE(otg_mode_names), otg);
-
-	return PTR_ERR_OR_ZERO(param_mode);
+	return register_otg_device(&otg->dev, otg);
 }
-- 
2.30.2




  parent reply	other threads:[~2022-09-05 15:36 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-05  9:55 [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 01/32] clk: define stub implementation for clk_get_parent Ahmad Fatoum
2022-09-12  9:23   ` Sascha Hauer
2022-09-05  9:55 ` [PATCH 02/32] clk: have SCMI and SiFive clock controllers depend on COMMON_CLK Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 03/32] meminfo: support SANDBOX build with DEBUG log level Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 04/32] net: phy: micrel: drop useless assignment of dummy read Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 05/32] mci: core: drop useless assignment Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 06/32] nvmem: core: propagate read failure Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 07/32] fs: remove never-read initializer in mount_all() Ahmad Fatoum
2022-09-05  9:55 ` Ahmad Fatoum [this message]
2022-09-05  9:55 ` [PATCH 09/32] usb: dwc2: gracefully handle unknown hs_phy_type Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 10/32] state: propagate failure to fixup enum32 into DT Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 11/32] of: silence warning about never-read error assignment Ahmad Fatoum
2022-09-12  9:41   ` Sascha Hauer
2022-09-05  9:55 ` [PATCH 12/32] commands: trigger: drop unused variable Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 13/32] commands: tutorial: fix memory leak Ahmad Fatoum
2022-09-12  9:44   ` Sascha Hauer
2022-09-05  9:55 ` [PATCH 14/32] bthread: fix null pointer dereference in error path Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 15/32] common: env: drop never-read initialization Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 16/32] of: refactor for of_fixup_reserved_memory() for clarity Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 17/32] password: avoid static analyzer false positive Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 18/32] regmap-mmio: regmap_mmio_get_min_stride: unify branches for readability Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 19/32] crypto: caam - delete unused variable Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 20/32] misc: ubootvar: always initialize struct ubootvar_data::flag Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 21/32] nvmem: core: drop always true condition Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 22/32] of: fdt: gracefully handle out-of-place properties Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 23/32] of: overlay: drop unused variable of_overlay_apply_dir() Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 24/32] of: partition: drop unused variable Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 25/32] serial: ns16550_pci: drop useless assignment Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 26/32] phy: core: drop useless else clause Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 27/32] fs: ext4: ext_barebox: handle ext_get_inode() errors Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 28/32] fs: fat: propagate f_lseek failure Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 29/32] fs: drop duplicate follow_managed() call Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 30/32] lib: parse_area_spec: guard against NULL pointer dereference Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 31/32] net: ping: propagate failure Ahmad Fatoum
2022-09-05  9:55 ` [PATCH 32/32] net: fastboot: keep error message initialized at all times Ahmad Fatoum
2022-09-12 10:06 ` [PATCH 00/32] treewide: fix some clang-analyze static analyzer warnings Sascha Hauer

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=20220905095557.596891-9-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --subject='Re: [PATCH 08/32] usb: otg: always propagate failure to register parameters' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox