Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D616EC433EF for ; Wed, 30 Mar 2022 16:27:07 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 39C91840B3; Wed, 30 Mar 2022 18:27:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Qbs3D2rU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B6E84840DE; Wed, 30 Mar 2022 18:27:03 +0200 (CEST) Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 80A2484092 for ; Wed, 30 Mar 2022 18:26:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x82a.google.com with SMTP id c4so18500468qtx.1 for ; Wed, 30 Mar 2022 09:26:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tumLL9BR8ALtsg8GU+j7YANgx3QwJZEbqtQqo6MMbSI=; b=Qbs3D2rUr0Y+DVsyHlct2vYOgM3m7jtb/U7hjIp33mvEFtOBAvgykpBoCcN6JcK5/d K3FBYotaB6lVW57AFVtYmk31o4MXT9wQtlS1dVs9FTxELZ9kNkP4eYgvowBBmJPg51zW 6ho9CUte42o9a7NQPIsmJApPFGQSS0S1LoXEdx8PhH7hET92W9Rw+4D7B6Y1VVQTjHzW 85rTxh5nUspy6OuwTeFS7mxw14TFPI14xgp8gfg5luRA9Joh1t0f1k+HV+Upij6L3BEI iisLHS3O1Vh0vqgqNwZ1GfHJE5mObjmtcV1OVLFmcMo7wrsGI+xNgGEjQfCpK/Mog2As 1u4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tumLL9BR8ALtsg8GU+j7YANgx3QwJZEbqtQqo6MMbSI=; b=QUh3fVBOsCeDrKRDimAM0NEIDYSjJ4dilQEPDWrGBtUsb+vRUPnGap93H/kb3VPxPo ubXg1M93Fgjin+RDiZZX196DaIfdX9TtoIYu/lpuo3qfET80n6f4lbl2zqD9nxYhCHcP PrBsx+zmOUoiuhmrniDYy3rAtPF2DSUMH6no2iVqeaaYhSZja0KjFNkU05J8PjXN/d6e Jx5vZHGke+TGKrzrcH0ogGXVgITqK9q0pkegT1dD4WhDEzGyb82PhztJinwYhFklB3Pk 7aeV2rAWDlcnb4q3gudHuEx7nAq4CKf7Rrtp539E2v4ucPI90xPEvBwivB3Vs3AfPvHW my8g== X-Gm-Message-State: AOAM531TGM6tbobIiayClxHUMmla0s7JlEDLxnoH3o/0SrHgzuQDaST7 lbySf5+/0N+VrA3KkrieyTlNxMmTPGk= X-Google-Smtp-Source: ABdhPJy9ndewPFay1T8DvrAR8WbHkgF6zU76Q2U/CjQGZdjUENc8QZ7U+R6M3Xjzvx/gWyURPhbmlA== X-Received: by 2002:ac8:5c8a:0:b0:2e1:a65f:5122 with SMTP id r10-20020ac85c8a000000b002e1a65f5122mr300421qta.239.1648657614024; Wed, 30 Mar 2022 09:26:54 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-18-137-133.washdc.fios.verizon.net. [108.18.137.133]) by smtp.gmail.com with ESMTPSA id 3-20020a370503000000b0067b03f03589sm11038726qkf.53.2022.03.30.09.26.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 09:26:53 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de, Simon Glass Cc: Sean Anderson Subject: [PATCH] dm: core: Use device_foreach_child where possible Date: Wed, 30 Mar 2022 12:26:40 -0400 Message-Id: <20220330162640.428724-1-seanga2@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean We have some nice macros for iterating over devices in device.h, but they are not used by the driver core. Convert all the users I could find. Signed-off-by: Sean Anderson --- drivers/core/device-remove.c | 4 ++-- drivers/core/device.c | 21 ++++++++++----------- drivers/core/devres.c | 2 +- drivers/core/dump.c | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 73d2e9e420..a86b9325dd 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -29,7 +29,7 @@ int device_chld_unbind(struct udevice *dev, struct driver *drv) assert(dev); - list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) { + device_foreach_child_safe(pos, n, dev) { if (drv && (pos->driver != drv)) continue; @@ -52,7 +52,7 @@ int device_chld_remove(struct udevice *dev, struct driver *drv, assert(dev); - list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) { + device_foreach_child_safe(pos, n, dev) { int ret; if (drv && (pos->driver != drv)) diff --git a/drivers/core/device.c b/drivers/core/device.c index 1b356f12dd..a7bfc47191 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -284,8 +284,7 @@ int device_reparent(struct udevice *dev, struct udevice *new_parent) assert(dev); assert(new_parent); - list_for_each_entry_safe(pos, n, &dev->parent->child_head, - sibling_node) { + device_foreach_child_safe(pos, n, dev->parent) { if (pos->driver != dev->driver) continue; @@ -729,7 +728,7 @@ int device_get_child(const struct udevice *parent, int index, { struct udevice *dev; - list_for_each_entry(dev, &parent->child_head, sibling_node) { + device_foreach_child(dev, parent) { if (!index--) return device_get_device_tail(dev, 0, devp); } @@ -742,7 +741,7 @@ int device_get_child_count(const struct udevice *parent) struct udevice *dev; int count = 0; - list_for_each_entry(dev, &parent->child_head, sibling_node) + device_foreach_child(dev, parent) count++; return count; @@ -753,7 +752,7 @@ int device_get_decendent_count(const struct udevice *parent) const struct udevice *dev; int count = 1; - list_for_each_entry(dev, &parent->child_head, sibling_node) + device_foreach_child(dev, parent) count += device_get_decendent_count(dev); return count; @@ -766,7 +765,7 @@ int device_find_child_by_seq(const struct udevice *parent, int seq, *devp = NULL; - list_for_each_entry(dev, &parent->child_head, sibling_node) { + device_foreach_child(dev, parent) { if (dev->seq_ == seq) { *devp = dev; return 0; @@ -795,7 +794,7 @@ int device_find_child_by_of_offset(const struct udevice *parent, int of_offset, *devp = NULL; - list_for_each_entry(dev, &parent->child_head, sibling_node) { + device_foreach_child(dev, parent) { if (dev_of_offset(dev) == of_offset) { *devp = dev; return 0; @@ -824,7 +823,7 @@ static struct udevice *_device_find_global_by_ofnode(struct udevice *parent, if (ofnode_equal(dev_ofnode(parent), ofnode)) return parent; - list_for_each_entry(dev, &parent->child_head, sibling_node) { + device_foreach_child(dev, parent) { found = _device_find_global_by_ofnode(dev, ofnode); if (found) return found; @@ -902,7 +901,7 @@ int device_find_first_inactive_child(const struct udevice *parent, struct udevice *dev; *devp = NULL; - list_for_each_entry(dev, &parent->child_head, sibling_node) { + device_foreach_child(dev, parent) { if (!device_active(dev) && device_get_uclass_id(dev) == uclass_id) { *devp = dev; @@ -920,7 +919,7 @@ int device_find_first_child_by_uclass(const struct udevice *parent, struct udevice *dev; *devp = NULL; - list_for_each_entry(dev, &parent->child_head, sibling_node) { + device_foreach_child(dev, parent) { if (device_get_uclass_id(dev) == uclass_id) { *devp = dev; return 0; @@ -937,7 +936,7 @@ int device_find_child_by_namelen(const struct udevice *parent, const char *name, *devp = NULL; - list_for_each_entry(dev, &parent->child_head, sibling_node) { + device_foreach_child(dev, parent) { if (!strncmp(dev->name, name, len) && strlen(dev->name) == len) { *devp = dev; diff --git a/drivers/core/devres.c b/drivers/core/devres.c index 313ddc7089..78914bdf7f 100644 --- a/drivers/core/devres.c +++ b/drivers/core/devres.c @@ -232,7 +232,7 @@ static void dump_resources(struct udevice *dev, int depth) (unsigned long)dr->size, dr->name, devres_phase_name[dr->phase]); - list_for_each_entry(child, &dev->child_head, sibling_node) + device_foreach_child(child, dev) dump_resources(child, depth + 1); } diff --git a/drivers/core/dump.c b/drivers/core/dump.c index f2f9cacc56..fe97dca954 100644 --- a/drivers/core/dump.c +++ b/drivers/core/dump.c @@ -39,7 +39,7 @@ static void show_devices(struct udevice *dev, int depth, int last_flag) printf("%s\n", dev->name); - list_for_each_entry(child, &dev->child_head, sibling_node) { + device_foreach_child(child, dev) { is_last = list_is_last(&child->sibling_node, &dev->child_head); show_devices(child, depth + 1, (last_flag << 1) | is_last); } -- 2.35.1