From patchwork Fri Jan 27 00:11:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 13117983 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8135FC54EAA for ; Fri, 27 Jan 2023 00:16:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0uBWlOLUXT8L5bu3doW7+78b1PnVbGVNWh6N0q3N52o=; b=B4JaXaTq0AWnfAwPPONDFxg2sM 05OqGnpwyoGoFw69ksPJzU0Bj5jn13MRRev8yUdjHiv/zEx/L4AmcIx32PXxgRUmO+cwe5CVFgtZV UTh56QPS0Ch556+FInEgq5RGnXA1u6yfRE2f+y5e2sBJlHR2BvPsKUp7jrDmPOdFQxZ5R/y1QpU03 Oav2BhSkfPo7grPwo3juWgj4u+/OPUaQYaiFV0e6WwsJj9c6MU2fx5CoDpJ+CqO1yMUxXp8LawsEq QrNYSYclmHvnv8istzBujwNbcwPiCw1GCCQuDmdsgB2Q7RLoQmty+o1SkqeWB7xrGX2hpEiYsY6ew yObL4W5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLCOP-00CvNH-Sn; Fri, 27 Jan 2023 00:14:58 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLCLb-00CuMF-U5 for linux-arm-kernel@lists.infradead.org; Fri, 27 Jan 2023 00:12:05 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id w70-20020a25df49000000b00803e799d7b1so3694206ybg.10 for ; Thu, 26 Jan 2023 16:12:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xmnKYDMGckXgFhZpaO7nCm5AdotTXCbrqCeB4/4reUA=; b=PMd9N+cUoBI1+XCPtZM2ZavRjj39Gr4Wu1cIhwZKLsDq5pNea8d1lUpCciqeA+bLAa nCCFzsn9qKyYHlK7D1T/jA0UEUfBjK8qExLyMdpyEJkyMLrNb7nADPR8lwT5chGAe5YR /KOdU5KwfpjOfxFXt3E7IZdVvJCqjPI2mfVi6w3CVFH238H+omoj38aOL9yEzSiNarqO hvh7/bGKNySXwNGvheklFu6dj9CGW+wZV0HZrtOqO+OPyJ9h0g64hLHeresmboIHBYMv qwKkLhTvCMXOuEEBvTJkV3CDQWCgj5yjbodPBKNwNY9a0JfquC0Td4cfASgqcC//XAQQ xikA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xmnKYDMGckXgFhZpaO7nCm5AdotTXCbrqCeB4/4reUA=; b=L1FU3l3ts7yWpypgGbOUNo5rsAIkMH8Py9zWJ5rqYtMq0mH4sjbn1y4o8aXtP3u0Dv jK6UvCTwTpZOd3HIAWaasojCaxHayKwlvNzivq5QxE079Q+kFjQeGoL/NkbZPs+sPNRl 37XQELD2Y2e2LggJ5EzJG40VNquoJzDpWUAE3/bXT5Roe89bNgZnXkrzPwC/8akMGPHs OK50HN6Tp5WrnLi/1vxQAHaaI85G2YMee6PLnKLiZdqFqxsFIK7E5rkN5onvn7SVgJxS K0L7GO9tGlncMR9cAZ9/8xVJqthYOV/y5QzRssutQ0Yq3Q1kS9Ji4EH61CeaFI/3UKEh 4yHg== X-Gm-Message-State: AFqh2kp8EP+pV33nVTx6qK4iK2GK3hZ2RHbT7PsIarTI8rSvehY2nzD7 yYELTvrw5loRs8ZUdXYGrn9KCZlGYppNi3c= X-Google-Smtp-Source: AMrXdXtccMFU5g8cqR4yhIhGpW4p3rK4cfzV+G3271lD029UOigJ8Rxd9pBUOt7tog+62UUFP2Au4t5UOIYQEts= X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:c3b4:8b1c:e3ee:3708]) (user=saravanak job=sendgmr) by 2002:a81:a54a:0:b0:4fa:6bec:c7d4 with SMTP id v10-20020a81a54a000000b004fa6becc7d4mr4092908ywg.214.1674778322520; Thu, 26 Jan 2023 16:12:02 -0800 (PST) Date: Thu, 26 Jan 2023 16:11:34 -0800 In-Reply-To: <20230127001141.407071-1-saravanak@google.com> Message-Id: <20230127001141.407071-8-saravanak@google.com> Mime-Version: 1.0 References: <20230127001141.407071-1-saravanak@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v2 07/11] driver core: fw_devlink: Consolidate device link flag computation From: Saravana Kannan To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Sudeep Holla , Cristian Marussi , Linus Walleij , Bartosz Golaszewski , Thomas Gleixner , Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Rob Herring , Frank Rowand , Geert Uytterhoeven , Magnus Damm , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Saravana Kannan Cc: Tony Lindgren , Linux Kernel Functional Testing , Naresh Kamboju , Abel Vesa , Alexander Stein , Geert Uytterhoeven , John Stultz , Doug Anderson , Guenter Roeck , Dmitry Baryshkov , Maxim Kiselev , Maxim Kochetkov , Miquel Raynal , Luca Weiss , Colin Foster , Martin Kepplinger , Jean-Philippe Brucker , kernel-team@android.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-acpi@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_161204_009347_46718448 X-CRM114-Status: GOOD ( 20.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Consolidate the code that computes the flags to be used when creating a device link from a fwnode link. Fixes: 2de9d8e0d2fe ("driver core: fw_devlink: Improve handling of cyclic dependencies") Signed-off-by: Saravana Kannan --- drivers/base/core.c | 28 +++++++++++++++------------- include/linux/fwnode.h | 1 - 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 82b29e9070bf..b61d5d86a600 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1726,8 +1726,11 @@ static int __init fw_devlink_strict_setup(char *arg) } early_param("fw_devlink.strict", fw_devlink_strict_setup); -u32 fw_devlink_get_flags(void) +static inline u32 fw_devlink_get_flags(u8 fwlink_flags) { + if (fwlink_flags & FWLINK_FLAG_CYCLE) + return FW_DEVLINK_FLAGS_PERMISSIVE | DL_FLAG_CYCLE; + return fw_devlink_flags; } @@ -1937,7 +1940,7 @@ static bool fwnode_ancestor_init_without_drv(struct fwnode_handle *fwnode) * fw_devlink_create_devlink - Create a device link from a consumer to fwnode * @con: consumer device for the device link * @sup_handle: fwnode handle of supplier - * @flags: devlink flags + * @link: fwnode link that's being converted to a device link * * This function will try to create a device link between the consumer device * @con and the supplier device represented by @sup_handle. @@ -1954,10 +1957,17 @@ static bool fwnode_ancestor_init_without_drv(struct fwnode_handle *fwnode) * possible to do that in the future */ static int fw_devlink_create_devlink(struct device *con, - struct fwnode_handle *sup_handle, u32 flags) + struct fwnode_handle *sup_handle, + struct fwnode_link *link) { struct device *sup_dev; int ret = 0; + u32 flags; + + if (con->fwnode == link->consumer) + flags = fw_devlink_get_flags(link->flags); + else + flags = FW_DEVLINK_FLAGS_PERMISSIVE; /* * In some cases, a device P might also be a supplier to its child node @@ -2090,7 +2100,6 @@ static void __fw_devlink_link_to_consumers(struct device *dev) struct fwnode_link *link, *tmp; list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook) { - u32 dl_flags = fw_devlink_get_flags(); struct device *con_dev; bool own_link = true; int ret; @@ -2120,14 +2129,13 @@ static void __fw_devlink_link_to_consumers(struct device *dev) con_dev = NULL; } else { own_link = false; - dl_flags = FW_DEVLINK_FLAGS_PERMISSIVE; } } if (!con_dev) continue; - ret = fw_devlink_create_devlink(con_dev, fwnode, dl_flags); + ret = fw_devlink_create_devlink(con_dev, fwnode, link); put_device(con_dev); if (!own_link || ret == -EAGAIN) continue; @@ -2168,19 +2176,13 @@ static void __fw_devlink_link_to_suppliers(struct device *dev, bool own_link = (dev->fwnode == fwnode); struct fwnode_link *link, *tmp; struct fwnode_handle *child = NULL; - u32 dl_flags; - - if (own_link) - dl_flags = fw_devlink_get_flags(); - else - dl_flags = FW_DEVLINK_FLAGS_PERMISSIVE; list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook) { int ret; struct device *sup_dev; struct fwnode_handle *sup = link->supplier; - ret = fw_devlink_create_devlink(dev, sup, dl_flags); + ret = fw_devlink_create_devlink(dev, sup, link); if (!own_link || ret == -EAGAIN) continue; diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index fdf2ee0285b7..5700451b300f 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -207,7 +207,6 @@ static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode, fwnode->flags &= ~FWNODE_FLAG_INITIALIZED; } -extern u32 fw_devlink_get_flags(void); extern bool fw_devlink_is_strict(void); int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup); void fwnode_links_purge(struct fwnode_handle *fwnode);