From patchwork Mon Mar 7 03:40:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 550079 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F920C4332F for ; Mon, 7 Mar 2022 03:39:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235115AbiCGDjy (ORCPT ); Sun, 6 Mar 2022 22:39:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235055AbiCGDju (ORCPT ); Sun, 6 Mar 2022 22:39:50 -0500 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8771B4EA23 for ; Sun, 6 Mar 2022 19:38:56 -0800 (PST) Received: by mail-ot1-x32f.google.com with SMTP id k9-20020a056830242900b005ad25f8ebfdso12060831ots.7 for ; Sun, 06 Mar 2022 19:38:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b/MCt7zD+7NRGZpCFHWN5u6MfVVdOsK3kPJmdcKk1zQ=; b=xs+/oH+0Xa8WaEhc0k7mUrN1ZnIjpHcFI0chw+wvfFTHgL5riPW7Eex0SEJjpPjVU2 hE5lYmneAB8/zqrH2EkhPMaJDzMRocgrsnUaco7P2Jzo3MjpNc1jKzdZczrM5XR25u8u OAUdjRZeM4BuvQ0eh0mTkdV2/a7NtxJHF92yVxCPUSKnIAEDDx5KkDBJhJH2ZxDv8vG5 Q45qvU0IADXxDQUszZNd2eUQjnXIqbBl5LPAqzKBZC7+djR6FGzHHKUrzh5VPVxyuAKD LVLnwvoM9YULHqNJLe3CGRt4E8/6WpPme2K7FtmSLKoTaK5EXtSfsC2HPMSLeG8bOtEG K0/Q== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=b/MCt7zD+7NRGZpCFHWN5u6MfVVdOsK3kPJmdcKk1zQ=; b=ogHcL4pV4hDSZlpGkphD1A+JHLG+zN3Xd0A8sT5nldYuKwKK1kpYMOZ8Vygc6FEQnw FseyZgNx/xEBifNb8mdAsVMErih/Sg0L+zcJlWpsf/JnUSN3RWNlduNjLWJYymA1Y1bU 0e1hTD3jyxBdBl2xLsBDJlYJKDFd7S1kI+LJSdZUVIhy+rz4q26j5THsJtTl0F4aHwuV WIcuzBl7T/Okq9sX/jJpXLY4R+G2UrsgTPva+LTtQDEBfZG0xIAGIwnHOcFYShux7D9u dwDlw/EI/yVYPrnJAAAR8DtIiVGxpR9HeaHaB4lQvfuGyC9f7luGxXmnurUNNZHHMFjQ T6uA== X-Gm-Message-State: AOAM530PD+0Os6xbEzlm1SvHUG1YXQOJXcZgJYhOMkewi0yunth89HAp vTllZYdXnrnC5TAYRJ01L5EzWA== X-Google-Smtp-Source: ABdhPJy9PAFepwg+UDYAwdRLD2axOA/9QjaQ4bB0YxN+ILEGjicdR2M3oqKZlVqHcp4RumfEUM3MSg== X-Received: by 2002:a9d:2da5:0:b0:5ad:fa9:832 with SMTP id g34-20020a9d2da5000000b005ad0fa90832mr4873882otb.250.1646624335886; Sun, 06 Mar 2022 19:38:55 -0800 (PST) Received: from ripper.. ([2600:1700:a0:3dc8:205:1bff:fec0:b9b3]) by smtp.gmail.com with ESMTPSA id o2-20020a05687072c200b000d9ae3e1fabsm5005172oak.12.2022.03.06.19.38.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 19:38:55 -0800 (PST) From: Bjorn Andersson To: Rob Herring , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , "Rafael J. Wysocki" , Hans de Goede Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Dmitry Baryshkov Subject: [PATCH v4 2/7] device property: Use multi-connection matchers for single case Date: Sun, 6 Mar 2022 19:40:35 -0800 Message-Id: <20220307034040.1111107-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220307034040.1111107-1-bjorn.andersson@linaro.org> References: <20220307034040.1111107-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The newly introduced helpers for searching for matches in the case of multiple connections can be resused by the single-connection case, so do this to save some duplication. Reviewed-by: Andy Shevchenko Signed-off-by: Bjorn Andersson --- Changes since v3: - Picked up Andy's r-b Changes since v2: - None Changes since v1: - None drivers/base/property.c | 55 ++++------------------------------------- 1 file changed, 5 insertions(+), 50 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 7fccb0587855..ead8d4dd1ae2 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1193,31 +1193,6 @@ const void *device_get_match_data(struct device *dev) } EXPORT_SYMBOL_GPL(device_get_match_data); -static void * -fwnode_graph_devcon_match(struct fwnode_handle *fwnode, const char *con_id, - void *data, devcon_match_fn_t match) -{ - struct fwnode_handle *node; - struct fwnode_handle *ep; - void *ret; - - fwnode_graph_for_each_endpoint(fwnode, ep) { - node = fwnode_graph_get_remote_port_parent(ep); - if (!fwnode_device_is_available(node)) { - fwnode_handle_put(node); - continue; - } - - ret = match(node, con_id, data); - fwnode_handle_put(node); - if (ret) { - fwnode_handle_put(ep); - return ret; - } - } - return NULL; -} - static unsigned int fwnode_graph_devcon_matches(struct fwnode_handle *fwnode, const char *con_id, void *data, devcon_match_fn_t match, @@ -1252,28 +1227,6 @@ static unsigned int fwnode_graph_devcon_matches(struct fwnode_handle *fwnode, return count; } -static void * -fwnode_devcon_match(struct fwnode_handle *fwnode, const char *con_id, - void *data, devcon_match_fn_t match) -{ - struct fwnode_handle *node; - void *ret; - int i; - - for (i = 0; ; i++) { - node = fwnode_find_reference(fwnode, con_id, i); - if (IS_ERR(node)) - break; - - ret = match(node, NULL, data); - fwnode_handle_put(node); - if (ret) - return ret; - } - - return NULL; -} - static unsigned int fwnode_devcon_matches(struct fwnode_handle *fwnode, const char *con_id, void *data, devcon_match_fn_t match, @@ -1320,16 +1273,18 @@ void *fwnode_connection_find_match(struct fwnode_handle *fwnode, const char *con_id, void *data, devcon_match_fn_t match) { + unsigned int count; void *ret; if (!fwnode || !match) return NULL; - ret = fwnode_graph_devcon_match(fwnode, con_id, data, match); - if (ret) + count = fwnode_graph_devcon_matches(fwnode, con_id, data, match, &ret, 1); + if (count) return ret; - return fwnode_devcon_match(fwnode, con_id, data, match); + count = fwnode_devcon_matches(fwnode, con_id, data, match, &ret, 1); + return count ? ret : NULL; } EXPORT_SYMBOL_GPL(fwnode_connection_find_match);