Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp40384ybg; Mon, 8 Jun 2020 15:53:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlh4fimaXAnajRxiBdBNCszTdyDRuFGYlFVext/BBb5sbK4AlzZrHPK/eq5MfMZ6O5muSU X-Received: by 2002:a17:906:ecef:: with SMTP id qt15mr22149442ejb.91.1591656782206; Mon, 08 Jun 2020 15:53:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591656782; cv=none; d=google.com; s=arc-20160816; b=bszNW5RghpTFu6Y4jrmhj5k7xaZg8UYrDT0P99LWMObKc2ovkA5JC5mTLLbR5clifS SFkazv05s5cxWfJUp3tPxCtbB1LsFF44t07AAyDj2zMFvlcbavd03W0ivCEsbs+1pABI alULAyIP/itNVHrFxGCAjq11vnJ2ifRRK/NChC3liLwqehPUBjviTbjXrPMgunXYh4at Vgme4C4/Ftb566dcuucgZH+ouDUiNvczK7J3bmm5EnFcoAIO5uaHRwdUD8yyHCYaNPI/ MlWEcLUYmISB/+ZGtwHceBwqynWOZQAiQ3Egyj1SDvhMzDyrJ3agPIVRLAvwjr26L19C ZLfw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=JTj7H+bWQ50L0w3gmhUU8lvfINHUiaK8WNziobU7SBE=; b=Fkz8pVI+rsRSP3UrUth8/cnEAO2buTVVudpY/YS/vH912M9Ifrq+rXFbKeyuyWWo6t CLYhnN/ISulBvkk9AigfD6JYZ9eYgWVry6w4Pxofqp/AeK0hJmlYffb3qwM8GsWTY2Yz Q2Zyjiw3fMDlAf6+ACS5RZH9XrVOTw/nKBZfnuO9Q5QrtMNmkuwM+cz+Y/3Zrwpu4o6J IilqjXbWGHqFmnOYAq88mg/aS1wy05845I0XSnnQqLea2Y8Ig2opmxueTBUqu3q0Gw3k 8kkcjONBsZqvaUPRB76EGXy7YUOg2qOslIM8xhtPChvnVBfa01i97i2TeRoGiV/b4NEP z0kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=XHWkmWB3; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id md3si9939772ejb.206.2020.06.08.15.52.37; Mon, 08 Jun 2020 15:53:02 -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=@ti.com header.s=ti-com-17Q1 header.b=XHWkmWB3; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726875AbgFHWra (ORCPT + 99 others); Mon, 8 Jun 2020 18:47:30 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:56096 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726734AbgFHWr3 (ORCPT ); Mon, 8 Jun 2020 18:47:29 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 058MlPaE050473; Mon, 8 Jun 2020 17:47:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1591656445; bh=JTj7H+bWQ50L0w3gmhUU8lvfINHUiaK8WNziobU7SBE=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=XHWkmWB3ttKSJ5CBrj2IIC5P/UmNkNWd7X/pVJsMdnUTF1aEKcrBrrkvDjr0lPTTs 7As8+dzP8NuP8mpBidza4PPUumj0PvfrDLdyH1oCCpcOxA/SopVkx/PHXuHBevNUd3 cttR9MGciO/S15CfieYNqT8cxZMcxC+64nb2m4V4= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 058MlPqP006026 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 8 Jun 2020 17:47:25 -0500 Received: from DLEE115.ent.ti.com (157.170.170.26) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Mon, 8 Jun 2020 17:47:25 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Mon, 8 Jun 2020 17:47:24 -0500 Received: from [10.250.48.148] (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 058MlOkE124381; Mon, 8 Jun 2020 17:47:24 -0500 Subject: Re: [PATCH v6 2/3] rpmsg: core: Add support to retrieve name extension To: Mathieu Poirier , , CC: , , References: <20200515205642.13529-1-mathieu.poirier@linaro.org> <20200515205642.13529-3-mathieu.poirier@linaro.org> From: Suman Anna Message-ID: <632db4a1-74e0-edc4-78ca-53109f11ace8@ti.com> Date: Mon, 8 Jun 2020 17:47:19 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200515205642.13529-3-mathieu.poirier@linaro.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mathieu, On 5/15/20 3:56 PM, Mathieu Poirier wrote: > 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 With the below minor nits fixed, Acked-by: Suman Anna > --- > 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"; > + * > + * can drop the additional blank line here, > + * 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) { This does fit on the same line, so no need to use multi-lines for this. regards Suman > + 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 */ >