Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp799017ybk; Fri, 15 May 2020 13:59:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyS15IYCNWSP9CvB3/ceoHuT53Ne/mf4W2aazkA4JKPs+2GsBAtC/0NVd+tAaVdOJ6ZfD2k X-Received: by 2002:a50:d7c7:: with SMTP id m7mr4818763edj.101.1589576346289; Fri, 15 May 2020 13:59:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589576346; cv=none; d=google.com; s=arc-20160816; b=Izq/cboZV8msET1RSUrbqQDbCmKpTRu1wTU0jSdbm3IwaT3WBM4GFfJBCZA7CP327h JwjV7pEeoUD7NGvLTH4OZ1yDsUrBj0gqYrwXPY5gddu7togFz9uOxiofa+WmQ0uzAP2Y bYo9xC0+amSKshXkYmtOERGIQipi0w89rENFBkqifQlfdknx+nws1GCT0wEWKypaKMg+ FGPMkiNHcRvScOEkpYxZO8CN4NeFkT2uyn03D2bmK37zVG1H+iYetiuxjT29NvRHawG3 /qUu2XgbbxodmEsMWEavDHwtPoK7T9zhKjl1zATPqfler8N1xNJKegtQXKetXk884JUt Xn3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GwJdWtZ6c264QmD1Xk9hA26PPDpE566oSpL1VQouYo4=; b=ypJbZE/AXyWgJHfWM/MBILLIi08Mi5CUixygPbP34NN27VZN81zmKk/jWQ5Hroh/zU Si3DyEWHMhWlnjOVgL7khckC4EeWUtn+jUBV6zjsJAtfaslOT19grcrDPHQ7hxBxTlI4 gpHGIx+Ylmag6xXinluSwS18pvNGej4+d8Lo4c8ZE0fXZ4loGcch3m1bYC7XqhU3NFqB st13KCquitAH8+V7OrJjA3j+hv3OsAIOJl5jcfGYHth8mGdkHfIQybz9GrpYikn/kgWT Tz9EegOMpL7Y8zp2jMgrN1ne767Jj9YY02jOy7lBH6RhgU/c+9u+Bwlh+Xwb1EQeGAjM mHmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dQEzdhkv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g7si1823970edm.288.2020.05.15.13.58.43; Fri, 15 May 2020 13:59:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dQEzdhkv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726722AbgEOU4u (ORCPT + 99 others); Fri, 15 May 2020 16:56:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726179AbgEOU4s (ORCPT ); Fri, 15 May 2020 16:56:48 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEAE2C05BD09 for ; Fri, 15 May 2020 13:56:47 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id k19so1392056pll.9 for ; Fri, 15 May 2020 13:56:47 -0700 (PDT) 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=GwJdWtZ6c264QmD1Xk9hA26PPDpE566oSpL1VQouYo4=; b=dQEzdhkvU3jFA3oQ8JYJYe/qYbNFMKM8qWJL/2ZeNcZooNUhycOmYpLfYsydXu7F5V SiaXuAUKftAYFJhfr5+s9k6KzfmWGZq7Xv8j5z0QWdW2IozJaJwBZ4OjFioi14hlQLXn Wp9EUj00zhi/b8I3uTxgxMqhtFNMGPRhOS3s/29bj8+tKYe8x5UeOvAEedxb6V8EoFJa hXl0C43tuh10z6k4iCmNGvbGEBY3Yb163KRRBzFQPXWVLNuHkmAIME7dUUBYV5OXC34d 6GD1IKYq0fQRGwiv6+mvU+36ImJW0EOsmwa03KLD41JTa5uHVmPkqI/C1AhAafmrdNBr fIoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GwJdWtZ6c264QmD1Xk9hA26PPDpE566oSpL1VQouYo4=; b=H6WNnfBKAn4v1+UpmlP1Jw2yY94N9UwIh37x6qJ3JpsgXJ6Ol5iAs8tp5FcxODqUnF 9skdtvq593jhkgbUy2aWr2r2HvsFOpgKPAPnxvhsUuhtK1fzPNGOmTwQmm58LNLlR1gf eihKdJcbw5oWgkGiwOGpuWGkPnqo2O6EbBMHEw2V12xJCIDpwlJRiMw8awapnG19gD1Q 4THsLEAYsiE9FPP6Ex/6W88oq6xaOl4MbVTNsO4XQIJCjNbIAU5udszS109kWa5ISqHM Qoph+yJW1+wnzie7YKwxG56+HmKW6gehgMXJJA6S6RuwRz7fxel2d8R80VW2GsceAurD Hbkg== X-Gm-Message-State: AOAM5311kdxyC/uD7mEh1VB9uaLVCS5IL7I+EQaiEbcJeH6P8XCKfIxG Kcth1mN+nvJb292HzMOw9YSENg== X-Received: by 2002:a17:90a:f003:: with SMTP id bt3mr5377655pjb.3.1589576206553; Fri, 15 May 2020 13:56:46 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id z13sm2208903pjz.42.2020.05.15.13.56.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2020 13:56:46 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: arnaud.pouliquen@st.com, s-anna@ti.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 2/3] rpmsg: core: Add support to retrieve name extension Date: Fri, 15 May 2020 14:56:41 -0600 Message-Id: <20200515205642.13529-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200515205642.13529-1-mathieu.poirier@linaro.org> References: <20200515205642.13529-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After adding support for rpmsg device name extension, this patch provides a function that returns the extension portion of an rpmsg device name. That way users of the name extension functionality don't have to write the same boiler plate code to extract the information. Suggested-by: Suman Anna ; Signed-off-by: Mathieu Poirier Acked-by: Arnaud Pouliquen --- drivers/rpmsg/rpmsg_core.c | 95 ++++++++++++++++++++++++++++++++++++++ include/linux/rpmsg.h | 13 ++++++ 2 files changed, 108 insertions(+) diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index 5e01e8dede6b..9583eb936607 100644 --- a/drivers/rpmsg/rpmsg_core.c +++ b/drivers/rpmsg/rpmsg_core.c @@ -439,6 +439,101 @@ static int rpmsg_dev_match(struct device *dev, struct device_driver *drv) return of_driver_match_device(dev, drv); } +/** + * rpmsg_device_get_name_extension() - get the name extension of a rpmsg device + * @rpdev: the rpmsg device to work with + * @skip: how many characters in the extension should be skipped over + * + * With function rpmsg_id_match() allowing for extension of the base driver name + * in order to differentiate services, this function returns the extension part + * of an rpmsg device name. As such and with the following rpmsg driver device + * id table and rpmsg device names: + * + * static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = { + * { .name = "rpmsg-client-sample" }, + * { }, + * } + * + * rpdev1->id.name == "rpmsg-client-sample"; + * rpdev2->id.name == "rpmsg-client-sample_instance0"; + * + * Calling rpmsg_device_get_name_extension() will yields the following: + * + * rpmsg_device_get_name_extension(rpdev1, 0) == NULL; + * rpmsg_device_get_name_extension(rpdev2, 0) == "_instance0"; + * rpmsg_device_get_name_extension(rpdev2, 1) == "instance0"; + * + * + * Return: The name extension if found, NULL if the name of the RPMSG device + * equals the name of the RPMSG driver and an error if no match is + * found or a validation problem has occurred. + */ +const char *rpmsg_device_get_name_extension(struct rpmsg_device *rpdev, + unsigned int skip) +{ + const char *drv_name, *dev_name, *extension; + const struct rpmsg_device_id *ids; + struct device *dev = &rpdev->dev; + struct rpmsg_driver *rpdrv; + bool match = false; + unsigned int i; + + if (!dev->driver) + return ERR_PTR(-EINVAL); + + rpdrv = to_rpmsg_driver(dev->driver); + + /* + * No point in going further if the device doesn't have name or + * the driver doesn't have a table to work with. + */ + if (!rpdev->id.name[0] || !rpdrv->id_table) + return ERR_PTR(-EINVAL); + + ids = rpdrv->id_table; + dev_name = rpdev->id.name; + + /* + * See if any name in the driver's table match the beginning + * of the rpmsg device's name. + */ + for (i = 0; ids[i].name[0]; i++) { + drv_name = ids[i].name; + if (strncmp(drv_name, + dev_name, strlen(drv_name)) == 0) { + match = true; + break; + } + } + + /* + * A match was not found, return an error to differentiate with cases + * where a match was found but the name has no extension (see below). + */ + if (!match) + return ERR_PTR(-ENOENT); + + /* No name extension to return if device and driver are the same */ + if (strlen(dev_name) == strlen(drv_name)) + return NULL; + + /* + * Make sure we were not requested to skip past the end + * of the device name. + */ + if (strlen(drv_name) + skip >= strlen(dev_name)) + return ERR_PTR(-EINVAL); + + /* + * Move past the base name published by the driver and + * skip any extra characters if needed. + */ + extension = dev_name + strlen(drv_name) + skip; + + return extension; +} +EXPORT_SYMBOL(rpmsg_device_get_name_extension); + static int rpmsg_uevent(struct device *dev, struct kobj_uevent_env *env) { struct rpmsg_device *rpdev = to_rpmsg_device(dev); diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 9fe156d1c018..9537b95ad30a 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -135,6 +135,9 @@ int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp, poll_table *wait); +const char *rpmsg_device_get_name_extension(struct rpmsg_device *dev, + unsigned int skip); + #else static inline int register_rpmsg_device(struct rpmsg_device *dev) @@ -242,6 +245,16 @@ static inline __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, return 0; } +static inline +const char *rpmsg_device_get_name_extension(struct rpmsg_device *dev, + unsigned int skip) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return NULL; +} + #endif /* IS_ENABLED(CONFIG_RPMSG) */ /* use a macro to avoid include chaining to get THIS_MODULE */ -- 2.20.1