]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
reset: Allow reset_get_by_name() with NULL name
authorSamuel Holland <samuel@sholland.org>
Sun, 22 Jan 2023 00:02:52 +0000 (18:02 -0600)
committerSean Anderson <seanga2@gmail.com>
Sun, 12 Feb 2023 18:44:20 +0000 (13:44 -0500)
This allows devm_reset_control_get(dev, NULL) to work and get the first
reset control, which is common in code ported from Linux.

Signed-off-by: Samuel Holland <samuel@sholland.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Link: https://lore.kernel.org/r/20230122000252.53642-2-samuel@sholland.org
drivers/reset/reset-uclass.c
include/reset.h
test/dm/reset.c

index bcef46039c215f031ac349a2158842e7f936ee05..b972faf01328313dcf75d7f4ea1d949a30b05396 100644 (file)
@@ -147,16 +147,18 @@ int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk)
 int reset_get_by_name(struct udevice *dev, const char *name,
                     struct reset_ctl *reset_ctl)
 {
-       int index;
+       int index = 0;
 
        debug("%s(dev=%p, name=%s, reset_ctl=%p)\n", __func__, dev, name,
              reset_ctl);
        reset_ctl->dev = NULL;
 
-       index = dev_read_stringlist_search(dev, "reset-names", name);
-       if (index < 0) {
-               debug("fdt_stringlist_search() failed: %d\n", index);
-               return index;
+       if (name) {
+               index = dev_read_stringlist_search(dev, "reset-names", name);
+               if (index < 0) {
+                       debug("fdt_stringlist_search() failed: %d\n", index);
+                       return index;
+               }
        }
 
        return reset_get_by_index(dev, index, reset_ctl);
index 965f02e0ceef64719403dd77195e49fd5c859a27..036a786d2acec66eeb3d4135cb1948d64c5556a6 100644 (file)
@@ -238,7 +238,8 @@ int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk);
  *
  * @dev:       The client device.
  * @name:      The name of the reset signal to request, within the client's
- *             list of reset signals.
+ *             list of reset signals, or NULL to request the first reset
+ *             signal in the list.
  * @reset_ctl: A pointer to a reset control struct to initialize.
  * Return: 0 if OK, or a negative error code.
  */
index 9c0045233642cc567c3228205a10be31098fd6bb..e2d6f456230c758364e34f32a335608a854e3edd 100644 (file)
@@ -35,8 +35,7 @@ static int dm_test_reset_base(struct unit_test_state *uts)
 
        /* Get the same reset port in 2 different ways and compare */
        ut_assertok(reset_get_by_index(dev, 0, &reset_method1));
-       ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 0,
-                                            &reset_method1_1));
+       ut_assertok(reset_get_by_name(dev, NULL, &reset_method1_1));
        ut_assertok(reset_get_by_index(dev, 1, &reset_method2));
        ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 1,
                                             &reset_method2_1));