Received: by 10.192.165.148 with SMTP id m20csp2185311imm; Thu, 26 Apr 2018 07:10:49 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+pU9b5hPpbnp8dvvniMV5oRlJleKyLtGlcbgFIv+qOZyZNpXNynHXlKyoG+aoeq8/LQShf X-Received: by 2002:a17:902:33a5:: with SMTP id b34-v6mr34443291plc.232.1524751849292; Thu, 26 Apr 2018 07:10:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524751849; cv=none; d=google.com; s=arc-20160816; b=LTYsTCDtuoNAwzuB+LM/l78UzvBXFJKaimSluR2yRraKAAY6Kd8cUp3byU511XTkUd ZSyXbPPuNTszdlr+4rB2fCLhse2nTOhB9TyWuz7/LiA2wsqxf9uKE6znwI3c5fcyBYaB EkgAX0V2rN6qva+Sd2zvFFC297KEWL9nm8HJH9lxoLcleKYdMXcDbnqpl7oG4ZaYJxee cNGjzTcQk1JkJxAgskfaWNlX96OXmKi3V4ZHq8qwMfY35P7a6M8h2Ov0cjXUlPJFXiBz ObcAGqs3nT8rBGY9TYdmlW1ab76O0IvMCBn4y27guZpWLxDkL+3FchKzoUbzbUaAjE+C 92gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Bd92YBfjJBg8gmPTaYjzsTwjf6uIESjao1Z80MbA9YQ=; b=LwLtrMGqgpq4cfdj5QWiAhiecOqeK4jLugfQwNT3tuXbelvtidfSzDvSrRGATS19Mf LB9s7RTkuvZPZ4mxehQXulKqDKvDVweGDpglGnmT6nkXvSYNzbgzzYeuXbImhX1sKk0Z jiaZ3xfgyayG7RDqNjwF22f81Dt+8pdV2ASJa/OarRhxtHsof91mjBAYRZq4Zks7d+cL 31Em1bCheKOMdY6A/TlNBGIJmTUrzWAeIMdsfdRU79KYjoFhJU1JZMypcQtBbDGYYkqC fC5Wuq50o/CSDjPA/Ql3Gr5DAcYZxW7Fo87CWbka2F3ajUdX2RjKElBv0iXlLHytbgAL N8Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@monstr-eu.20150623.gappssmtp.com header.s=20150623 header.b=R3kuiVmX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m4si15610567pgv.517.2018.04.26.07.10.34; Thu, 26 Apr 2018 07:10:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@monstr-eu.20150623.gappssmtp.com header.s=20150623 header.b=R3kuiVmX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932210AbeDZOI4 (ORCPT + 99 others); Thu, 26 Apr 2018 10:08:56 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:51047 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756536AbeDZOI2 (ORCPT ); Thu, 26 Apr 2018 10:08:28 -0400 Received: by mail-wm0-f68.google.com with SMTP id t11so6347233wmt.0 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=Y/QiewGO3kKd1i1ptR0xF4DaWmh65PBjDiOqC0ICNXdWxbLcqKvJzGSclYUbaI8Si/ lknnrCmRngOAApHCMpQFyTmb8EFDy8WKFBU16tDFlakrmWveYeROf+zvfF/xXs2Bu6nX Oz2owvXG9BB9+Mw2fuXXZYvPtIA2DLOBROI3sFeg87QTpmyK5SViLpXY6ABcoUa/4tW6 axRxf8TfL7LLTouvfUOM/7pLoYcsBc9/LOwKixGf3s1VP8qs59VROHwQJtl/ZTvZ/snQ 8w2UNXesFh8r7mwutR1h0yS3Q9pOB4ZxASDO05tlfzpjUDKfNE/No5RzjIg2cVXfg8rn aO/Q== X-Gm-Message-State: ALQs6tDKBh9Cqyltip+XLNOpmN6Uksa07ZRRmXpmee7VCFda/b2DC5Id fhXudoo9SftQ5y2Y2CMJTrvgRPdE 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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); -- 2.17.0