From patchwork Thu Apr 26 14:08:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 905083 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="R3kuiVmX"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40WzSQ0mhDz9s02 for ; Fri, 27 Apr 2018 00:08:38 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932121AbeDZOIe (ORCPT ); Thu, 26 Apr 2018 10:08:34 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:51759 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756535AbeDZOI2 (ORCPT ); Thu, 26 Apr 2018 10:08:28 -0400 Received: by mail-wm0-f65.google.com with SMTP id j4so13229850wme.1 for ; Thu, 26 Apr 2018 07:08:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=Bd92YBfjJBg8gmPTaYjzsTwjf6uIESjao1Z80MbA9YQ=; b=R3kuiVmX42jwM2V5V9UTB4EMMb4HyJV4iGtvzJ2s/opYm9hQa10mZESFG+XWfeZ3qz uUEAiDWo1eq50TdH0zGbE8WXIgoMkuRVbZLbhkPRvIR/gY2Ox++iz+lX/0KyOsZZoafn LP7teXBZbPrUU+Qh4TRxPuZs7TN9m6D8JAR6I9153Yz1I9iUshFlLmCCkSx7ZR67Ij7c JCbRFRo/0BDK6985W03+aQpNbb1UlSZ4RA3DgJ//F09Q+oL9TGtOVz8Mqr97RY0jibud 1cMthOhWb9d/RcE6URCSRVEKd4Xa/eDr+GmwMyp4SW7zCHbiArQnCbu8HKSVMle6fER7 QX8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=Bd92YBfjJBg8gmPTaYjzsTwjf6uIESjao1Z80MbA9YQ=; b=HXtAv3/KaPMxXzgeylzOHfZ06qkeixQj2UyqoqJa8+Odht2mZwILqd7BEYswRNKtTM xVAYl7+PKvxwLN0NMQvzY/+zIBTppZN8FQezQ9Gn7fdeyyZCWIii+JAFVpmSBJmwro6v mcygmKFDaXr6GRukyzR47WZfFSEExnKDIUw+gOpGhQ0xXXdZfnrLzJpZWaftZmiqmdmy yMzKEGGB/UsKvTH1QeHEw2LH7U6tUd5gixt5VpoY2LIT/GOcDLlkipG/NclOxFzlh1yF RAl6npUwn11SOHC7/9QGHFzUgtvC33jZusoq4HTb+0puaZWb0T+/FQNv2vOIODjlemMv nzNw== X-Gm-Message-State: ALQs6tAgCU3+Q+qGbrAPainIQcv8iAcs94LTBnPlSaC7DWrIFBuvUHlA GPjKCmjTDmkGVx/qU07wMWF0zQ== X-Google-Smtp-Source: AIpwx4+cc72ajMMhLspxpiO/9AMNkQx5kiTKGTuQanP0C2Sg9X8jAMJ4cihajVAcPTn+lYdf89Xs7w== X-Received: by 10.28.92.203 with SMTP id q194mr18201309wmb.135.1524751706975; Thu, 26 Apr 2018 07:08:26 -0700 (PDT) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id d9sm24465531wmh.38.2018.04.26.07.08.26 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 26 Apr 2018 07:08:26 -0700 (PDT) From: Michal Simek To: linux-kernel@vger.kernel.org, monstr@monstr.eu, gnomes@lxorguk.ukuu.org.uk, Alexander Graf Cc: devicetree@vger.kernel.org, Rob Herring , Frank Rowand Subject: [RFC PATCH 1/3] of: base: Introduce of_alias_check_id() to check alias IDs Date: Thu, 26 Apr 2018 16:08:17 +0200 Message-Id: <6045807691c310ccdd57ab16524b7525f26a1dc1.1524751696.git.michal.simek@xilinx.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The function travers the lookup table to check if the request alias id is compatible with the device driver match structure. This function will be used by serial drivers to check if requested alias is allocated or free to use. Signed-off-by: Michal Simek --- drivers/of/base.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 2 ++ 2 files changed, 51 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 848f549164cd..382de01acc72 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1892,6 +1892,55 @@ int of_alias_get_id(struct device_node *np, const char *stem) } EXPORT_SYMBOL_GPL(of_alias_get_id); +/** + * of_alias_check_id - Check alias id for the give compatibility + * @matches: Array of of device match structures to search in + * @stem: Alias stem of the given device_node + * @id: Alias ID for checking + * + * The function travers the lookup table to check if the request alias id + * is compatible with the device driver match structure + * + * Return true if ID is allocated, return false if not + */ +bool of_alias_check_id(const struct of_device_id *matches, const char *stem, + int id) +{ + struct alias_prop *app; + bool ret = false; + + mutex_lock(&of_mutex); + pr_debug("%s: Looking for stem: %s, id: %d\n", __func__, stem, id); + list_for_each_entry(app, &aliases_lookup, link) { + pr_debug("%s: stem: %s, id: %d\n", + __func__, app->stem, app->id); + + if (strcmp(app->stem, stem) != 0) { + pr_debug("%s: stem comparison doesn't passed %s\n", + __func__, app->stem); + continue; + } + + if (app->id != id) { + pr_debug("%s: id comparison doesn't passed %d\n", + __func__, app->id); + continue; + } + + if (of_match_node(matches, app->np)) { + pr_debug("%s: Allocated ID %d\n", __func__, app->id); + ret = true; + break; + } + pr_debug("%s: Free ID %d\n", __func__, app->id); + break; + } + mutex_unlock(&of_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(of_alias_check_id); + /** * of_alias_get_highest_id - Get highest alias id for the given stem * @stem: Alias stem to be examined diff --git a/include/linux/of.h b/include/linux/of.h index 4d25e4f952d9..a18a390a6129 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -387,6 +387,8 @@ extern int of_phandle_iterator_args(struct of_phandle_iterator *it, extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); extern int of_alias_get_id(struct device_node *np, const char *stem); extern int of_alias_get_highest_id(const char *stem); +extern bool of_alias_check_id(const struct of_device_id *matches, + const char *stem, int id); extern int of_machine_is_compatible(const char *compat);